svelte-sitemap 2.3.2 → 2.5.0-beta.0
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/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
# Svelte `sitemap.xml` generator
|
|
6
6
|
|
|
7
|
-
> Small helper which scans your Svelte routes and generates
|
|
7
|
+
> Small helper which scans your Svelte routes and generates _sitemap.xml_
|
|
8
8
|
>
|
|
9
|
+
> - Designed for Svelte `adapter-static` with `prerender` option
|
|
9
10
|
> - TypeScript, JavaScript, CLI version
|
|
10
11
|
> - Useful options
|
|
11
|
-
> - Compatible with Svelte `adapter-static`
|
|
12
12
|
> - Workaround for [this official SvelteKit issue](https://github.com/sveltejs/kit/issues/1142)
|
|
13
13
|
|
|
14
14
|
## Install
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-sitemap",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-beta.0",
|
|
4
4
|
"description": "Small helper which scans your Svelte routes folder and generates static sitemap.xml",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"author": "BART! <bart@bartweb.cz>",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"fast-glob": "^3.2.11",
|
|
32
|
-
"minimist": "^1.2.
|
|
32
|
+
"minimist": "^1.2.6",
|
|
33
33
|
"xmlbuilder2": "^3.0.2"
|
|
34
34
|
},
|
|
35
35
|
"repository": {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Options, PagesJson } from '../interfaces/global.interface';
|
|
2
|
+
export declare const removeHtml: (fileName: string) => string;
|
|
2
3
|
export declare function prepareData(domain: string, options?: Options): Promise<PagesJson[]>;
|
|
4
|
+
export declare const showErrors: (ERRORS: {
|
|
5
|
+
folder: boolean;
|
|
6
|
+
htmlFiles: boolean;
|
|
7
|
+
}) => void;
|
|
3
8
|
export declare const writeSitemap: (items: PagesJson[], options: Options) => void;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeSitemap = exports.prepareData = void 0;
|
|
6
|
+
exports.writeSitemap = exports.showErrors = exports.prepareData = exports.removeHtml = void 0;
|
|
7
7
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const xmlbuilder2_1 = require("xmlbuilder2");
|
|
@@ -18,19 +18,41 @@ const getUrl = (url, domain, options) => {
|
|
|
18
18
|
.split(((_a = options === null || options === void 0 ? void 0 : options.outDir) !== null && _a !== void 0 ? _a : vars_1.OUT_DIR) + '/')
|
|
19
19
|
.pop()
|
|
20
20
|
.replace('index.html', '');
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
trimmed = (0, exports.removeHtml)(trimmed);
|
|
22
|
+
// Add all traling slashes
|
|
23
|
+
if (options === null || options === void 0 ? void 0 : options.trailingSlashes) {
|
|
24
|
+
trimmed = trimmed.length && !trimmed.endsWith('/') ? trimmed + '/' : trimmed;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
23
27
|
trimmed = trimmed.endsWith('/') ? trimmed.slice(0, -1) : trimmed;
|
|
24
28
|
slash = trimmed ? slash : '';
|
|
25
29
|
}
|
|
26
30
|
return `${domain}${slash}${trimmed}`;
|
|
27
31
|
};
|
|
32
|
+
const removeHtml = (fileName) => {
|
|
33
|
+
if (fileName === null || fileName === void 0 ? void 0 : fileName.endsWith('.html')) {
|
|
34
|
+
return fileName.slice(0, -5);
|
|
35
|
+
}
|
|
36
|
+
return fileName;
|
|
37
|
+
};
|
|
38
|
+
exports.removeHtml = removeHtml;
|
|
28
39
|
async function prepareData(domain, options) {
|
|
29
40
|
var _a;
|
|
30
41
|
console.log(vars_helper_1.cliColors.cyanAndBold, `> Using ${vars_1.APP_NAME}`);
|
|
42
|
+
const FOLDER = (_a = options === null || options === void 0 ? void 0 : options.outDir) !== null && _a !== void 0 ? _a : vars_1.OUT_DIR;
|
|
43
|
+
const ERRORS = {
|
|
44
|
+
folder: false,
|
|
45
|
+
htmlFiles: false
|
|
46
|
+
};
|
|
31
47
|
const ignore = prepareIgnored(options === null || options === void 0 ? void 0 : options.ignore, options === null || options === void 0 ? void 0 : options.outDir);
|
|
32
48
|
const changeFreq = prepareChangeFreq(options);
|
|
33
|
-
const pages = await (0, fast_glob_1.default)(`${
|
|
49
|
+
const pages = await (0, fast_glob_1.default)(`${FOLDER}/**/*.html`, { ignore });
|
|
50
|
+
if (!fs_1.default.existsSync(FOLDER)) {
|
|
51
|
+
ERRORS.folder = true;
|
|
52
|
+
}
|
|
53
|
+
if (!pages.length) {
|
|
54
|
+
ERRORS.htmlFiles = true;
|
|
55
|
+
}
|
|
34
56
|
const results = pages.map((page) => {
|
|
35
57
|
return {
|
|
36
58
|
page: getUrl(page, domain, options),
|
|
@@ -38,9 +60,20 @@ async function prepareData(domain, options) {
|
|
|
38
60
|
lastMod: (options === null || options === void 0 ? void 0 : options.resetTime) ? new Date().toISOString().split('T')[0] : ''
|
|
39
61
|
};
|
|
40
62
|
});
|
|
63
|
+
(0, exports.showErrors)(ERRORS);
|
|
41
64
|
return results;
|
|
42
65
|
}
|
|
43
66
|
exports.prepareData = prepareData;
|
|
67
|
+
const showErrors = (ERRORS) => {
|
|
68
|
+
if (ERRORS.folder && ERRORS.htmlFiles) {
|
|
69
|
+
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsgFolder)(vars_1.OUT_DIR));
|
|
70
|
+
}
|
|
71
|
+
else if (ERRORS.htmlFiles) {
|
|
72
|
+
// If no page exists, then the static adapter is probably not used
|
|
73
|
+
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsgHtmlFiles)(vars_1.OUT_DIR));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.showErrors = showErrors;
|
|
44
77
|
const writeSitemap = (items, options) => {
|
|
45
78
|
var _a;
|
|
46
79
|
const sitemap = (0, xmlbuilder2_1.create)({ version: '1.0', encoding: 'UTF-8' }).ele('urlset', {
|
|
@@ -66,7 +99,7 @@ const writeSitemap = (items, options) => {
|
|
|
66
99
|
console.log(vars_helper_1.cliColors.green, (0, vars_helper_1.successMsg)(outDir));
|
|
67
100
|
}
|
|
68
101
|
catch (e) {
|
|
69
|
-
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.
|
|
102
|
+
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsgWrite)(outDir), e);
|
|
70
103
|
}
|
|
71
104
|
};
|
|
72
105
|
exports.writeSitemap = writeSitemap;
|
|
@@ -4,4 +4,6 @@ export declare const cliColors: {
|
|
|
4
4
|
red: string;
|
|
5
5
|
};
|
|
6
6
|
export declare const successMsg: (outDir: string) => string;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const errorMsgWrite: (outDir: string) => string;
|
|
8
|
+
export declare const errorMsgFolder: (outDir: string) => string;
|
|
9
|
+
export declare const errorMsgHtmlFiles: (outDir: string) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.errorMsgHtmlFiles = exports.errorMsgFolder = exports.errorMsgWrite = exports.successMsg = exports.cliColors = void 0;
|
|
4
4
|
exports.cliColors = {
|
|
5
5
|
cyanAndBold: '\x1b[36m\x1b[1m%s\x1b[22m\x1b[0m',
|
|
6
6
|
green: '\x1b[32m%s\x1b[0m',
|
|
@@ -8,5 +8,9 @@ exports.cliColors = {
|
|
|
8
8
|
};
|
|
9
9
|
const successMsg = (outDir) => ` ✔ done. Check your new sitemap here: ./${outDir}/sitemap.xml`;
|
|
10
10
|
exports.successMsg = successMsg;
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
11
|
+
const errorMsgWrite = (outDir) => ` × File '${outDir}/sitemap.xml' could not be created.`;
|
|
12
|
+
exports.errorMsgWrite = errorMsgWrite;
|
|
13
|
+
const errorMsgFolder = (outDir) => ` × Folder '${outDir}/' doesn't exist.\n Make sure you are using this library as 'postbuild' so '${outDir}/' folder was successfully created before running this script. See https://github.com/bartholomej/svelte-sitemap#readme`;
|
|
14
|
+
exports.errorMsgFolder = errorMsgFolder;
|
|
15
|
+
const errorMsgHtmlFiles = (outDir) => ` × There is no static html file in your '${outDir}/' folder. Are you sure you are using Svelte adapter-static with prerender option? See https://github.com/bartholomej/svelte-sitemap#readme`;
|
|
16
|
+
exports.errorMsgHtmlFiles = errorMsgHtmlFiles;
|
package/src/index.js
CHANGED
|
@@ -17,7 +17,7 @@ const createSitemap = async (domain = vars_1.DOMAIN, options) => {
|
|
|
17
17
|
(0, global_helper_1.writeSitemap)(json, options);
|
|
18
18
|
}
|
|
19
19
|
else {
|
|
20
|
-
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.
|
|
20
|
+
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsgWrite)((_a = options.outDir) !== null && _a !== void 0 ? _a : vars_1.OUT_DIR));
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
exports.createSitemap = createSitemap;
|