refactor: Improve code readability and maintainability

This commit is contained in:
Gauthier Daniels 2025-04-22 13:14:10 +02:00
parent f5f797eea7
commit d02c083898
2 changed files with 48 additions and 23 deletions

View File

@ -37,7 +37,7 @@ QuickLinks.QuickLink = (props: QuickLinkProps) => (
<div class="relative overflow-hidden rounded-xl p-6">
<Icon icon={props.icon} color="blue" class="h-8 w-8" />
<h2 class="mt-4 font-display text-base text-slate-900">
<h2 class="mt-4 font-display text-base text-slate-900 leading-5">
<Link href={props.href}>
<span class="absolute -inset-px rounded-xl" />
{props.title}
@ -45,7 +45,7 @@ QuickLinks.QuickLink = (props: QuickLinkProps) => (
</h2>
{props.lastEdited && (
<p class="-mt-2 italic mb-2 text-xs text-slate-500">
<p class="mt-2 mb-4 italic text-xs text-slate-500">
<span class="font-semibold">Dernière modification :</span>{" "}
<time datetime={props.lastEdited.toISOString()}>
{props.lastEdited.toLocaleDateString("fr-FR", {

View File

@ -230,30 +230,55 @@ class DocCache {
...customConfig,
};
const checkIfIncludedBasePath = (doc: SectionCache) => {
if (config.includedBasePaths.length > 0) {
return config.includedBasePaths.some((basePath) => {
return doc.filePath.startsWith(basePath);
});
}
return true;
};
const checkIfExcludedBasePaths = (doc: SectionCache) => {
if (config.excludedBasePaths.length > 0) {
return !config.excludedBasePaths.some((basePath) => {
return doc.filePath.startsWith(basePath);
});
}
return true;
};
const checkIfIncludedFileNames = (doc: SectionCache) => {
if (config.includedFileNames.length > 0) {
return config.includedFileNames.some((fileName) => {
return doc.filePath.includes(fileName);
});
}
return true;
};
const checkIfExcludedFileNames = (doc: SectionCache) => {
if (config.excludedFileNames.length > 0) {
return !config.excludedFileNames.some((fileName) => {
return doc.filePath.includes(fileName);
});
}
return true;
};
const sortedDocs = Array.from(this.cache.values())
.sort((a, b) => b.lastEdit.getTime() - a.lastEdit.getTime())
.filter((doc) => {
if (config.includedBasePaths.length > 0) {
return config.includedBasePaths.some((basePath) => {
return doc.filePath.startsWith(basePath);
});
}
if (config.excludedBasePaths.length > 0) {
return !config.excludedBasePaths.some((basePath) => {
return doc.filePath.startsWith(basePath);
});
}
if (config.includedFileNames.length > 0) {
return config.includedFileNames.some((fileName) => {
return doc.filePath.includes(fileName);
});
}
if (config.excludedFileNames.length > 0) {
return !config.excludedFileNames.some((fileName) => {
return doc.filePath.includes(fileName);
});
}
return true;
return [
checkIfIncludedBasePath(doc),
checkIfExcludedBasePaths(doc),
checkIfIncludedFileNames(doc),
checkIfExcludedFileNames(doc),
].every((check) => check === true);
});
if (config.limit > 0) return sortedDocs.slice(0, config.limit);