refactor(glossaire): centralize glossary relation helpers
This commit is contained in:
@@ -1,76 +1,21 @@
|
||||
---
|
||||
import {
|
||||
countGlossaryEntriesByFamily,
|
||||
countGlossaryEntriesByKind,
|
||||
getFondamentaux,
|
||||
hrefOfGlossaryEntry,
|
||||
} from "../lib/glossary";
|
||||
|
||||
const {
|
||||
allEntries = [],
|
||||
} = Astro.props;
|
||||
|
||||
const slugOf = (entry) => String(entry.id).replace(/\.(md|mdx)$/i, "");
|
||||
const hrefOf = (entry) => `/glossaire/${slugOf(entry)}/`;
|
||||
|
||||
const collator = new Intl.Collator("fr", { sensitivity: "base", numeric: true });
|
||||
const bySlug = new Map(allEntries.map((entry) => [slugOf(entry), entry]));
|
||||
|
||||
function sortByTerm(list = []) {
|
||||
return [...list].sort((a, b) => collator.compare(a.data.term, b.data.term));
|
||||
}
|
||||
|
||||
function familyOf(entry) {
|
||||
const explicit = entry?.data?.family;
|
||||
if (explicit) return explicit;
|
||||
|
||||
const slug = slugOf(entry);
|
||||
const kind = entry?.data?.kind;
|
||||
|
||||
if (kind === "paradigme") return "paradigme";
|
||||
if (kind === "doctrine") return "doctrine";
|
||||
if (kind === "verbe") return "verbe";
|
||||
|
||||
if (slug === "scene-depreuve") return "scene";
|
||||
if (slug === "autarchicratie") return "pathologie";
|
||||
if (slug === "obliteration-archicratique") return "dynamique";
|
||||
|
||||
if (
|
||||
[
|
||||
"archicratie",
|
||||
"arcalite",
|
||||
"cratialite",
|
||||
"archicration",
|
||||
"co-viabilite",
|
||||
"tension",
|
||||
].includes(slug)
|
||||
) {
|
||||
return "concept-fondamental";
|
||||
}
|
||||
|
||||
if (slug === "archicrations-differentielles-et-formes-hybrides") {
|
||||
return "topologie";
|
||||
}
|
||||
|
||||
if (kind === "topologie" && slug.startsWith("archicrations-")) {
|
||||
return "meta-regime";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
const fondamentauxWanted = [
|
||||
"archicratie",
|
||||
"arcalite",
|
||||
"cratialite",
|
||||
"archicration",
|
||||
"co-viabilite",
|
||||
"tension",
|
||||
];
|
||||
|
||||
const fondamentaux = sortByTerm(
|
||||
fondamentauxWanted
|
||||
.map((slug) => bySlug.get(slug))
|
||||
.filter(Boolean)
|
||||
);
|
||||
const fondamentaux = getFondamentaux(allEntries);
|
||||
|
||||
const totalEntries = allEntries.length;
|
||||
const paradigmesCount = allEntries.filter((entry) => entry.data.kind === "paradigme").length;
|
||||
const doctrinesCount = allEntries.filter((entry) => entry.data.kind === "doctrine").length;
|
||||
const metaRegimesCount = allEntries.filter((entry) => familyOf(entry) === "meta-regime").length;
|
||||
const paradigmesCount = countGlossaryEntriesByKind(allEntries, "paradigme");
|
||||
const doctrinesCount = countGlossaryEntriesByKind(allEntries, "doctrine");
|
||||
const metaRegimesCount = countGlossaryEntriesByFamily(allEntries, "meta-regime");
|
||||
|
||||
const portalLinks = [
|
||||
{ href: "/glossaire/concepts-fondamentaux/", label: "Concepts fondamentaux" },
|
||||
@@ -115,7 +60,7 @@ const portalLinks = [
|
||||
<h2 class="glossary-home-aside__heading">Noyau archicratique</h2>
|
||||
<ul class="glossary-home-aside__list">
|
||||
{fondamentaux.map((entry) => (
|
||||
<li><a href={hrefOf(entry)}>{entry.data.term}</a></li>
|
||||
<li><a href={hrefOfGlossaryEntry(entry)}>{entry.data.term}</a></li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user