svelte-sitemap 2.1.1 → 2.2.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
@@ -2,7 +2,7 @@
2
2
  [![Package License](https://img.shields.io/npm/l/svelte-sitemap.svg)](https://www.npmjs.com/svelte-sitemap)
3
3
  [![Build & Publish](https://github.com/bartholomej/svelte-sitemap/workflows/Build%20&%20Publish/badge.svg)](https://github.com/bartholomej/svelte-sitemap/actions)
4
4
 
5
- # Svelte static sitemap.xml generator
5
+ # Svelte `sitemap.xml` generator
6
6
 
7
7
  > Small helper which scans your Svelte routes and generates static sitemap.xml
8
8
  >
@@ -13,61 +13,66 @@
13
13
 
14
14
  ## Install
15
15
 
16
- via yarn
16
+ via `yarn` or `npm`
17
17
 
18
18
  ```bash
19
19
  yarn add svelte-sitemap --dev
20
+ # npm install svelte-sitemap --save-dev
20
21
  ```
21
22
 
22
- via npm
23
+ ## Usage
23
24
 
24
- ```bash
25
- npm install svelte-sitemap --save-dev
26
- ```
25
+ ### CLI method (recommended)
27
26
 
28
- ## Usage
27
+ Run in your project root folder to see how it works.
29
28
 
30
- ### CLI
29
+ I recommend using it as a **postbuild hook**. See this [example](#example).
31
30
 
32
31
  ```bash
33
- svelte-sitemap --domain https://example.com
32
+ yarn svelte-sitemap --domain https://example.com
33
+ # npx svelte-sitemap --domain https://example.com
34
34
  ```
35
35
 
36
36
  It scans your routes in `build/` folder and generates `build/sitemap.xml` file
37
37
 
38
- ### JavaScript
38
+ ### TypeScript or JavaScript method (optional)
39
+
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.
39
41
 
40
- ```javascript
41
- import { createSitemap } from './src/index';
42
+ ```typescript
43
+ import { createSitemap } from 'svelte-sitemap/src/index.js';
42
44
 
43
45
  createSitemap('https://example.com', { debug: true });
44
46
  ```
45
47
 
48
+ And now you can run your script like this: `node my-script.js`
49
+
46
50
  ## Example
47
51
 
48
- Highly recommended to use as `postbuild` hook in you `package.json`
52
+ Highly recommended to use as `postbuild` hook in your `package.json`
49
53
 
50
54
  ```json
51
55
  {
52
56
  "name": "my-project",
53
57
  "scripts": {
54
- "postbuild": "svelte-sitemap --domain https://mydomain.com"
58
+ "postbuild": "npx svelte-sitemap --domain https://mydomain.com"
55
59
  }
56
60
  }
57
61
  ```
58
62
 
59
63
  ## Options
60
64
 
61
- | Option | Description | default | example |
62
- | ---------------------- | ---------------------------- | --------------------- | -------------------------------------- |
63
- | -d, --domain | Use your domain (required) | `https://example.com` | `-d https://mydomain.com` |
64
- | -o, --out-dir | Set custum build folder | `build` | `-o dist` |
65
- | -i, --ignore | Ignore files or folders | [] | `-i '**/admin/**' -i 'my-secret-page'` |
66
- | -t, --trailing-slashes | Add trailing slashes | false | `--trailing-slashes` |
67
- | -r, --reset-time | Set lastModified time to now | false | `-r` |
68
- | -h, --help | Display this usage info | - | - |
69
- | -v, --version | Show version | - | - |
70
- | --debug | Show some useful logs | - | `--debug` |
65
+ | Option | Description | default | example |
66
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------- | -------------------------------------- |
67
+ | -d, --domain | Use your domain **[required]** | `https://example.com` | `-d https://mydomain.com` |
68
+ | -o, --out-dir | Set custum build folder | `build` | `-o dist` |
69
+ | -i, --ignore | Ignore files or folders | [] | `-i '**/admin/**' -i 'my-secret-page'` |
70
+ | -t, --trailing-slashes | Add trailing slashes | false | `--trailing-slashes` |
71
+ | -r, --reset-time | Set lastModified time to now | false | `-r` |
72
+ | -c, --change-freq | Set change frequency [Option](https://github.com/bartholomej/svelte-sitemap/blob/master/src/interfaces/global.interface.ts#L22) | - | `--change-freq daily` |
73
+ | -h, --help | Display this usage info | - | `-v` |
74
+ | -v, --version | Show version | - | `-h` |
75
+ | --debug | Show some useful logs | - | `--debug` |
71
76
 
72
77
  ## FAQ
73
78
 
@@ -76,7 +81,7 @@ Highly recommended to use as `postbuild` hook in you `package.json`
76
81
  > Let's say we want to ignore all `admin` folders and subfolders + just one exact page `pages/my-secret-page`
77
82
 
78
83
  ```bash
79
- svelte-sitemap --domain https://www.example.com --ignore 'pages/my-secret-page' --ignore '**/admin/**'
84
+ npx svelte-sitemap --domain https://www.example.com --ignore 'pages/my-secret-page' --ignore '**/admin/**'
80
85
  ```
81
86
 
82
87
  ## Development
package/index.js CHANGED
@@ -38,7 +38,7 @@ const args = (0, minimist_1.default)(process.argv.slice(2), {
38
38
  });
39
39
  if (args.help || args.version === '' || args.version === true) {
40
40
  const log = args.help ? console.log : console.error;
41
- log('Static Sitemap generator for SvelteKit');
41
+ log('Svelte `sitemap.xml` generator');
42
42
  log('');
43
43
  log(`svelte-sitemap ${package_json_1.version} (check updates: ${REPO_URL})`);
44
44
  log('');
@@ -49,7 +49,7 @@ if (args.help || args.version === '' || args.version === true) {
49
49
  log(' -i, --ignore Exclude some pages or folders');
50
50
  log(' -t, --trailing-slashes Do you like trailing slashes?');
51
51
  log(' -r, --reset-time Set modified time to now');
52
- log(' -c, --change-freq Set change frequency `weekly` | `daily` | ...');
52
+ log(' -c, --change-freq Set change frequency `weekly` | `daily` | ');
53
53
  log(' -v, --version Show version');
54
54
  log(' --debug Debug mode');
55
55
  log(' ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-sitemap",
3
- "version": "2.1.1",
3
+ "version": "2.2.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>",
@@ -8,6 +8,7 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
8
8
  const fs_1 = __importDefault(require("fs"));
9
9
  const xmlbuilder2_1 = require("xmlbuilder2");
10
10
  const package_json_1 = require("../../package.json");
11
+ const global_interface_1 = require("../interfaces/global.interface");
11
12
  const vars_1 = require("../vars");
12
13
  const vars_helper_1 = require("./vars.helper");
13
14
  const getUrl = (url, domain, options) => {
@@ -28,12 +29,12 @@ async function prepareData(domain, options) {
28
29
  var _a;
29
30
  console.log(vars_helper_1.cliColors.cyanAndBold, `> Using ${vars_1.APP_NAME}`);
30
31
  const ignore = prepareIgnored(options === null || options === void 0 ? void 0 : options.ignore, options === null || options === void 0 ? void 0 : options.outDir);
32
+ const changeFreq = prepareChangeFreq(options);
31
33
  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 });
32
34
  const results = pages.map((page) => {
33
- var _a;
34
35
  return {
35
36
  page: getUrl(page, domain, options),
36
- changeFreq: (_a = options === null || options === void 0 ? void 0 : options.changeFreq) !== null && _a !== void 0 ? _a : '',
37
+ changeFreq: changeFreq,
37
38
  lastMod: (options === null || options === void 0 ? void 0 : options.resetTime) ? new Date().toISOString().split('T')[0] : ''
38
39
  };
39
40
  });
@@ -77,3 +78,15 @@ const prepareIgnored = (ignored, outDir = vars_1.OUT_DIR) => {
77
78
  }
78
79
  return ignore;
79
80
  };
81
+ const prepareChangeFreq = (options) => {
82
+ let result = null;
83
+ if (options === null || options === void 0 ? void 0 : options.changeFreq) {
84
+ if (global_interface_1.changeFreq.includes(options.changeFreq)) {
85
+ result = options.changeFreq;
86
+ }
87
+ else {
88
+ console.log(vars_helper_1.cliColors.red, ` × Option \`--change-freq ${options.changeFreq}\` is not a valid value. See docs: https://github.com/bartholomej/svelte-sitemap#options`);
89
+ }
90
+ }
91
+ return result;
92
+ };
@@ -16,4 +16,8 @@ export interface PagesJson {
16
16
  changeFreq?: ChangeFreq;
17
17
  lastMod?: string;
18
18
  }
19
- export declare type ChangeFreq = 'weekly' | 'daily' | string;
19
+ export declare const changeFreq: readonly ["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"];
20
+ /**
21
+ * Specs: https://www.sitemaps.org/protocol.html
22
+ */
23
+ export declare type ChangeFreq = typeof changeFreq[number];
@@ -1,2 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.changeFreq = void 0;
4
+ exports.changeFreq = [
5
+ 'always',
6
+ 'hourly',
7
+ 'daily',
8
+ 'weekly',
9
+ 'monthly',
10
+ 'yearly',
11
+ 'never'
12
+ ];