@rr0/cms 0.3.43 → 0.3.45
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.
|
@@ -7,35 +7,39 @@ export class LanguageReplaceCommand extends DomReplaceCommand {
|
|
|
7
7
|
super("#alternate", undefined);
|
|
8
8
|
}
|
|
9
9
|
async createReplacer(context) {
|
|
10
|
-
const doc = context.file.document;
|
|
11
10
|
return new class {
|
|
12
11
|
async replace(original) {
|
|
13
12
|
if (!original.hasChildNodes()) {
|
|
14
13
|
const inputFile = context.file;
|
|
14
|
+
const fileName = inputFile.name;
|
|
15
15
|
const langInfo = inputFile.lang;
|
|
16
16
|
const variants = langInfo.variants;
|
|
17
|
-
|
|
17
|
+
let fileLang = langInfo.lang;
|
|
18
18
|
let pageLang;
|
|
19
19
|
const hasEnglishVariant = variants.includes("en");
|
|
20
20
|
if (hasEnglishVariant) {
|
|
21
|
-
pageLang =
|
|
21
|
+
pageLang = fileLang ? fileLang : "fr";
|
|
22
22
|
}
|
|
23
|
-
else {
|
|
24
|
-
if (
|
|
25
|
-
pageLang =
|
|
23
|
+
else if (variants.includes("fr")) {
|
|
24
|
+
if (fileLang && fileLang !== "fr") {
|
|
25
|
+
pageLang = fileLang;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
pageLang = "
|
|
28
|
+
pageLang = "en";
|
|
29
|
+
fileLang = fileName.includes("_" + pageLang) ? pageLang : "";
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
else {
|
|
33
|
+
pageLang = "fr";
|
|
34
|
+
}
|
|
35
|
+
inputFile.document.documentElement.lang = inputFile.lang.lang = pageLang;
|
|
32
36
|
const langVariants = variants.length == 1 && variants[0] == "" ? [pageLang == "fr" ? "en" : "fr"] : variants;
|
|
33
|
-
const
|
|
37
|
+
const doc = inputFile.document;
|
|
34
38
|
for (let i = 0; i < langVariants.length; i++) {
|
|
35
39
|
const langVariant = langVariants[i];
|
|
36
40
|
const altLink = doc.createElement("a");
|
|
37
|
-
const toReplace = (
|
|
38
|
-
|
|
41
|
+
const toReplace = (fileLang ? "_" + fileLang : "") + ".";
|
|
42
|
+
let replacement = `${variants[i] == "" ? "" : "_" + langVariant}.`;
|
|
39
43
|
altLink.href = "/" + fileName.replace(toReplace, replacement);
|
|
40
44
|
const altText = langVariant === "en" ? "English version" : "Version française";
|
|
41
45
|
altLink.textContent = Buffer.from(altText, "utf-8").toString();
|
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.3.
|
|
5
|
+
"version": "0.3.45",
|
|
6
6
|
"description": "RR0 Content Management System (CMS)",
|
|
7
7
|
"exports": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"preview": "vite preview --host",
|
|
24
24
|
"build": "rm -Rf dist && tsc --project tsconfig.prod.json",
|
|
25
25
|
"circular-deps": "dpdm src",
|
|
26
|
-
"prepublishOnly": "npm run build && npm test",
|
|
26
|
+
"prepublishOnly": "npm run build && npm run test-ci",
|
|
27
27
|
"test": "testscript",
|
|
28
|
-
"test-one": "rm -Rf out && tsx src/
|
|
28
|
+
"test-one": "rm -Rf out && tsx src/CMSGenerator.test.ts",
|
|
29
29
|
"test-ci": "rm -Rf out && testscript"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"image-size": "^2.0.2",
|
|
42
42
|
"jsdom": "^26.1.0",
|
|
43
43
|
"selenium-webdriver": "^4.32.0",
|
|
44
|
-
"ssg-api": "^1.
|
|
44
|
+
"ssg-api": "^1.17.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@javarome/testscript": "^0.13.1",
|