svelte-sitemap 2.3.1 → 2.3.2-beta.1
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 +29 -5
- package/index.js +23 -4
- package/package.json +1 -1
- package/src/helpers/config.d.ts +5 -0
- package/src/helpers/config.js +28 -0
- package/src/helpers/file.d.ts +1 -0
- package/src/helpers/file.js +16 -0
- package/src/helpers/global.helper.js +0 -1
- package/src/helpers/vars.helper.js +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +3 -5
- package/src/interfaces/global.interface.d.ts +3 -0
- package/src/vars.d.ts +1 -2
- package/src/vars.js +2 -2
package/README.md
CHANGED
|
@@ -22,7 +22,30 @@ yarn add svelte-sitemap --dev
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
###
|
|
25
|
+
### Config file method (recommended)
|
|
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)
|
|
26
49
|
|
|
27
50
|
Run in your project root folder to see how it works.
|
|
28
51
|
|
|
@@ -35,27 +58,27 @@ yarn svelte-sitemap --domain https://example.com
|
|
|
35
58
|
|
|
36
59
|
It scans your routes in `build/` folder and generates `build/sitemap.xml` file
|
|
37
60
|
|
|
38
|
-
### TypeScript or JavaScript method (
|
|
61
|
+
### TypeScript or JavaScript method (Alternative 2)
|
|
39
62
|
|
|
40
63
|
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.
|
|
41
64
|
|
|
42
65
|
```typescript
|
|
43
66
|
import { createSitemap } from 'svelte-sitemap/src/index.js';
|
|
44
67
|
|
|
45
|
-
createSitemap('https://example.com',
|
|
68
|
+
createSitemap({ domain: 'https://example.com', debug: true });
|
|
46
69
|
```
|
|
47
70
|
|
|
48
71
|
And now you can run your script like this: `node my-script.js`
|
|
49
72
|
|
|
50
73
|
## Example
|
|
51
74
|
|
|
52
|
-
Highly recommended to use as `postbuild` hook in your `package.json`
|
|
75
|
+
Highly recommended to use as `postbuild` hook in your `package.json` with config file `svelte-sitemap.cjs` in your project root.
|
|
53
76
|
|
|
54
77
|
```json
|
|
55
78
|
{
|
|
56
79
|
"name": "my-project",
|
|
57
80
|
"scripts": {
|
|
58
|
-
"postbuild": "npx svelte-sitemap
|
|
81
|
+
"postbuild": "npx svelte-sitemap"
|
|
59
82
|
}
|
|
60
83
|
}
|
|
61
84
|
```
|
|
@@ -114,6 +137,7 @@ yarn demo
|
|
|
114
137
|
- svelte-sitemap is workaround for [this official SvelteKit issue](https://github.com/sveltejs/kit/issues/1142)
|
|
115
138
|
- Brand new version is inspired by [Richard's article](https://r-bt.com/learning/sveltekit-sitemap/)
|
|
116
139
|
- 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)
|
|
117
141
|
|
|
118
142
|
## ⭐️ Show your support
|
|
119
143
|
|
package/index.js
CHANGED
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
|
+
var _a, _b;
|
|
6
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
8
|
const minimist_1 = __importDefault(require("minimist"));
|
|
8
9
|
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");
|
|
9
12
|
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}`);
|
|
10
15
|
const REPO_URL = 'https://github.com/bartholomej/svelte-sitemap';
|
|
11
16
|
let stop = false;
|
|
17
|
+
// Load svelte-sitemap.cjs
|
|
18
|
+
const config = (0, config_1.loadConfig)(vars_1.CONFIG_FILE);
|
|
12
19
|
const args = (0, minimist_1.default)(process.argv.slice(2), {
|
|
13
20
|
string: ['domain', 'out-dir', 'ignore', 'change-freq'],
|
|
14
21
|
boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],
|
|
@@ -55,11 +62,14 @@ if (args.help || args.version === '' || args.version === true) {
|
|
|
55
62
|
log(' ');
|
|
56
63
|
process.exit(args.help ? 0 : 1);
|
|
57
64
|
}
|
|
58
|
-
else if (!args.domain) {
|
|
65
|
+
else if (!config.domain && !args.domain) {
|
|
59
66
|
console.log(`⚠ svelte-sitemap: --domain argument is required.\n\nSee instructions: ${REPO_URL}\n\nExample:\n\n svelte-sitemap --domain https://mydomain.com\n`);
|
|
60
67
|
process.exit(0);
|
|
61
68
|
}
|
|
62
|
-
else if (
|
|
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'))) {
|
|
63
73
|
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`);
|
|
64
74
|
process.exit(0);
|
|
65
75
|
}
|
|
@@ -75,14 +85,23 @@ else {
|
|
|
75
85
|
const outDir = args['out-dir'];
|
|
76
86
|
const ignore = args['ignore'];
|
|
77
87
|
const attribution = args['attribution'] === '' || args['attribution'] === false ? false : true;
|
|
78
|
-
const
|
|
88
|
+
const optionsCli = {
|
|
79
89
|
debug,
|
|
80
90
|
resetTime,
|
|
81
91
|
changeFreq,
|
|
82
92
|
outDir,
|
|
93
|
+
domain,
|
|
83
94
|
attribution,
|
|
84
95
|
ignore,
|
|
85
96
|
trailingSlashes
|
|
86
97
|
};
|
|
87
|
-
|
|
98
|
+
// Config file is preferred
|
|
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
|
+
}
|
|
88
107
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const loadFile: <T>(fileName: string, throwError?: boolean) => T;
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -27,7 +27,6 @@ const getUrl = (url, domain, options) => {
|
|
|
27
27
|
};
|
|
28
28
|
async function prepareData(domain, options) {
|
|
29
29
|
var _a;
|
|
30
|
-
console.log(vars_helper_1.cliColors.cyanAndBold, `> Using ${vars_1.APP_NAME}`);
|
|
31
30
|
const ignore = prepareIgnored(options === null || options === void 0 ? void 0 : options.ignore, options === null || options === void 0 ? void 0 : options.outDir);
|
|
32
31
|
const changeFreq = prepareChangeFreq(options);
|
|
33
32
|
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: (
|
|
1
|
+
import { OptionsSvelteSitemap } from './interfaces/global.interface';
|
|
2
|
+
export declare const createSitemap: (options: OptionsSvelteSitemap) => Promise<void>;
|
package/src/index.js
CHANGED
|
@@ -3,13 +3,11 @@ 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
|
|
7
|
-
const createSitemap = async (domain = vars_1.DOMAIN, options) => {
|
|
8
|
-
var _a;
|
|
6
|
+
const createSitemap = async (options) => {
|
|
9
7
|
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
10
8
|
console.log('OPTIONS', options);
|
|
11
9
|
}
|
|
12
|
-
const json = await (0, global_helper_1.prepareData)(domain, options);
|
|
10
|
+
const json = await (0, global_helper_1.prepareData)(options.domain, options);
|
|
13
11
|
if (options === null || options === void 0 ? void 0 : options.debug) {
|
|
14
12
|
console.log('RESULT', json);
|
|
15
13
|
}
|
|
@@ -17,7 +15,7 @@ const createSitemap = async (domain = vars_1.DOMAIN, options) => {
|
|
|
17
15
|
(0, global_helper_1.writeSitemap)(json, options);
|
|
18
16
|
}
|
|
19
17
|
else {
|
|
20
|
-
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsg)(
|
|
18
|
+
console.error(vars_helper_1.cliColors.red, (0, vars_helper_1.errorMsg)(options.outDir));
|
|
21
19
|
}
|
|
22
20
|
};
|
|
23
21
|
exports.createSitemap = createSitemap;
|
package/src/vars.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Options } from './interfaces/global.interface';
|
|
2
1
|
export declare const APP_NAME = "svelte-sitemap";
|
|
3
2
|
export declare const DOMAIN = "https://example.com";
|
|
4
|
-
export declare const OPTIONS: Options;
|
|
5
3
|
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.CONFIG_FILE = exports.OUT_DIR = 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' };
|
|
7
6
|
exports.OUT_DIR = 'build';
|
|
7
|
+
exports.CONFIG_FILE = 'svelte-sitemap.cjs';
|