@rr0/cms 0.1.22 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,6 @@ export interface RR0BuildOptions {
11
11
  timeOptions: TimeServiceOptions;
12
12
  siteBaseUrl: string;
13
13
  timeFormat: Intl.DateTimeFormatOptions;
14
- timeFiles: string[];
15
14
  directoryPages: string[];
16
15
  ufoCaseDirectoryFile: string;
17
16
  ufoCasesExclusions: string[];
package/dist/RR0Build.js CHANGED
@@ -6,7 +6,7 @@ import { GooglePlaceService, PlaceReplacerFactory } from "./place/index.js";
6
6
  import { OrganizationFactory, OrganizationService } from "./org/index.js";
7
7
  import { RR0ContextImpl } from "./RR0Context.js";
8
8
  import { HtmlTable } from "./util/index.js";
9
- import { AngularExpressionReplaceCommand, ClassDomReplaceCommand, CopyStep, DomReplaceCommand, HtAccessToNetlifyConfigReplaceCommand, Ssg, SsiEchoVarReplaceCommand, SsiIfReplaceCommand, SsiIncludeReplaceCommand, SsiLastModifiedReplaceCommand, SsiSetVarReplaceCommand, StringEchoVarReplaceCommand } from "ssg-api";
9
+ import { AngularExpressionReplaceCommand, ClassDomReplaceCommand, CopyStep, DomReplaceCommand, HtAccessToNetlifyConfigReplaceCommand, HtmlFileContents, Ssg, SsiEchoVarReplaceCommand, SsiIfReplaceCommand, SsiIncludeReplaceCommand, SsiLastModifiedReplaceCommand, SsiSetVarReplaceCommand, StringEchoVarReplaceCommand } from "ssg-api";
10
10
  import { LanguageReplaceCommand } from "./lang/index.js";
11
11
  import { AuthorReplaceCommand, PeopleDirectoryStepFactory, PeopleFactory, PeopleReplacerFactory, PeopleService, WitnessReplacerFactory } from "./people";
12
12
  import { PersistentSourceRegistry, SourceFileCounter, SourceIndexStep, SourceRenderer, SourceReplacer, SourceReplacerFactory } from "./source";
@@ -31,7 +31,9 @@ import { writeFile } from "@javarome/fileutil";
31
31
  import { AllDataService, RR0EventFactory, TypedDataFactory } from "@rr0/data";
32
32
  const outputFunc = async (context, outFile) => {
33
33
  try {
34
- context.file.contents = context.file.serialize();
34
+ if (context.file instanceof HtmlFileContents) {
35
+ context.file.contents = context.file.serialize();
36
+ }
35
37
  context.log("Writing", outFile.name);
36
38
  await outFile.write();
37
39
  context.file.contents = outFile.contents;
@@ -74,7 +76,7 @@ export class RR0Build {
74
76
  }
75
77
  async run(args) {
76
78
  const context = this.context;
77
- const timeFiles = this.options.timeFiles;
79
+ const timeFiles = this.options.timeOptions.files;
78
80
  context.setVar("timeFilesCount", timeFiles.length);
79
81
  const timeService = this.timeService;
80
82
  const timeElementFactory = new TimeElementFactory(timeService.renderer);
@@ -1,17 +1,13 @@
1
1
  import { glob } from "glob";
2
2
  import { describe } from "@javarome/testscript";
3
- import { FileContents } from "@javarome/fileutil";
4
- import { CLI } from "./util/index.js";
5
3
  import { RR0Build } from "./RR0Build.js";
6
4
  import { testFilePath } from "./test";
7
5
  import * as process from "node:process";
8
6
  describe("Build", () => {
9
7
  console.time("ssg");
10
- let args = new CLI().getArgs();
11
- const configFile = args.config;
12
- if (configFile) {
13
- args = JSON.parse(FileContents.read(configFile).contents);
14
- }
8
+ const args = {
9
+ force: "true"
10
+ };
15
11
  const cliContents = args.contents;
16
12
  console.debug("contents", cliContents);
17
13
  const mandatoryRoots = ["people/*.html", "science/crypto/ufo/enquete/dossier/*.html"];
@@ -53,10 +49,6 @@ describe("Build", () => {
53
49
  if (!googleMapsApiKey) {
54
50
  throw Error("GOOGLE_MAPS_API_KEY is required");
55
51
  }
56
- const timeOptions = {
57
- root: testFilePath("time"),
58
- files: []
59
- };
60
52
  const timeFormat = {
61
53
  year: "numeric",
62
54
  month: "long",
@@ -97,9 +89,13 @@ describe("Build", () => {
97
89
  const sourceRegistryFileName = testFilePath("source/index.json");
98
90
  const siteBaseUrl = "https://rr0.org/";
99
91
  const mail = "rr0@rr0.org";
92
+ const timeOptions = {
93
+ root: testFilePath("time"),
94
+ files: timeFiles
95
+ };
100
96
  const build = new RR0Build({
101
97
  contentRoots, copies, outDir, locale: "fr", googleMapsApiKey, mail, timeOptions,
102
- siteBaseUrl, timeFormat, timeFiles, directoryPages,
98
+ siteBaseUrl, timeFormat, directoryPages,
103
99
  ufoCaseDirectoryFile: testFilePath("science/crypto/ufo/enquete/dossier/index.html"),
104
100
  ufoCasesExclusions: ["science/crypto/ufo/enquete/dossier/canular"].map(testFilePath),
105
101
  sourceRegistryFileName,
@@ -9,6 +9,15 @@ export class RR0ContextImpl extends SsgContextImpl {
9
9
  this.messages = messages;
10
10
  this.images = new Set();
11
11
  this.fileMap = new Map();
12
+ while (!this.messages) {
13
+ if (locale.length > 2) {
14
+ locale = locale.substring(0, 2); // Fallback to language without country specifics
15
+ }
16
+ else {
17
+ locale = "fr"; // Default language
18
+ }
19
+ this.messages = ssgMessages[locale];
20
+ }
12
21
  }
13
22
  read(filePath) {
14
23
  let file = this.fileMap.get(filePath);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { describe, expect, test } from "@javarome/testscript";
2
+ import { rr0TestUtil } from "./test";
3
+ import { ssgMessages } from "./lang";
4
+ describe("RROContextImpl", () => {
5
+ describe("constructor with locale", () => {
6
+ test("default locale", () => {
7
+ const context = rr0TestUtil.time.newHtmlContext("test.html", "");
8
+ expect(context.locale).toBe("fr");
9
+ });
10
+ test("supported locale", () => {
11
+ const context = rr0TestUtil.time.newHtmlContext("test.html", "", "en");
12
+ expect(context.locale).toBe("en");
13
+ });
14
+ test("locale fallback to lang only", () => {
15
+ const context = rr0TestUtil.time.newHtmlContext("test.html", "", "en-US");
16
+ expect(context.messages).toEqual(ssgMessages["en"]);
17
+ });
18
+ test("locale fallback to default", () => {
19
+ const context = rr0TestUtil.time.newHtmlContext("test.html", "", "xx");
20
+ expect(context.messages).toEqual(ssgMessages["fr"]);
21
+ });
22
+ });
23
+ });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@rr0/cms",
3
3
  "type": "module",
4
4
  "author": "Jérôme Beau <rr0@rr0.org> (https://rr0.org)",
5
- "version": "0.1.22",
5
+ "version": "0.1.24",
6
6
  "description": "RR0 Content Management System (CMS)",
7
7
  "exports": "./dist/index.js",
8
8
  "types": "./dist/index.d.ts",
@@ -23,14 +23,14 @@
23
23
  "build": "rm -Rf dist && tsc --project tsconfig.prod.json",
24
24
  "prepublishOnly": "npm run build",
25
25
  "test": "testscript",
26
- "test-one": "rm -Rf out && tsx src/RR0Build.test.ts",
26
+ "test-one": "rm -Rf out && tsx src/RR0Context.test.ts",
27
27
  "test-ci": "rm -Rf out && testscript"
28
28
  },
29
29
  "dependencies": {
30
30
  "@googlemaps/google-maps-services-js": "^3.4.0",
31
31
  "@rr0/common": "^1.1.3",
32
32
  "@rr0/lang": "^0.1.12",
33
- "@rr0/time": "^0.8.4",
33
+ "@rr0/time": "^0.8.5",
34
34
  "@rr0/place": "^0.3.2",
35
35
  "@rr0/data": "^0.1.2",
36
36
  "@javarome/fileutil": "^0.3.6",