olum-compiler 2.0.1 → 2.0.3
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 +15 -5
- package/lib/helpers.js +0 -1
- package/package.json +1 -1
package/bin/ssg.js
CHANGED
|
@@ -156,8 +156,9 @@ function siteUrl() {
|
|
|
156
156
|
return "";
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
+
const DEFAULT_DELAY = 500;
|
|
159
160
|
function readDelay(raw, source) {
|
|
160
|
-
if (raw === undefined || raw === null || raw === "") return
|
|
161
|
+
if (raw === undefined || raw === null || raw === "") return DEFAULT_DELAY;
|
|
161
162
|
|
|
162
163
|
const ms =
|
|
163
164
|
typeof raw === "number" || typeof raw === "string" ? Number(raw) : NaN;
|
|
@@ -166,7 +167,7 @@ function readDelay(raw, source) {
|
|
|
166
167
|
fail(
|
|
167
168
|
`ignoring ${source} — expected a number of milliseconds, got ${shown}`,
|
|
168
169
|
);
|
|
169
|
-
return
|
|
170
|
+
return DEFAULT_DELAY;
|
|
170
171
|
}
|
|
171
172
|
return Math.round(ms);
|
|
172
173
|
}
|
|
@@ -181,7 +182,7 @@ function ssgDelay() {
|
|
|
181
182
|
'package.json "olum.SSG_DELAY"',
|
|
182
183
|
);
|
|
183
184
|
} catch (err) {
|
|
184
|
-
return
|
|
185
|
+
return DEFAULT_DELAY;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
188
|
|
|
@@ -196,14 +197,17 @@ const xmlEscape = (str) =>
|
|
|
196
197
|
.replace(/'/g, "'");
|
|
197
198
|
|
|
198
199
|
function writeSitemapXml(finalRoutes) {
|
|
200
|
+
const has404 = finalRoutes.find((item) => item == "/404");
|
|
199
201
|
const base = siteUrl();
|
|
200
202
|
if (!base)
|
|
201
203
|
fail(
|
|
202
204
|
'no package.json "olum.SITE_URL" — sitemap.xml falls back to relative paths, which crawlers ignore',
|
|
203
205
|
);
|
|
204
206
|
|
|
205
|
-
const urls = finalRoutes.filter(
|
|
206
|
-
|
|
207
|
+
const urls = finalRoutes.filter(
|
|
208
|
+
(route) =>
|
|
209
|
+
route !== "/404" &&
|
|
210
|
+
fs.existsSync(path.join(distDir, route, "index.html")),
|
|
207
211
|
);
|
|
208
212
|
const lastmod = new Date().toISOString().slice(0, 10);
|
|
209
213
|
const body = urls
|
|
@@ -217,6 +221,12 @@ function writeSitemapXml(finalRoutes) {
|
|
|
217
221
|
path.join(distDir, "sitemap.xml"),
|
|
218
222
|
`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${body}\n</urlset>\n`,
|
|
219
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
|
+
);
|
|
220
230
|
return urls.length;
|
|
221
231
|
}
|
|
222
232
|
|
package/lib/helpers.js
CHANGED
|
@@ -20,7 +20,6 @@ const base64ToString = (base64) =>
|
|
|
20
20
|
Buffer.from(base64, "base64").toString("ascii");
|
|
21
21
|
const acorn = require("acorn");
|
|
22
22
|
|
|
23
|
-
// keep in sync with bin/ssg.js, which reads this same file
|
|
24
23
|
const routesPath = path.resolve(__dirname, "../routes.json");
|
|
25
24
|
|
|
26
25
|
const cleanParentheses = (filePath, type = "name") => {
|