svelte-sitemap 2.3.2-beta.1 → 2.4.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 +5 -29
- package/index.js +4 -23
- package/package.json +2 -2
- package/src/helpers/global.helper.d.ts +1 -0
- package/src/helpers/global.helper.js +15 -3
- package/src/helpers/vars.helper.js +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +5 -3
- package/src/interfaces/global.interface.d.ts +0 -3
- package/src/vars.d.ts +2 -1
- package/src/vars.js +2 -2
- package/src/helpers/config.d.ts +0 -5
- package/src/helpers/config.js +0 -28
- package/src/helpers/file.d.ts +0 -1
- package/src/helpers/file.js +0 -16
package/README.md
CHANGED
|
@@ -22,30 +22,7 @@ yarn add svelte-sitemap --dev
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
###
|
|
26
|
-
|
|
27
|
-
Create config file `svelte-sitemap.cjs` in the root of your project:
|
|
28
|
-
|
|
29
|
-
`svelte-sitemap.cjs`
|
|
30
|
-
|
|
31
|
-
```js
|
|
32
|
-
module.exports = {
|
|
33
|
-
domain: 'https://www.example.com'
|
|
34
|
-
// ...more options
|
|
35
|
-
};
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Add `svelte-sitemap` as your postbuild script in `package.json` file:
|
|
39
|
-
|
|
40
|
-
`package.json`
|
|
41
|
-
|
|
42
|
-
```json
|
|
43
|
-
{
|
|
44
|
-
"postbuild": "npx svelte-sitemap"
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### CLI method (Alternative 1)
|
|
25
|
+
### CLI method (recommended)
|
|
49
26
|
|
|
50
27
|
Run in your project root folder to see how it works.
|
|
51
28
|
|
|
@@ -58,27 +35,27 @@ yarn svelte-sitemap --domain https://example.com
|
|
|
58
35
|
|
|
59
36
|
It scans your routes in `build/` folder and generates `build/sitemap.xml` file
|
|
60
37
|
|
|
61
|
-
### TypeScript or JavaScript method (
|
|
38
|
+
### TypeScript or JavaScript method (optional)
|
|
62
39
|
|
|
63
40
|
Sometimes it can be useful to call the script directly from JavaScript or TypeScript. Of course there is also this option, but in most cases you will need the [CLI method](#cli-method-recommended) as a postbuild hook.
|
|
64
41
|
|
|
65
42
|
```typescript
|
|
66
43
|
import { createSitemap } from 'svelte-sitemap/src/index.js';
|
|
67
44
|
|
|
68
|
-
createSitemap(
|
|
45
|
+
createSitemap('https://example.com', { debug: true });
|
|
69
46
|
```
|
|
70
47
|
|
|
71
48
|
And now you can run your script like this: `node my-script.js`
|
|
72
49
|
|
|
73
50
|
## Example
|
|
74
51
|
|
|
75
|
-
Highly recommended to use as `postbuild` hook in your `package.json`
|
|
52
|
+
Highly recommended to use as `postbuild` hook in your `package.json`
|
|
76
53
|
|
|
77
54
|
```json
|
|
78
55
|
{
|
|
79
56
|
"name": "my-project",
|
|
80
57
|
"scripts": {
|
|
81
|
-
"postbuild": "npx svelte-sitemap"
|
|
58
|
+
"postbuild": "npx svelte-sitemap --domain https://mydomain.com"
|
|
82
59
|
}
|
|
83
60
|
}
|
|
84
61
|
```
|
|
@@ -137,7 +114,6 @@ yarn demo
|
|
|
137
114
|
- svelte-sitemap is workaround for [this official SvelteKit issue](https://github.com/sveltejs/kit/issues/1142)
|
|
138
115
|
- Brand new version is inspired by [Richard's article](https://r-bt.com/learning/sveltekit-sitemap/)
|
|
139
116
|
- Thanks to [@auderer](https://github.com/auderer) because [his issue](https://github.com/bartholomej/svelte-sitemap/issues/1) changed the direction of this library
|
|
140
|
-
- Config files inspired by [next-sitemap](https://github.com/iamvishnusankar/next-sitemap)
|
|
141
117
|
|
|
142
118
|
## ⭐️ Show your support
|
|
143
119
|
|
package/index.js
CHANGED
|
@@ -3,19 +3,12 @@
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
|
-
var _a, _b;
|
|
7
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
7
|
const minimist_1 = __importDefault(require("minimist"));
|
|
9
8
|
const package_json_1 = require("./package.json");
|
|
10
|
-
const config_1 = require("./src/helpers/config");
|
|
11
|
-
const vars_helper_1 = require("./src/helpers/vars.helper");
|
|
12
9
|
const index_1 = require("./src/index");
|
|
13
|
-
const vars_1 = require("./src/vars");
|
|
14
|
-
console.log(vars_helper_1.cliColors.cyanAndBold, `> Using ${vars_1.APP_NAME}`);
|
|
15
10
|
const REPO_URL = 'https://github.com/bartholomej/svelte-sitemap';
|
|
16
11
|
let stop = false;
|
|
17
|
-
// Load svelte-sitemap.cjs
|
|
18
|
-
const config = (0, config_1.loadConfig)(vars_1.CONFIG_FILE);
|
|
19
12
|
const args = (0, minimist_1.default)(process.argv.slice(2), {
|
|
20
13
|
string: ['domain', 'out-dir', 'ignore', 'change-freq'],
|
|
21
14
|
boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],
|
|
@@ -62,14 +55,11 @@ if (args.help || args.version === '' || args.version === true) {
|
|
|
62
55
|
log(' ');
|
|
63
56
|
process.exit(args.help ? 0 : 1);
|
|
64
57
|
}
|
|
65
|
-
else if (!
|
|
58
|
+
else if (!args.domain) {
|
|
66
59
|
console.log(`⚠ svelte-sitemap: --domain argument is required.\n\nSee instructions: ${REPO_URL}\n\nExample:\n\n svelte-sitemap --domain https://mydomain.com\n`);
|
|
67
60
|
process.exit(0);
|
|
68
61
|
}
|
|
69
|
-
else if (
|
|
70
|
-
// (config.domain || args.domain) &&
|
|
71
|
-
!((_a = config.domain) === null || _a === void 0 ? void 0 : _a.includes('http')) &&
|
|
72
|
-
!((_b = args.domain) === null || _b === void 0 ? void 0 : _b.includes('http'))) {
|
|
62
|
+
else if (!args.domain.includes('http')) {
|
|
73
63
|
console.log(`⚠ svelte-sitemap: --domain argument must starts with https://\n\nSee instructions: ${REPO_URL}\n\nExample:\n\n svelte-sitemap --domain https://mydomain.com\n`);
|
|
74
64
|
process.exit(0);
|
|
75
65
|
}
|
|
@@ -85,23 +75,14 @@ else {
|
|
|
85
75
|
const outDir = args['out-dir'];
|
|
86
76
|
const ignore = args['ignore'];
|
|
87
77
|
const attribution = args['attribution'] === '' || args['attribution'] === false ? false : true;
|
|
88
|
-
const
|
|
78
|
+
const options = {
|
|
89
79
|
debug,
|
|
90
80
|
resetTime,
|
|
91
81
|
changeFreq,
|
|
92
82
|
outDir,
|
|
93
|
-
domain,
|
|
94
83
|
attribution,
|
|
95
84
|
ignore,
|
|
96
85
|
trailingSlashes
|
|
97
86
|
};
|
|
98
|
-
|
|
99
|
-
if (config && Object.keys(config).length === 0) {
|
|
100
|
-
console.log(vars_helper_1.cliColors.cyanAndBold, ` ✔ Using CLI options. Config file ${vars_1.CONFIG_FILE} not found.`);
|
|
101
|
-
(0, index_1.createSitemap)(optionsCli);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
console.log(vars_helper_1.cliColors.green, ` ✔ Loading config from ${vars_1.CONFIG_FILE}. CLI options are ignored now.`);
|
|
105
|
-
(0, index_1.createSitemap)((0, config_1.withDefaultConfig)(config));
|
|
106
|
-
}
|
|
87
|
+
(0, index_1.createSitemap)(domain, options);
|
|
107
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-sitemap",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.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,4 @@
|
|
|
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[]>;
|
|
3
4
|
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.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,15 +18,27 @@ 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;
|
|
41
|
+
console.log(vars_helper_1.cliColors.cyanAndBold, `> Using ${vars_1.APP_NAME}`);
|
|
30
42
|
const ignore = prepareIgnored(options === null || options === void 0 ? void 0 : options.ignore, options === null || options === void 0 ? void 0 : options.outDir);
|
|
31
43
|
const changeFreq = prepareChangeFreq(options);
|
|
32
44
|
const pages = await (0, fast_glob_1.default)(`${(_a = options === null || options === void 0 ? void 0 : options.outDir) !== null && _a !== void 0 ? _a : vars_1.OUT_DIR}/**/*.html`, { ignore });
|
|
@@ -6,7 +6,7 @@ exports.cliColors = {
|
|
|
6
6
|
green: '\x1b[32m%s\x1b[0m',
|
|
7
7
|
red: '\x1b[31m%s\x1b[0m'
|
|
8
8
|
};
|
|
9
|
-
const successMsg = (outDir) => ` ✔
|
|
9
|
+
const successMsg = (outDir) => ` ✔ done. Check your new sitemap here: ./${outDir}/sitemap.xml`;
|
|
10
10
|
exports.successMsg = successMsg;
|
|
11
11
|
const errorMsg = (outDir) => ` × Make sure you are using this script as 'postbuild' so '${outDir}' folder was successfully created before running this script. See https://github.com/bartholomej/svelte-sitemap#readme`;
|
|
12
12
|
exports.errorMsg = errorMsg;
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const createSitemap: (options
|
|
1
|
+
import { Options } from './interfaces/global.interface';
|
|
2
|
+
export declare const createSitemap: (domain?: string, options?: Options) => Promise<void>;
|
package/src/index.js
CHANGED
|
@@ -3,11 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createSitemap = void 0;
|
|
4
4
|
const global_helper_1 = require("./helpers/global.helper");
|
|
5
5
|
const vars_helper_1 = require("./helpers/vars.helper");
|
|
6
|
-
const
|
|
6
|
+
const vars_1 = require("./vars");
|
|
7
|
+
const createSitemap = async (domain = vars_1.DOMAIN, options) => {
|
|
8
|
+
var _a;
|
|
7
9
|
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
8
10
|
console.log('OPTIONS', options);
|
|
9
11
|
}
|
|
10
|
-
const json = await (0, global_helper_1.prepareData)(
|
|
12
|
+
const json = await (0, global_helper_1.prepareData)(domain, options);
|
|
11
13
|
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
12
14
|
console.log('RESULT', json);
|
|
13
15
|
}
|
|
@@ -15,7 +17,7 @@ const createSitemap = async (options) => {
|
|
|
15
17
|
(0, global_helper_1.writeSitemap)(json, options);
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
18
|
-
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsg)(options.outDir));
|
|
20
|
+
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsg)((_a = options.outDir) !== null && _a !== void 0 ? _a : vars_1.OUT_DIR));
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
23
|
exports.createSitemap = createSitemap;
|
package/src/vars.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { Options } from './interfaces/global.interface';
|
|
1
2
|
export declare const APP_NAME = "svelte-sitemap";
|
|
2
3
|
export declare const DOMAIN = "https://example.com";
|
|
4
|
+
export declare const OPTIONS: Options;
|
|
3
5
|
export declare const OUT_DIR = "build";
|
|
4
|
-
export declare const CONFIG_FILE = "svelte-sitemap.cjs";
|
package/src/vars.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.OUT_DIR = exports.OPTIONS = exports.DOMAIN = exports.APP_NAME = void 0;
|
|
4
4
|
exports.APP_NAME = 'svelte-sitemap';
|
|
5
5
|
exports.DOMAIN = 'https://example.com';
|
|
6
|
+
exports.OPTIONS = { resetTime: false, debug: false, changeFreq: 'weekly' };
|
|
6
7
|
exports.OUT_DIR = 'build';
|
|
7
|
-
exports.CONFIG_FILE = 'svelte-sitemap.cjs';
|
package/src/helpers/config.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { OptionsSvelteSitemap } from '../interfaces/global.interface';
|
|
2
|
-
export declare const loadConfig: (path: string) => OptionsSvelteSitemap;
|
|
3
|
-
export declare const defaultConfig: OptionsSvelteSitemap;
|
|
4
|
-
export declare const updateConfig: (currConfig: OptionsSvelteSitemap, newConfig: OptionsSvelteSitemap) => OptionsSvelteSitemap;
|
|
5
|
-
export declare const withDefaultConfig: (config: OptionsSvelteSitemap) => OptionsSvelteSitemap;
|
package/src/helpers/config.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withDefaultConfig = exports.updateConfig = exports.defaultConfig = exports.loadConfig = void 0;
|
|
4
|
-
const vars_1 = require("./../vars");
|
|
5
|
-
const file_1 = require("./file");
|
|
6
|
-
const loadConfig = (path) => {
|
|
7
|
-
const baseConfig = (0, file_1.loadFile)(path);
|
|
8
|
-
return baseConfig;
|
|
9
|
-
};
|
|
10
|
-
exports.loadConfig = loadConfig;
|
|
11
|
-
exports.defaultConfig = {
|
|
12
|
-
debug: false,
|
|
13
|
-
changeFreq: null,
|
|
14
|
-
resetTime: false,
|
|
15
|
-
outDir: vars_1.OUT_DIR,
|
|
16
|
-
attribution: true,
|
|
17
|
-
ignore: null,
|
|
18
|
-
trailingSlashes: false,
|
|
19
|
-
domain: null
|
|
20
|
-
};
|
|
21
|
-
const updateConfig = (currConfig, newConfig) => {
|
|
22
|
-
return Object.assign(Object.assign({}, currConfig), newConfig);
|
|
23
|
-
};
|
|
24
|
-
exports.updateConfig = updateConfig;
|
|
25
|
-
const withDefaultConfig = (config) => {
|
|
26
|
-
return (0, exports.updateConfig)(exports.defaultConfig, config);
|
|
27
|
-
};
|
|
28
|
-
exports.withDefaultConfig = withDefaultConfig;
|
package/src/helpers/file.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const loadFile: <T>(fileName: string, throwError?: boolean) => T;
|
package/src/helpers/file.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadFile = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const loadFile = (fileName, throwError = true) => {
|
|
7
|
-
const filePath = (0, path_1.resolve)((0, path_1.resolve)(process.cwd(), fileName));
|
|
8
|
-
if ((0, fs_1.existsSync)(filePath)) {
|
|
9
|
-
return require(filePath);
|
|
10
|
-
}
|
|
11
|
-
if (throwError) {
|
|
12
|
-
new Error(`${filePath} does not exist.`);
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
};
|
|
16
|
-
exports.loadFile = loadFile;
|