UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

159 lines (158 loc) 9.11 kB
import { glob } from "glob"; import { describe } from "@javarome/testscript"; import { CMSGenerator } from "./CMSGenerator.js"; import { BaseOvniFranceRR0Mapping, FuforaRR0Mapping, NuforcRR0Mapping, RR0Mapping, SceauRR0Mapping, UrecatRR0Mapping } from "./time/index.js"; import { WitnessReplacerFactory } from "./people/index.js"; import * as process from "node:process"; import { GeipanRR0Mapping } from "./org/eu/fr/cnes/geipan/geipan/GeipanRR0Mapping.js"; import { BaseReplaceCommand } from "./BaseReplaceCommand.js"; import { LanguageReplaceCommand } from "./lang/LanguageReplaceCommand.js"; import { AngularExpressionReplaceCommand, ClassDomReplaceCommand, DomReplaceCommand, SsiEchoVarReplaceCommand, SsiIfReplaceCommand, SsiLastModifiedReplaceCommand, SsiSetVarReplaceCommand, StringEchoVarReplaceCommand } from "ssg-api"; import { rr0DefaultCopyright } from "./RR0DefaultCopyright.js"; import { DescriptionReplaceCommand } from "./DescriptionReplaceCommand.js"; import { CodeReplacerFactory } from "./tech/index.js"; import { PlaceReplacerFactory } from "./place/index.js"; import { IndexedReplacerFactory, UnitReplaceCommand } from "./index.js"; import { rr0TestUtil } from "./test/index.js"; export async function getTimeFiles() { const minusYearFiles = await glob(rr0TestUtil.filePath("time/-?/?/?/?/index.html")); const year1Files = await glob(rr0TestUtil.filePath("time/?/index.html")); const year2Files = await glob(rr0TestUtil.filePath("time/?/?/index.html")); const year3Files = await glob(rr0TestUtil.filePath("time/?/?/?/index.html")); const year4Files = await glob(rr0TestUtil.filePath("time/?/?/?/?/index.html")); const monthFiles = await glob(rr0TestUtil.filePath("time/?/?/?/?/??/index.html")); const dayFiles = await glob(rr0TestUtil.filePath("time/?/?/?/?/??/??/index.html")); return year1Files.concat(year2Files).concat(year3Files).concat(year4Files).concat(minusYearFiles).concat(monthFiles).concat(dayFiles).sort(); } describe("Build", () => { console.time("ssg"); const args = { contents: ["test/**/*.html"], force: "true" }; const cliContents = args.contents; console.debug("contents", cliContents); const mandatoryRoots = ["people/*.html", "science/crypto/ufo/enquete/dossier/*.html"]; const contentRoots = cliContents ? cliContents.concat(mandatoryRoots) : [ "croyance/**/*.html", "index.html", "404.html", "googlebe03dcf00678bb7c.html", "Contact.html", "Copyright.html", "preambule.html", "FAQ.html", "Referencement.html", "time/**/*.html", "book/**/*.html", "droit/**/*.html", "org/**/*.html", "people/**/*.html", "place/**/*.html", "politique/**/*.html", "science/**/*.html", "tech/**/*.html", "udb/*.html", "js/**/*.html" ].map(rr0TestUtil.filePath); const copiesArg = args.copies; const copies = copiesArg ? copiesArg : [ "favicon.ico", "manifest.json", "opensearch.xml", "apple-touch-icon.png", "apple-touch-icon_400x400.png", "screenshot1.jpg", "rr0.css", "map.css", "diagram.css", "print.css", "figure.css", "section.css", "table.css", "nav.css", // "**/*.png", "**/*.jpg", "**/*.gif", "**/*.webp", "!out/**/*", "**/*.cmmn", "**/*.bpmn", "tech/info/soft/reseau/protocole/index.js", "tech/info/soft/reseau/protocole/ports.json", "tech/info/soft/reseau/protocole/index.css", "tech/info/soft/data/doc/index.js", "tech/info/soft/data/doc/index.json", "tech/info/soft/data/doc/index.css", "people/index.js", "people/index.css", "people/witness/index.css", "search/SearchComponent.mjs", "search/index.json", "search/search.css", "source/index.css", "note/index.css", "link.css", "quote.css", "time/DualRangeComponent.mjs", "index/index.js", "lang/form.js", "lang/form.css", "lang/speech.js", "lang/speech.css", "croyance/divin/theisme/mono/livre/islam/coran/index.js" ].map(path => rr0TestUtil.filePath(path)); const outDir = "out"; const googleMapsApiKey = process.env.GOOGLE_MAPS_API_KEY; if (!googleMapsApiKey) { throw Error("GOOGLE_MAPS_API_KEY is required"); } const timeFormat = { year: "numeric", month: "long", day: "numeric", weekday: "long", hour: "2-digit", minute: "2-digit" }; const directoryPages = [ "people/index.html", "people/witness/index.html", "people/militaires.html", "people/scientifiques.html", "people/astronomes.html", "people/politicians.html", "people/dirigeants.html", "people/pilotes.html", "people/contactes.html", "people/ufologues.html", "tech/info/Personnes.html", "people/Contributeurs.html" ].map(path => rr0TestUtil.filePath(path)); getTimeFiles().then(async (timeFiles) => { const orgFiles = await glob("test/org/**/index.html"); const directoryOptions = { root: rr0TestUtil.filePath("people/index.html"), scientists: rr0TestUtil.filePath("people/scientifiques.html"), ufologists: rr0TestUtil.filePath("people/ufologues.html"), ufoWitnesses: rr0TestUtil.filePath("people/witness/index.html"), astronomers: rr0TestUtil.filePath("people/astronomes.html"), contactees: rr0TestUtil.filePath("people/contactes.html"), pilots: rr0TestUtil.filePath("people/pilotes.html"), military: rr0TestUtil.filePath("people/militaires.html"), softwareEngineers: rr0TestUtil.filePath("tech/info/Personnes.html"), politicians: rr0TestUtil.filePath("people/politicians.html"), rulers: rr0TestUtil.filePath("people/dirigeants.html") }; const sourceRegistryFileName = rr0TestUtil.filePath("source/index.json"); const siteBaseUrl = "https://rr0.org/"; const mail = "rr0@rr0.org"; const timeOptions = { rootDir: rr0TestUtil.filePath("time"), files: timeFiles }; const orgOptions = { rootDir: rr0TestUtil.filePath("org"), files: orgFiles }; const dataOptions = { time: timeOptions, org: orgOptions }; // const actions: ChronologyReplacerActions = {read: ["backup", "fetch"], write: ["backup", "pages"]} // const actions: ChronologyReplacerActions = {read: [], write: ["backup"]} const actions = { read: ["fetch"], write: ["backup"] }; const rr0Mapping = new RR0Mapping(actions); const geipanRR0Mapping = new GeipanRR0Mapping(actions); const baseOvniFranceRR0Mapping = new BaseOvniFranceRR0Mapping(actions); const fuforaRR0Mapping = new FuforaRR0Mapping(actions); const nuforcRR0Mapping = new NuforcRR0Mapping(actions); const urecatRR0Mapping = new UrecatRR0Mapping(actions); const sceauRR0Mapping = new SceauRR0Mapping(actions); const mappings = [rr0Mapping /* geipanRR0Mapping, baseOvniFranceRR0Mapping, fuforaRR0Mapping, nuforcRR0Mapping, urecatRR0Mapping, sceauRR0Mapping*/ ]; const pageReplacers = [ new BaseReplaceCommand("/"), new LanguageReplaceCommand(), new SsiEchoVarReplaceCommand("copyright", [rr0DefaultCopyright]), new StringEchoVarReplaceCommand(), new AngularExpressionReplaceCommand(), new SsiIfReplaceCommand(), new SsiSetVarReplaceCommand("title", (_match, ...args) => `<title>${args[0]}</title>`), new SsiSetVarReplaceCommand("url", (_match, ...args) => `<meta name="url" content="${args[0]}"/>`), new SsiLastModifiedReplaceCommand(timeFormat), new DescriptionReplaceCommand("UFO data for french-reading people", "abstract") ]; const contentsReplacers = [ new DomReplaceCommand("code", new CodeReplacerFactory()), new ClassDomReplaceCommand(new PlaceReplacerFactory(), "place"), new ClassDomReplaceCommand(new WitnessReplacerFactory(), "temoin", "temoin1", "temoin2", "temoin3"), new ClassDomReplaceCommand(new IndexedReplacerFactory(), "indexed"), new UnitReplaceCommand() ]; const generator = new CMSGenerator({ contentRoots, copies, outDir, locale: "fr", googleMapsApiKey, mail, dataOptions, siteBaseUrl, timeFormat, directoryPages, ufoCaseDirectoryFile: rr0TestUtil.filePath("science/crypto/ufo/enquete/dossier/index.html"), ufoCasesExclusions: ["science/crypto/ufo/enquete/dossier/canular"].map(path => rr0TestUtil.filePath(path)), sourceRegistryFileName, directoryExcluded: ["people/Astronomers_fichiers", "people/witness", "people/author"].map(path => rr0TestUtil.filePath(path)), directoryOptions, mappings, contentReplacers: [...pageReplacers, ...contentsReplacers] }); await generator.generate(args); }); });