olum-compiler 2.0.2 → 2.0.4
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.
- package/bin/ssg.js +11 -2
- package/lib/helpers.js +19 -6
- package/package.json +1 -1
package/bin/ssg.js
CHANGED
|
@@ -197,14 +197,17 @@ const xmlEscape = (str) =>
|
|
|
197
197
|
.replace(/'/g, "'");
|
|
198
198
|
|
|
199
199
|
function writeSitemapXml(finalRoutes) {
|
|
200
|
+
const has404 = finalRoutes.find((item) => item == "/404");
|
|
200
201
|
const base = siteUrl();
|
|
201
202
|
if (!base)
|
|
202
203
|
fail(
|
|
203
204
|
'no package.json "olum.SITE_URL" — sitemap.xml falls back to relative paths, which crawlers ignore',
|
|
204
205
|
);
|
|
205
206
|
|
|
206
|
-
const urls = finalRoutes.filter(
|
|
207
|
-
|
|
207
|
+
const urls = finalRoutes.filter(
|
|
208
|
+
(route) =>
|
|
209
|
+
route !== "/404" &&
|
|
210
|
+
fs.existsSync(path.join(distDir, route, "index.html")),
|
|
208
211
|
);
|
|
209
212
|
const lastmod = new Date().toISOString().slice(0, 10);
|
|
210
213
|
const body = urls
|
|
@@ -218,6 +221,12 @@ function writeSitemapXml(finalRoutes) {
|
|
|
218
221
|
path.join(distDir, "sitemap.xml"),
|
|
219
222
|
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${body}\n</urlset>\n`,
|
|
220
223
|
);
|
|
224
|
+
|
|
225
|
+
if (has404 && fs.existsSync(path.join(distDir, "404", "index.html")))
|
|
226
|
+
fs.copyFileSync(
|
|
227
|
+
path.join(distDir, "404", "index.html"),
|
|
228
|
+
path.join(distDir, "404.html"),
|
|
229
|
+
);
|
|
221
230
|
return urls.length;
|
|
222
231
|
}
|
|
223
232
|
|
package/lib/helpers.js
CHANGED
|
@@ -33,9 +33,20 @@ const cleanParentheses = (filePath, type = "name") => {
|
|
|
33
33
|
|
|
34
34
|
const cleanNumbersPrefix = (name, type = "name") => {
|
|
35
35
|
if (type === "url") {
|
|
36
|
-
|
|
36
|
+
const trimmedDigit =
|
|
37
|
+
name.match(/(?:^|\/)(\d+)-/)?.[1] ?? name.match(/-(\d+)$/)?.[1] ?? "";
|
|
38
|
+
return {
|
|
39
|
+
name: name.replace(/(^|\/)\d+-/g, "$1"),
|
|
40
|
+
trimmedDigit,
|
|
41
|
+
};
|
|
37
42
|
}
|
|
38
|
-
|
|
43
|
+
|
|
44
|
+
const trimmedDigit =
|
|
45
|
+
name.match(/^(\d+)/)?.[1] ?? name.match(/(\d+)$/)?.[1] ?? "";
|
|
46
|
+
return {
|
|
47
|
+
name: name.replace(/\d+-?/g, ""),
|
|
48
|
+
trimmedDigit,
|
|
49
|
+
};
|
|
39
50
|
};
|
|
40
51
|
|
|
41
52
|
function isUpper(char) {
|
|
@@ -717,8 +728,8 @@ function toComponentName(file) {
|
|
|
717
728
|
function generateImports(manifest) {
|
|
718
729
|
return Object.values(manifest)
|
|
719
730
|
.map(({ page }) => {
|
|
720
|
-
const
|
|
721
|
-
return `import ${
|
|
731
|
+
const { name, trimmedDigit } = cleanNumbersPrefix(toComponentName(page));
|
|
732
|
+
return `import ${name}${trimmedDigit ? "_" + trimmedDigit : ""} from "./${page.replace(/.html$/, ".js")}";`;
|
|
722
733
|
})
|
|
723
734
|
.join("\n");
|
|
724
735
|
}
|
|
@@ -753,8 +764,10 @@ function generateRoutes(manifest) {
|
|
|
753
764
|
const result = `export const routes = [
|
|
754
765
|
${routes
|
|
755
766
|
.map(({ path, comp }) => {
|
|
756
|
-
|
|
757
|
-
|
|
767
|
+
const { name } = cleanNumbersPrefix(path, "url");
|
|
768
|
+
const _comp = cleanNumbersPrefix(comp);
|
|
769
|
+
paths.push(name);
|
|
770
|
+
return ` { path: "${name}", comp: ${_comp.name}${_comp.trimmedDigit ? "_" + _comp.trimmedDigit : ""} }`;
|
|
758
771
|
})
|
|
759
772
|
.join(",\n")}
|
|
760
773
|
];`;
|