svelte-sitemap 3.3.0-next.0 → 3.3.0-next.2

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
@@ -26,9 +26,37 @@ npm install svelte-sitemap --save-dev
26
26
 
27
27
  ## 🚀 Usage
28
28
 
29
- > There are four ways to use this library. Pick the one that suits you best.
29
+ > If you're using SvelteKit with Vite (which is the default), you can integrate the sitemap generation directly into the Vite build pipeline.
30
30
 
31
- ### Method 1: Config file (recommended)
31
+ Add the plugin to your `vite.config.ts`:
32
+
33
+ ```typescript
34
+ // vite.config.ts
35
+ import { sveltekit } from '@sveltejs/kit/vite';
36
+ import { svelteSitemap } from 'svelte-sitemap/vite'; // <-- Add svelte-sitemap vite plugin
37
+ import { defineConfig } from 'vite';
38
+
39
+ export default defineConfig({
40
+ plugins: [
41
+ sveltekit(),
42
+ svelteSitemap({ domain: 'https://example.com' }) // <-- Configure the plugin with your options
43
+ ]
44
+ });
45
+ ```
46
+
47
+ The sitemap is generated automatically at the end of every `vite build`. All [options](#%EF%B8%8F-options) are supported.
48
+
49
+ ---
50
+
51
+ ### Alternative Methods
52
+
53
+ For other setups, the following methods are still supported but are deprecated in favor of the Vite plugin.
54
+
55
+ <details>
56
+ <summary><b>✨ Config file</b></summary>
57
+
58
+ > [!WARNING]
59
+ > Running the generator via CLI is an alternative. We recommend migrating to the **Vite plugin** instead.
32
60
 
33
61
  Create a config file `svelte-sitemap.config.ts` in the root of your project:
34
62
 
@@ -55,11 +83,15 @@ Then add `svelte-sitemap` as a `postbuild` script in `package.json`:
55
83
  }
56
84
  ```
57
85
 
58
- That's it. After every `build`, the sitemap is automatically generated in your `build/` folder.
86
+ After every `build`, the sitemap is generated in your `build/` folder.
59
87
 
60
- ---
88
+ </details>
61
89
 
62
- ### ⌨️ Method 2: CLI (legacy)
90
+ <details>
91
+ <summary><b>⌨️ CLI flags (Deprecated)</b></summary>
92
+
93
+ > [!WARNING]
94
+ > Passing configuration options directly as CLI flags is deprecated and will be removed in a future version. Please use the **Vite plugin** or a **config file** instead.
63
95
 
64
96
  Pass options directly as CLI flags — no config file needed:
65
97
 
@@ -73,9 +105,13 @@ Pass options directly as CLI flags — no config file needed:
73
105
 
74
106
  See all available flags in the [Options](#%EF%B8%8F-options) table below.
75
107
 
76
- ---
108
+ </details>
109
+
110
+ <details>
111
+ <summary><b>🔧 JavaScript / TypeScript API (Deprecated)</b></summary>
77
112
 
78
- ### 🔧 Method 3: JavaScript / TypeScript API
113
+ > [!WARNING]
114
+ > Calling the generator programmatically is deprecated. We recommend migrating to the **Vite plugin** instead.
79
115
 
80
116
  Sometimes it's useful to call the script directly from code:
81
117
 
@@ -92,29 +128,46 @@ Run your script:
92
128
  node my-script.js
93
129
  ```
94
130
 
95
- ---
96
-
97
- ### ⚡ Method 4: Vite plugin
98
-
99
- If you're using SvelteKit with Vite (which is the default), you can integrate the sitemap generation directly into the Vite build pipeline — no extra `postbuild` script needed.
131
+ </details>
100
132
 
101
- Add the plugin to your `vite.config.ts`:
102
-
103
- ```typescript
104
- // vite.config.ts
105
- import { sveltekit } from '@sveltejs/kit/vite';
106
- import { svelteSitemap } from 'svelte-sitemap/vite'; // <-- Add svelte-sitemap vite plugin
107
- import { defineConfig } from 'vite';
108
-
109
- export default defineConfig({
110
- plugins: [
111
- sveltekit(),
112
- svelteSitemap({ domain: 'https://example.com' }) // <-- Configure the plugin with your options
113
- ]
114
- });
115
- ```
133
+ ---
116
134
 
117
- The sitemap is generated automatically at the end of every `vite build`. All [options](#%EF%B8%8F-options) are supported.
135
+ ## 🔄 Migration to Vite Plugin
136
+
137
+ Migrating from the CLI or config file to the Vite plugin is quick and straightforward:
138
+
139
+ 1. **Remove `svelte-sitemap` from `package.json` scripts:**
140
+ ```diff
141
+ {
142
+ "scripts": {
143
+ - "postbuild": "npx svelte-sitemap"
144
+ }
145
+ }
146
+ ```
147
+
148
+ 2. **Delete your config file** (e.g., `svelte-sitemap.config.ts`) if you have one.
149
+
150
+ 3. **Register the plugin in `vite.config.ts`:**
151
+ Import `svelteSitemap` and configure your options directly inside the plugin. Convert any CLI flags (kebab-case) or config keys (camelCase) to option keys:
152
+
153
+ ```typescript
154
+ // vite.config.ts
155
+ import { sveltekit } from '@sveltejs/kit/vite';
156
+ import { svelteSitemap } from 'svelte-sitemap/vite';
157
+ import { defineConfig } from 'vite';
158
+
159
+ export default defineConfig({
160
+ plugins: [
161
+ sveltekit(),
162
+ svelteSitemap({
163
+ domain: 'https://example.com',
164
+ // Convert your existing config/flags to options, e.g.:
165
+ // --ignore / ignore -> ignore: ['**/admin/**']
166
+ // --out-dir / outDir -> outDir: 'dist'
167
+ })
168
+ ]
169
+ });
170
+ ```
118
171
 
119
172
  ---
120
173
 
package/cli.js CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import { APP_NAME, CONFIG_FILES, REPO_URL } from "./const.js";
2
+ import { CONFIG_FILES, REPO_URL } from "./const.js";
3
3
  import { version as version$1 } from "./package.js";
4
4
  import { cliColors, errorMsgGeneration } from "./helpers/vars.helper.js";
5
- import { createSitemap } from "./index.js";
5
+ import { createSitemap, printIntro } from "./index.js";
6
6
  import { defaultConfig, loadConfig, withDefaultConfig } from "./helpers/config.js";
7
7
  import minimist from "minimist";
8
8
  //#region src/cli.ts
9
9
  const version = version$1;
10
10
  const main = async () => {
11
- console.log(cliColors.cyanAndBold, `> Using ${APP_NAME}`);
12
11
  let stop = false;
13
12
  const config = await loadConfig(CONFIG_FILES);
14
13
  const args = minimist(process.argv.slice(2), {
@@ -77,9 +76,12 @@ const main = async () => {
77
76
  log(" --debug Debug mode");
78
77
  log(" ");
79
78
  process.exit(args.help ? 0 : 1);
80
- } else if (config && Object.keys(config).length > 0) {
79
+ }
80
+ printIntro();
81
+ if (config && Object.keys(config).length > 0) {
81
82
  const hasCliOptions = process.argv.slice(2).length > 0;
82
83
  console.log(cliColors.green, ` ✔ Reading config file...`);
84
+ console.log(cliColors.yellow, ` ⚠ Deprecated: Running svelte-sitemap via CLI is deprecated. Please use the Vite plugin instead. See ${REPO_URL}#-usage`);
83
85
  const allowedKeys = Object.keys(defaultConfig);
84
86
  const invalidKeys = Object.keys(config).filter((key) => !allowedKeys.includes(key));
85
87
  if (invalidKeys.length > 0) console.log(cliColors.yellow, ` ⚠ Invalid properties in config file, so I ignore them: ${invalidKeys.join(", ")}`);
@@ -134,7 +136,7 @@ const main = async () => {
134
136
  trailingSlashes,
135
137
  additional
136
138
  };
137
- console.log(cliColors.yellow, ` Hint: Configuration file is now the preferred method to set up svelte-sitemap. See ${REPO_URL}?tab=readme-ov-file#-usage`);
139
+ console.log(cliColors.yellow, ` Deprecated: Passing options directly via CLI flags is deprecated and will be removed in a future version. Please use the Vite plugin (recommended) or a config file. See ${REPO_URL}#-usage`);
138
140
  console.log(cliColors.cyanAndBold, ` ✔ Using CLI options. Config file not found.`);
139
141
  try {
140
142
  await createSitemap(optionsCli);
package/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":["pkg.version"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport minimist from 'minimist';\nimport pkg from './../package.json' with { type: 'json' };\nimport { APP_NAME, CONFIG_FILES, REPO_URL } from './const.js';\nimport type { ChangeFreq, OptionsSvelteSitemap } from './dto/index.js';\nimport { defaultConfig, loadConfig, withDefaultConfig } from './helpers/config.js';\nimport { cliColors, errorMsgGeneration } from './helpers/vars.helper.js';\nimport { createSitemap } from './index.js';\nconst version = pkg.version;\n\nconst main = async () => {\n console.log(cliColors.cyanAndBold, `> Using ${APP_NAME}`);\n\n let stop = false;\n\n const config = await loadConfig(CONFIG_FILES);\n\n const args = minimist(process.argv.slice(2), {\n string: ['domain', 'out-dir', 'ignore', 'change-freq', 'additional'],\n boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],\n default: { attribution: true, 'trailing-slashes': false, default: false },\n alias: {\n d: 'domain',\n D: 'domain',\n h: 'help',\n H: 'help',\n v: 'version',\n V: 'version',\n O: 'out-dir',\n o: 'out-dir',\n r: 'reset-time',\n R: 'reset-time',\n c: 'change-freq',\n C: 'change-freq',\n i: 'ignore',\n I: 'ignore',\n t: 'trailing-slashes',\n T: 'trailing-slashes',\n a: 'additional',\n A: 'additional'\n },\n unknown: (err: string) => {\n if (config && Object.keys(config).length > 0) return false;\n console.log(cliColors.yellow, ' ⚠ This argument is not supported:', err);\n // console.log(cliColors.yellow, ' Use: `svelte-sitemap --help` for more options.');\n stop = true;\n return false;\n }\n });\n\n if (args.help || args.version === '' || args.version === true) {\n const log = args.help ? console.log : console.error;\n log('Svelte `sitemap.xml` generator');\n log('');\n log(`svelte-sitemap ${version} (check updates: ${REPO_URL})`);\n log('');\n log('Options:');\n log('');\n log(' -d, --domain Use your domain (eg. https://example.com)');\n log(' -o, --out-dir Custom output dir');\n log(' -i, --ignore Exclude some pages or folders');\n log(' -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)');\n log(' -t, --trailing-slashes Do you like trailing slashes?');\n log(' -r, --reset-time Set modified time to now');\n log(' -c, --change-freq Set change frequency `weekly` | `daily` | …');\n log(' -v, --version Show version');\n log(' --debug Debug mode');\n log(' ');\n process.exit(args.help ? 0 : 1);\n } else if (config && Object.keys(config).length > 0) {\n // --- CONFIG FILE PATH ---\n const hasCliOptions = process.argv.slice(2).length > 0;\n console.log(cliColors.green, ` ✔ Reading config file...`);\n\n const allowedKeys = Object.keys(defaultConfig);\n const invalidKeys = Object.keys(config).filter((key) => !allowedKeys.includes(key));\n if (invalidKeys.length > 0) {\n console.log(\n cliColors.yellow,\n ` ⚠ Invalid properties in config file, so I ignore them: ${invalidKeys.join(', ')}`\n );\n }\n\n if (hasCliOptions) {\n console.log(\n cliColors.yellow,\n ` ⚠ You have also set CLI options (arguments with '--'), but they are ignored because your config file 'svelte-sitemap.config.ts' is used.`\n );\n }\n\n if (!config.domain) {\n console.log(\n cliColors.yellow,\n ` ⚠ svelte-sitemap: 'domain' property is required in your config file. See instructions: ${REPO_URL}\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!config.domain.startsWith('https://')) {\n console.log(\n cliColors.yellow,\n ` ⚠ svelte-sitemap: 'domain' property in your config file must start with https:// See instructions: ${REPO_URL}\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n try {\n await createSitemap(withDefaultConfig(config));\n } catch (err) {\n console.error(cliColors.red, errorMsgGeneration, err);\n process.exit(0);\n }\n } else {\n // --- CLI ARGUMENTS PATH ---\n if (stop) {\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!args.domain) {\n console.log(\n cliColors.red,\n ` ⚠ svelte-sitemap: --domain argument is required. See instructions: ${REPO_URL}\\n Example:\\n svelte-sitemap --domain https://mydomain.com\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!args.domain.startsWith('https://')) {\n console.log(\n cliColors.red,\n ` ⚠ svelte-sitemap: --domain argument must start with https:// See instructions: ${REPO_URL}\\n Example:\\n\\n svelte-sitemap --domain https://mydomain.com\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n const domain: string = args.domain;\n const debug: boolean = args.debug === '' || args.debug === true ? true : false;\n const additional = Array.isArray(args['additional'])\n ? args['additional']\n : args.additional\n ? [args.additional]\n : [];\n const resetTime: boolean =\n args['reset-time'] === '' || args['reset-time'] === true ? true : false;\n const trailingSlashes: boolean =\n args['trailing-slashes'] === '' || args['trailing-slashes'] === true ? true : false;\n const changeFreq: ChangeFreq = args['change-freq'];\n const outDir: string = args['out-dir'];\n const ignore: string = args['ignore'];\n const attribution: boolean =\n args['attribution'] === '' || args['attribution'] === false ? false : true;\n\n const optionsCli: OptionsSvelteSitemap = {\n debug,\n resetTime,\n changeFreq,\n outDir,\n domain,\n attribution,\n ignore,\n trailingSlashes,\n additional\n };\n\n console.log(\n cliColors.yellow,\n ` Hint: Configuration file is now the preferred method to set up svelte-sitemap. See ${REPO_URL}?tab=readme-ov-file#-usage`\n );\n console.log(cliColors.cyanAndBold, ` ✔ Using CLI options. Config file not found.`);\n try {\n await createSitemap(optionsCli);\n } catch (err) {\n console.error(cliColors.red, errorMsgGeneration, err);\n process.exit(0);\n }\n }\n};\n\nmain();\n"],"mappings":";;;;;;;;AAQA,MAAM,UAAUA;AAEhB,MAAM,OAAO,YAAY;CACvB,QAAQ,IAAI,UAAU,aAAa,WAAW,UAAU;CAExD,IAAI,OAAO;CAEX,MAAM,SAAS,MAAM,WAAW,YAAY;CAE5C,MAAM,OAAO,SAAS,QAAQ,KAAK,MAAM,CAAC,GAAG;EAC3C,QAAQ;GAAC;GAAU;GAAW;GAAU;GAAe;EAAY;EACnE,SAAS;GAAC;GAAe;GAAc;GAAoB;GAAS;EAAS;EAC7E,SAAS;GAAE,aAAa;GAAM,oBAAoB;GAAO,SAAS;EAAM;EACxE,OAAO;GACL,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;EACL;EACA,UAAU,QAAgB;GACxB,IAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG,OAAO;GACrD,QAAQ,IAAI,UAAU,QAAQ,uCAAuC,GAAG;GAExE,OAAO;GACP,OAAO;EACT;CACF,CAAC;CAED,IAAI,KAAK,QAAQ,KAAK,YAAY,MAAM,KAAK,YAAY,MAAM;EAC7D,MAAM,MAAM,KAAK,OAAO,QAAQ,MAAM,QAAQ;EAC9C,IAAI,gCAAgC;EACpC,IAAI,EAAE;EACN,IAAI,kBAAkB,QAAQ,mBAAmB,SAAS,EAAE;EAC5D,IAAI,EAAE;EACN,IAAI,UAAU;EACd,IAAI,EAAE;EACN,IAAI,qEAAqE;EAC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QAAQ;GAChB,QAAQ,IACN,UAAU,KACV,wEAAwE,SAAS,iEACnF;GACA,QAAQ,MAAM,UAAU,KAAK,kBAAkB;GAC/C,QAAQ,KAAK,CAAC;EAChB;EAEA,IAAI,CAAC,KAAK,OAAO,WAAW,UAAU,GAAG;GACvC,QAAQ,IACN,UAAU,KACV,oFAAoF,SAAS,mEAC/F;GACA,QAAQ,MAAM,UAAU,KAAK,kBAAkB;GAC/C,QAAQ,KAAK,CAAC;EAChB;EAEA,MAAM,SAAiB,KAAK;EAC5B,MAAM,QAAiB,KAAK,UAAU,MAAM,KAAK,UAAU,OAAO,OAAO;EACzE,MAAM,aAAa,MAAM,QAAQ,KAAK,aAAa,IAC/C,KAAK,gBACL,KAAK,aACH,CAAC,KAAK,UAAU,IAChB,CAAC;EACP,MAAM,YACJ,KAAK,kBAAkB,MAAM,KAAK,kBAAkB,OAAO,OAAO;EACpE,MAAM,kBACJ,KAAK,wBAAwB,MAAM,KAAK,wBAAwB,OAAO,OAAO;EAChF,MAAM,aAAyB,KAAK;EACpC,MAAM,SAAiB,KAAK;EAC5B,MAAM,SAAiB,KAAK;EAI5B,MAAM,aAAmC;GACvC;GACA;GACA;GACA;GACA;GACA,aARA,KAAK,mBAAmB,MAAM,KAAK,mBAAmB,QAAQ,QAAQ;GAStE;GACA;GACA;EACF;EAEA,QAAQ,IACN,UAAU,QACV,0FAA0F,SAAS,2BACrG;EACA,QAAQ,IAAI,UAAU,aAAa,+CAA+C;EAClF,IAAI;GACF,MAAM,cAAc,UAAU;EAChC,SAAS,KAAK;GACZ,QAAQ,MAAM,UAAU,KAAK,oBAAoB,GAAG;GACpD,QAAQ,KAAK,CAAC;EAChB;CACF;AACF;AAEA,KAAK"}
1
+ {"version":3,"file":"cli.js","names":["pkg.version"],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport minimist from 'minimist';\nimport pkg from './../package.json' with { type: 'json' };\nimport { CONFIG_FILES, REPO_URL } from './const.js';\nimport type { ChangeFreq, OptionsSvelteSitemap } from './dto/index.js';\nimport { defaultConfig, loadConfig, withDefaultConfig } from './helpers/config.js';\nimport { cliColors, errorMsgGeneration } from './helpers/vars.helper.js';\nimport { createSitemap, printIntro } from './index.js';\nconst version = pkg.version;\n\nconst main = async () => {\n let stop = false;\n\n const config = await loadConfig(CONFIG_FILES);\n\n const args = minimist(process.argv.slice(2), {\n string: ['domain', 'out-dir', 'ignore', 'change-freq', 'additional'],\n boolean: ['attribution', 'reset-time', 'trailing-slashes', 'debug', 'version'],\n default: { attribution: true, 'trailing-slashes': false, default: false },\n alias: {\n d: 'domain',\n D: 'domain',\n h: 'help',\n H: 'help',\n v: 'version',\n V: 'version',\n O: 'out-dir',\n o: 'out-dir',\n r: 'reset-time',\n R: 'reset-time',\n c: 'change-freq',\n C: 'change-freq',\n i: 'ignore',\n I: 'ignore',\n t: 'trailing-slashes',\n T: 'trailing-slashes',\n a: 'additional',\n A: 'additional'\n },\n unknown: (err: string) => {\n if (config && Object.keys(config).length > 0) return false;\n console.log(cliColors.yellow, ' ⚠ This argument is not supported:', err);\n // console.log(cliColors.yellow, ' Use: `svelte-sitemap --help` for more options.');\n stop = true;\n return false;\n }\n });\n\n if (args.help || args.version === '' || args.version === true) {\n const log = args.help ? console.log : console.error;\n log('Svelte `sitemap.xml` generator');\n log('');\n log(`svelte-sitemap ${version} (check updates: ${REPO_URL})`);\n log('');\n log('Options:');\n log('');\n log(' -d, --domain Use your domain (eg. https://example.com)');\n log(' -o, --out-dir Custom output dir');\n log(' -i, --ignore Exclude some pages or folders');\n log(' -a, --additional Additional pages outside of SvelteKit (e.g. /, /contact)');\n log(' -t, --trailing-slashes Do you like trailing slashes?');\n log(' -r, --reset-time Set modified time to now');\n log(' -c, --change-freq Set change frequency `weekly` | `daily` | …');\n log(' -v, --version Show version');\n log(' --debug Debug mode');\n log(' ');\n process.exit(args.help ? 0 : 1);\n }\n\n printIntro();\n\n if (config && Object.keys(config).length > 0) {\n // --- CONFIG FILE PATH ---\n const hasCliOptions = process.argv.slice(2).length > 0;\n console.log(cliColors.green, ` ✔ Reading config file...`);\n console.log(\n cliColors.yellow,\n ` ⚠ Deprecated: Running svelte-sitemap via CLI is deprecated. Please use the Vite plugin instead. See ${REPO_URL}#-usage`\n );\n\n const allowedKeys = Object.keys(defaultConfig);\n const invalidKeys = Object.keys(config).filter((key) => !allowedKeys.includes(key));\n if (invalidKeys.length > 0) {\n console.log(\n cliColors.yellow,\n ` ⚠ Invalid properties in config file, so I ignore them: ${invalidKeys.join(', ')}`\n );\n }\n\n if (hasCliOptions) {\n console.log(\n cliColors.yellow,\n ` ⚠ You have also set CLI options (arguments with '--'), but they are ignored because your config file 'svelte-sitemap.config.ts' is used.`\n );\n }\n\n if (!config.domain) {\n console.log(\n cliColors.yellow,\n ` ⚠ svelte-sitemap: 'domain' property is required in your config file. See instructions: ${REPO_URL}\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!config.domain.startsWith('https://')) {\n console.log(\n cliColors.yellow,\n ` ⚠ svelte-sitemap: 'domain' property in your config file must start with https:// See instructions: ${REPO_URL}\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n try {\n await createSitemap(withDefaultConfig(config));\n } catch (err) {\n console.error(cliColors.red, errorMsgGeneration, err);\n process.exit(0);\n }\n } else {\n // --- CLI ARGUMENTS PATH ---\n if (stop) {\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!args.domain) {\n console.log(\n cliColors.red,\n ` ⚠ svelte-sitemap: --domain argument is required. See instructions: ${REPO_URL}\\n Example:\\n svelte-sitemap --domain https://mydomain.com\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n if (!args.domain.startsWith('https://')) {\n console.log(\n cliColors.red,\n ` ⚠ svelte-sitemap: --domain argument must start with https:// See instructions: ${REPO_URL}\\n Example:\\n\\n svelte-sitemap --domain https://mydomain.com\\n`\n );\n console.error(cliColors.red, errorMsgGeneration);\n process.exit(0);\n }\n\n const domain: string = args.domain;\n const debug: boolean = args.debug === '' || args.debug === true ? true : false;\n const additional = Array.isArray(args['additional'])\n ? args['additional']\n : args.additional\n ? [args.additional]\n : [];\n const resetTime: boolean =\n args['reset-time'] === '' || args['reset-time'] === true ? true : false;\n const trailingSlashes: boolean =\n args['trailing-slashes'] === '' || args['trailing-slashes'] === true ? true : false;\n const changeFreq: ChangeFreq = args['change-freq'];\n const outDir: string = args['out-dir'];\n const ignore: string = args['ignore'];\n const attribution: boolean =\n args['attribution'] === '' || args['attribution'] === false ? false : true;\n\n const optionsCli: OptionsSvelteSitemap = {\n debug,\n resetTime,\n changeFreq,\n outDir,\n domain,\n attribution,\n ignore,\n trailingSlashes,\n additional\n };\n\n console.log(\n cliColors.yellow,\n ` Deprecated: Passing options directly via CLI flags is deprecated and will be removed in a future version. Please use the Vite plugin (recommended) or a config file. See ${REPO_URL}#-usage`\n );\n console.log(cliColors.cyanAndBold, ` ✔ Using CLI options. Config file not found.`);\n try {\n await createSitemap(optionsCli);\n } catch (err) {\n console.error(cliColors.red, errorMsgGeneration, err);\n process.exit(0);\n }\n }\n};\n\nmain();\n"],"mappings":";;;;;;;;AAQA,MAAM,UAAUA;AAEhB,MAAM,OAAO,YAAY;CACvB,IAAI,OAAO;CAEX,MAAM,SAAS,MAAM,WAAW,YAAY;CAE5C,MAAM,OAAO,SAAS,QAAQ,KAAK,MAAM,CAAC,GAAG;EAC3C,QAAQ;GAAC;GAAU;GAAW;GAAU;GAAe;EAAY;EACnE,SAAS;GAAC;GAAe;GAAc;GAAoB;GAAS;EAAS;EAC7E,SAAS;GAAE,aAAa;GAAM,oBAAoB;GAAO,SAAS;EAAM;EACxE,OAAO;GACL,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG;GACH,GAAG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AAiB,KAAK;EAI5B,MAAM,aAAmC;GACvC;GACA;GACA;GACA;GACA;GACA,aARA,KAAK,mBAAmB,MAAM,KAAK,mBAAmB,QAAQ,QAAQ;GAStE;GACA;GACA;EACF;EAEA,QAAQ,IACN,UAAU,QACV,gLAAgL,SAAS,QAC3L;EACA,QAAQ,IAAI,UAAU,aAAa,+CAA+C;EAClF,IAAI;GACF,MAAM,cAAc,UAAU;EAChC,SAAS,KAAK;GACZ,QAAQ,MAAM,UAAU,KAAK,oBAAoB,GAAG;GACpD,QAAQ,KAAK,CAAC;EAChB;CACF;AACF;AAEA,KAAK"}
@@ -44,12 +44,23 @@ async function prepareData(domain, options) {
44
44
  detectErrors({
45
45
  folder: !fs.existsSync(FOLDER),
46
46
  htmlFiles: !pages.length
47
- });
47
+ }, FOLDER);
48
+ await checkPrerenderRoutes(pages, FOLDER, options);
48
49
  return results;
49
50
  }
50
- const detectErrors = ({ folder, htmlFiles }) => {
51
- if (folder && htmlFiles) console.error(cliColors.red, errorMsgFolder(OUT_DIR));
52
- else if (htmlFiles) console.error(cliColors.red, errorMsgHtmlFiles(OUT_DIR));
51
+ const detectErrors = ({ folder, htmlFiles }, outDir = OUT_DIR) => {
52
+ if (folder && htmlFiles) console.error(cliColors.red, errorMsgFolder(outDir));
53
+ else if (htmlFiles) console.error(cliColors.red, errorMsgHtmlFiles(outDir));
54
+ };
55
+ const checkPrerenderRoutes = async (pages, outDir, options) => {
56
+ if (fs.existsSync(`${outDir}/_app`)) {
57
+ const hasOnlyRootOrFallback = pages.every((page) => {
58
+ const basename = page.split("/").pop();
59
+ return basename === "index.html" || basename === "fallback.html";
60
+ });
61
+ const hasNoAdditional = !options?.additional || options.additional.length === 0;
62
+ if (hasOnlyRootOrFallback && hasNoAdditional) console.warn(cliColors.yellow, ` ⚠️ Warning: Only the homepage or fallback page was found in '${outDir}/'.\n If your SvelteKit site has multiple routes, make sure you enabled prerendering for them.\n For SPA (Single Page Apps), you can add routes manually using the 'additional' option.`);
63
+ }
53
64
  };
54
65
  const writeSitemap = (items, options, domain) => {
55
66
  const outDir = options?.outDir ?? "build";
@@ -1 +1 @@
1
- {"version":3,"file":"global.helper.js","names":["pkg.version"],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import fg from 'fast-glob';\nimport fs from 'fs';\nimport { create } from 'xmlbuilder2';\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces.js';\nimport pkg from '../../package.json' with { type: 'json' };\nimport { CHANGE_FREQ, CHUNK, OUT_DIR } from '../const.js';\nimport type { ChangeFreq, Options, OptionsSvelteSitemap, PagesJson } from './../dto/index.js';\nimport {\n cliColors,\n errorMsgFolder,\n errorMsgHtmlFiles,\n errorMsgWrite,\n successMsg\n} from './vars.helper.js';\n\nconst version = pkg.version;\n\nconst getUrl = (url: string, domain: string, options: Options) => {\n let slash: '' | '/' = getSlash(domain);\n\n let trimmed = url\n .split((options?.outDir ?? OUT_DIR) + '/')\n .pop()\n .replace('index.html', '');\n\n trimmed = removeHtml(trimmed);\n\n // Add all traling slashes\n if (options?.trailingSlashes) {\n trimmed = trimmed.length && !trimmed.endsWith('/') ? trimmed + '/' : trimmed;\n } else {\n trimmed = trimmed.endsWith('/') ? trimmed.slice(0, -1) : trimmed;\n slash = trimmed ? slash : '';\n }\n\n // URI-encode each path segment to handle special characters (e.g. spaces → %20).\n // Decode first to avoid double-encoding already percent-encoded segments.\n trimmed = trimmed\n .split('/')\n .map((segment) => {\n try {\n return encodeURIComponent(decodeURIComponent(segment));\n } catch {\n return encodeURIComponent(segment);\n }\n })\n .join('/');\n\n return `${domain}${slash}${trimmed}`;\n};\n\nexport const removeHtml = (fileName: string) => {\n if (fileName?.endsWith('.html')) {\n return fileName.slice(0, -5);\n }\n return fileName;\n};\n\nexport async function prepareData(domain: string, options?: Options): Promise<PagesJson[]> {\n const FOLDER = options?.outDir ?? OUT_DIR;\n\n const ignore = prepareIgnored(options?.ignore, options?.outDir);\n const changeFreq = prepareChangeFreq(options);\n const pages: string[] = await fg(`${FOLDER}/**/*.html`, { ignore });\n\n if (options.additional) pages.push(...options.additional);\n\n const results = pages.map((page) => {\n return {\n page: getUrl(page, domain, options),\n changeFreq: changeFreq,\n lastMod: options?.resetTime ? new Date().toISOString().split('T')[0] : ''\n };\n });\n\n detectErrors({\n folder: !fs.existsSync(FOLDER),\n htmlFiles: !pages.length\n });\n\n return results;\n}\n\nexport const detectErrors = ({ folder, htmlFiles }: { folder: boolean; htmlFiles: boolean }) => {\n if (folder && htmlFiles) {\n console.error(cliColors.red, errorMsgFolder(OUT_DIR));\n } else if (htmlFiles) {\n // If no page exists, then the static adapter is probably not used\n console.error(cliColors.red, errorMsgHtmlFiles(OUT_DIR));\n }\n};\n\nexport const writeSitemap = (items: PagesJson[], options: Options, domain: string): void => {\n const outDir = options?.outDir ?? OUT_DIR;\n\n if (items?.length <= CHUNK.maxSize) {\n createFile(items, options, outDir);\n } else {\n // If the number of pages is greater than the chunk size, then we split the sitemap into multiple files\n // and create an index file that links to all of them\n // https://support.google.com/webmasters/answer/183668?hl=en\n const numberOfChunks = Math.ceil(items.length / CHUNK.maxSize);\n\n console.log(\n cliColors.cyanAndBold,\n `> Oh, your site is huge! Writing sitemap in chunks of ${numberOfChunks} pages and its index sitemap.xml`\n );\n\n for (let i = 0; i < items.length; i += CHUNK.maxSize) {\n const chunk = items.slice(i, i + CHUNK.maxSize);\n createFile(chunk, options, outDir, i / CHUNK.maxSize + 1);\n }\n createIndexFile(numberOfChunks, outDir, options, domain);\n }\n};\n\nconst createFile = (\n items: PagesJson[],\n options: Options,\n outDir: string,\n chunkId?: number\n): void => {\n const sitemap = createXml('urlset');\n addAttribution(sitemap, options);\n\n for (const item of items) {\n const page = sitemap.ele('url');\n page.ele('loc').txt(item.page);\n if (item.changeFreq) {\n page.ele('changefreq').txt(item.changeFreq);\n }\n if (item.lastMod) {\n page.ele('lastmod').txt(item.lastMod);\n }\n }\n\n const xml = finishXml(sitemap);\n\n const fileName = chunkId ? `sitemap-${chunkId}.xml` : 'sitemap.xml';\n\n try {\n fs.writeFileSync(`${outDir}/${fileName}`, xml);\n console.log(cliColors.green, successMsg(outDir, fileName));\n } catch (e) {\n console.error(cliColors.red, errorMsgWrite(outDir, fileName), e);\n }\n};\n\nconst createIndexFile = (\n numberOfChunks: number,\n outDir: string,\n options: Options,\n domain: string\n): void => {\n const FILENAME = 'sitemap.xml';\n const slash = getSlash(domain);\n\n const sitemap = createXml('sitemapindex');\n addAttribution(sitemap, options);\n\n for (let i = 1; i <= numberOfChunks; i++) {\n sitemap.ele('sitemap').ele('loc').txt(`${domain}${slash}sitemap-${i}.xml`);\n }\n\n const xml = finishXml(sitemap);\n\n try {\n fs.writeFileSync(`${outDir}/${FILENAME}`, xml);\n console.log(cliColors.green, successMsg(outDir, FILENAME));\n } catch (e) {\n console.error(cliColors.red, errorMsgWrite(outDir, FILENAME), e);\n }\n};\n\nconst prepareIgnored = (\n ignored: string | string[],\n outDir: string = OUT_DIR\n): string[] | undefined => {\n let ignore: string[] | undefined;\n if (ignored) {\n ignore = Array.isArray(ignored) ? ignored : [ignored];\n ignore = ignore.map((ignoredPage) => `${outDir}/${ignoredPage}`);\n }\n return ignore;\n};\n\nconst prepareChangeFreq = (options: Options): ChangeFreq => {\n let result: ChangeFreq = null;\n\n if (options?.changeFreq) {\n if (CHANGE_FREQ.includes(options.changeFreq)) {\n result = options.changeFreq;\n } else {\n console.log(\n cliColors.red,\n ` × Option \\`--change-freq ${options.changeFreq}\\` is not a valid value. See docs: https://github.com/bartholomej/svelte-sitemap#options`\n );\n }\n }\n return result;\n};\n\nconst getSlash = (domain: string) => (domain.split('/').pop() ? '/' : '');\n\nconst createXml = (elementName: 'urlset' | 'sitemapindex'): XMLBuilder => {\n return create({ version: '1.0', encoding: 'UTF-8' }).ele(elementName, {\n xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'\n });\n};\n\nconst finishXml = (sitemap: XMLBuilder): string => {\n return sitemap.end({ prettyPrint: true });\n};\n\nconst addAttribution = (sitemap: XMLBuilder, options: Options): void => {\n if (options?.attribution !== false) {\n sitemap.com(\n ` This file was automatically generated by https://github.com/bartholomej/svelte-sitemap v${version} `\n );\n }\n};\n"],"mappings":";;;;;;;AAeA,MAAM,UAAUA;AAEhB,MAAM,UAAU,KAAa,QAAgB,YAAqB;CAChE,IAAI,QAAkB,SAAS,MAAM;CAErC,IAAI,UAAU,IACX,OAAO,SAAS,UAAA,WAAqB,GAAG,EACxC,IAAI,EACJ,QAAQ,cAAc,EAAE;CAE3B,UAAU,WAAW,OAAO;CAG5B,IAAI,SAAS,iBACX,UAAU,QAAQ,UAAU,CAAC,QAAQ,SAAS,GAAG,IAAI,UAAU,MAAM;MAChE;EACL,UAAU,QAAQ,SAAS,GAAG,IAAI,QAAQ,MAAM,GAAG,EAAE,IAAI;EACzD,QAAQ,UAAU,QAAQ;CAC5B;CAIA,UAAU,QACP,MAAM,GAAG,EACT,KAAK,YAAY;EAChB,IAAI;GACF,OAAO,mBAAmB,mBAAmB,OAAO,CAAC;EACvD,QAAQ;GACN,OAAO,mBAAmB,OAAO;EACnC;CACF,CAAC,EACA,KAAK,GAAG;CAEX,OAAO,GAAG,SAAS,QAAQ;AAC7B;AAEA,MAAa,cAAc,aAAqB;CAC9C,IAAI,UAAU,SAAS,OAAO,GAC5B,OAAO,SAAS,MAAM,GAAG,EAAE;CAE7B,OAAO;AACT;AAEA,eAAsB,YAAY,QAAgB,SAAyC;CACzF,MAAM,SAAS,SAAS,UAAA;CAExB,MAAM,SAAS,eAAe,SAAS,QAAQ,SAAS,MAAM;CAC9D,MAAM,aAAa,kBAAkB,OAAO;CAC5C,MAAM,QAAkB,MAAM,GAAG,GAAG,OAAO,aAAa,EAAE,OAAO,CAAC;CAElE,IAAI,QAAQ,YAAY,MAAM,KAAK,GAAG,QAAQ,UAAU;CAExD,MAAM,UAAU,MAAM,KAAK,SAAS;EAClC,OAAO;GACL,MAAM,OAAO,MAAM,QAAQ,OAAO;GACtB;GACZ,SAAS,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AAa,gBAAuD;CACxE,OAAO,OAAO;EAAE,SAAS;EAAO,UAAU;CAAQ,CAAC,EAAE,IAAI,aAAa,EACpE,OAAO,8CACT,CAAC;AACH;AAEA,MAAM,aAAa,YAAgC;CACjD,OAAO,QAAQ,IAAI,EAAE,aAAa,KAAK,CAAC;AAC1C;AAEA,MAAM,kBAAkB,SAAqB,YAA2B;CACtE,IAAI,SAAS,gBAAgB,OAC3B,QAAQ,IACN,4FAA4F,QAAQ,EACtG;AAEJ"}
1
+ {"version":3,"file":"global.helper.js","names":["pkg.version"],"sources":["../../src/helpers/global.helper.ts"],"sourcesContent":["import fg from 'fast-glob';\nimport fs from 'fs';\nimport { create } from 'xmlbuilder2';\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces.js';\nimport pkg from '../../package.json' with { type: 'json' };\nimport { CHANGE_FREQ, CHUNK, OUT_DIR } from '../const.js';\nimport type { ChangeFreq, Options, OptionsSvelteSitemap, PagesJson } from './../dto/index.js';\nimport {\n cliColors,\n errorMsgFolder,\n errorMsgHtmlFiles,\n errorMsgWrite,\n successMsg\n} from './vars.helper.js';\n\nconst version = pkg.version;\n\nconst getUrl = (url: string, domain: string, options: Options) => {\n let slash: '' | '/' = getSlash(domain);\n\n let trimmed = url\n .split((options?.outDir ?? OUT_DIR) + '/')\n .pop()\n .replace('index.html', '');\n\n trimmed = removeHtml(trimmed);\n\n // Add all traling slashes\n if (options?.trailingSlashes) {\n trimmed = trimmed.length && !trimmed.endsWith('/') ? trimmed + '/' : trimmed;\n } else {\n trimmed = trimmed.endsWith('/') ? trimmed.slice(0, -1) : trimmed;\n slash = trimmed ? slash : '';\n }\n\n // URI-encode each path segment to handle special characters (e.g. spaces → %20).\n // Decode first to avoid double-encoding already percent-encoded segments.\n trimmed = trimmed\n .split('/')\n .map((segment) => {\n try {\n return encodeURIComponent(decodeURIComponent(segment));\n } catch {\n return encodeURIComponent(segment);\n }\n })\n .join('/');\n\n return `${domain}${slash}${trimmed}`;\n};\n\nexport const removeHtml = (fileName: string) => {\n if (fileName?.endsWith('.html')) {\n return fileName.slice(0, -5);\n }\n return fileName;\n};\n\nexport async function prepareData(domain: string, options?: Options): Promise<PagesJson[]> {\n const FOLDER = options?.outDir ?? OUT_DIR;\n\n const ignore = prepareIgnored(options?.ignore, options?.outDir);\n const changeFreq = prepareChangeFreq(options);\n const pages: string[] = await fg(`${FOLDER}/**/*.html`, { ignore });\n\n if (options.additional) pages.push(...options.additional);\n\n const results = pages.map((page) => {\n return {\n page: getUrl(page, domain, options),\n changeFreq: changeFreq,\n lastMod: options?.resetTime ? new Date().toISOString().split('T')[0] : ''\n };\n });\n\n detectErrors(\n {\n folder: !fs.existsSync(FOLDER),\n htmlFiles: !pages.length\n },\n FOLDER\n );\n\n await checkPrerenderRoutes(pages, FOLDER, options);\n\n return results;\n}\n\nexport const detectErrors = (\n { folder, htmlFiles }: { folder: boolean; htmlFiles: boolean },\n outDir: string = OUT_DIR\n) => {\n if (folder && htmlFiles) {\n console.error(cliColors.red, errorMsgFolder(outDir));\n } else if (htmlFiles) {\n // If no page exists, then the static adapter is probably not used\n console.error(cliColors.red, errorMsgHtmlFiles(outDir));\n }\n};\n\nexport const checkPrerenderRoutes = async (pages: string[], outDir: string, options?: Options) => {\n // Check if it's a SvelteKit build by checking for the '_app' directory in output folder\n const appDirExists = fs.existsSync(`${outDir}/_app`);\n\n if (appDirExists) {\n const hasOnlyRootOrFallback = pages.every((page) => {\n const basename = page.split('/').pop();\n return basename === 'index.html' || basename === 'fallback.html';\n });\n\n const hasNoAdditional = !options?.additional || options.additional.length === 0;\n\n if (hasOnlyRootOrFallback && hasNoAdditional) {\n console.warn(\n cliColors.yellow,\n ` ⚠️ Warning: Only the homepage or fallback page was found in '${outDir}/'.\\n` +\n ` If your SvelteKit site has multiple routes, make sure you enabled prerendering for them.\\n` +\n ` For SPA (Single Page Apps), you can add routes manually using the 'additional' option.`\n );\n }\n }\n};\n\nexport const writeSitemap = (items: PagesJson[], options: Options, domain: string): void => {\n const outDir = options?.outDir ?? OUT_DIR;\n\n if (items?.length <= CHUNK.maxSize) {\n createFile(items, options, outDir);\n } else {\n // If the number of pages is greater than the chunk size, then we split the sitemap into multiple files\n // and create an index file that links to all of them\n // https://support.google.com/webmasters/answer/183668?hl=en\n const numberOfChunks = Math.ceil(items.length / CHUNK.maxSize);\n\n console.log(\n cliColors.cyanAndBold,\n `> Oh, your site is huge! Writing sitemap in chunks of ${numberOfChunks} pages and its index sitemap.xml`\n );\n\n for (let i = 0; i < items.length; i += CHUNK.maxSize) {\n const chunk = items.slice(i, i + CHUNK.maxSize);\n createFile(chunk, options, outDir, i / CHUNK.maxSize + 1);\n }\n createIndexFile(numberOfChunks, outDir, options, domain);\n }\n};\n\nconst createFile = (\n items: PagesJson[],\n options: Options,\n outDir: string,\n chunkId?: number\n): void => {\n const sitemap = createXml('urlset');\n addAttribution(sitemap, options);\n\n for (const item of items) {\n const page = sitemap.ele('url');\n page.ele('loc').txt(item.page);\n if (item.changeFreq) {\n page.ele('changefreq').txt(item.changeFreq);\n }\n if (item.lastMod) {\n page.ele('lastmod').txt(item.lastMod);\n }\n }\n\n const xml = finishXml(sitemap);\n\n const fileName = chunkId ? `sitemap-${chunkId}.xml` : 'sitemap.xml';\n\n try {\n fs.writeFileSync(`${outDir}/${fileName}`, xml);\n console.log(cliColors.green, successMsg(outDir, fileName));\n } catch (e) {\n console.error(cliColors.red, errorMsgWrite(outDir, fileName), e);\n }\n};\n\nconst createIndexFile = (\n numberOfChunks: number,\n outDir: string,\n options: Options,\n domain: string\n): void => {\n const FILENAME = 'sitemap.xml';\n const slash = getSlash(domain);\n\n const sitemap = createXml('sitemapindex');\n addAttribution(sitemap, options);\n\n for (let i = 1; i <= numberOfChunks; i++) {\n sitemap.ele('sitemap').ele('loc').txt(`${domain}${slash}sitemap-${i}.xml`);\n }\n\n const xml = finishXml(sitemap);\n\n try {\n fs.writeFileSync(`${outDir}/${FILENAME}`, xml);\n console.log(cliColors.green, successMsg(outDir, FILENAME));\n } catch (e) {\n console.error(cliColors.red, errorMsgWrite(outDir, FILENAME), e);\n }\n};\n\nconst prepareIgnored = (\n ignored: string | string[],\n outDir: string = OUT_DIR\n): string[] | undefined => {\n let ignore: string[] | undefined;\n if (ignored) {\n ignore = Array.isArray(ignored) ? ignored : [ignored];\n ignore = ignore.map((ignoredPage) => `${outDir}/${ignoredPage}`);\n }\n return ignore;\n};\n\nconst prepareChangeFreq = (options: Options): ChangeFreq => {\n let result: ChangeFreq = null;\n\n if (options?.changeFreq) {\n if (CHANGE_FREQ.includes(options.changeFreq)) {\n result = options.changeFreq;\n } else {\n console.log(\n cliColors.red,\n ` × Option \\`--change-freq ${options.changeFreq}\\` is not a valid value. See docs: https://github.com/bartholomej/svelte-sitemap#options`\n );\n }\n }\n return result;\n};\n\nconst getSlash = (domain: string) => (domain.split('/').pop() ? '/' : '');\n\nconst createXml = (elementName: 'urlset' | 'sitemapindex'): XMLBuilder => {\n return create({ version: '1.0', encoding: 'UTF-8' }).ele(elementName, {\n xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'\n });\n};\n\nconst finishXml = (sitemap: XMLBuilder): string => {\n return sitemap.end({ prettyPrint: true });\n};\n\nconst addAttribution = (sitemap: XMLBuilder, options: Options): void => {\n if (options?.attribution !== false) {\n sitemap.com(\n ` This file was automatically generated by https://github.com/bartholomej/svelte-sitemap v${version} `\n );\n }\n};\n"],"mappings":";;;;;;;AAeA,MAAM,UAAUA;AAEhB,MAAM,UAAU,KAAa,QAAgB,YAAqB;CAChE,IAAI,QAAkB,SAAS,MAAM;CAErC,IAAI,UAAU,IACX,OAAO,SAAS,UAAA,WAAqB,GAAG,EACxC,IAAI,EACJ,QAAQ,cAAc,EAAE;CAE3B,UAAU,WAAW,OAAO;CAG5B,IAAI,SAAS,iBACX,UAAU,QAAQ,UAAU,CAAC,QAAQ,SAAS,GAAG,IAAI,UAAU,MAAM;MAChE;EACL,UAAU,QAAQ,SAAS,GAAG,IAAI,QAAQ,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AAQ,CAAC,EAAE,IAAI,aAAa,EACpE,OAAO,8CACT,CAAC;AACH;AAEA,MAAM,aAAa,YAAgC;CACjD,OAAO,QAAQ,IAAI,EAAE,aAAa,KAAK,CAAC;AAC1C;AAEA,MAAM,kBAAkB,SAAqB,YAA2B;CACtE,IAAI,SAAS,gBAAgB,OAC3B,QAAQ,IACN,4FAA4F,QAAQ,EACtG;AAEJ"}
@@ -8,8 +8,8 @@ const cliColors = {
8
8
  const successMsg = (outDir, filename) => ` ✔ Done. Check your new sitemap here: ./${outDir}/${filename}`;
9
9
  const errorMsgWrite = (outDir, filename) => ` × File '${outDir}/${filename}' could not be created.`;
10
10
  const errorMsgGeneration = ` × Sitemap generation failed.`;
11
- 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. Or are you using Vercel? See https://github.com/bartholomej/svelte-sitemap#error-missing-folder`;
12
- 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#error-missing-html-files`;
11
+ const errorMsgFolder = (outDir) => ` × Folder '${outDir}/' doesn't exist.\n Make sure your build completed successfully and the output folder was created.\n If you are using SvelteKit, ensure you are using adapter-static and your outDir matches the adapter's output folder. See https://github.com/bartholomej/svelte-sitemap#-error-missing-folder`;
12
+ const errorMsgHtmlFiles = (outDir) => ` × There is no static html file in your '${outDir}/' folder.\n This generator requires static HTML files to scan. If you are using adapter-static, make sure you have prerendering enabled.\n If you are building a fully dynamic SSR site, you should generate your sitemap dynamically (e.g., via a +server.ts route) instead. See https://github.com/bartholomej/svelte-sitemap#-error-missing-html-files`;
13
13
  //#endregion
14
14
  export { cliColors, errorMsgFolder, errorMsgGeneration, errorMsgHtmlFiles, errorMsgWrite, successMsg };
15
15
 
@@ -1 +1 @@
1
- {"version":3,"file":"vars.helper.js","names":[],"sources":["../../src/helpers/vars.helper.ts"],"sourcesContent":["export const cliColors = {\n cyanAndBold: '\\x1b[36m\\x1b[1m%s\\x1b[22m\\x1b[0m',\n green: '\\x1b[32m%s\\x1b[0m',\n red: '\\x1b[31m%s\\x1b[0m',\n yellow: '\\x1b[33m%s\\x1b[0m'\n};\n\nexport const successMsg = (outDir: string, filename: string) =>\n ` ✔ Done. Check your new sitemap here: ./${outDir}/${filename}`;\n\nexport const errorMsgWrite = (outDir: string, filename: string) =>\n ` × File '${outDir}/${filename}' could not be created.`;\n\nexport const errorMsgGeneration = ` × Sitemap generation failed.`;\n\nexport const errorMsgFolder = (outDir: string) =>\n ` × 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. Or are you using Vercel? See https://github.com/bartholomej/svelte-sitemap#error-missing-folder`;\n\nexport const errorMsgHtmlFiles = (outDir: string) =>\n ` × 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#error-missing-html-files`;\n"],"mappings":";AAAA,MAAa,YAAY;CACvB,aAAa;CACb,OAAO;CACP,KAAK;CACL,QAAQ;AACV;AAEA,MAAa,cAAc,QAAgB,aACzC,4CAA4C,OAAO,GAAG;AAExD,MAAa,iBAAiB,QAAgB,aAC5C,aAAa,OAAO,GAAG,SAAS;AAElC,MAAa,qBAAqB;AAElC,MAAa,kBAAkB,WAC7B,eAAe,OAAO,iFAAiF,OAAO;AAEhH,MAAa,qBAAqB,WAChC,6CAA6C,OAAO"}
1
+ {"version":3,"file":"vars.helper.js","names":[],"sources":["../../src/helpers/vars.helper.ts"],"sourcesContent":["export const cliColors = {\n cyanAndBold: '\\x1b[36m\\x1b[1m%s\\x1b[22m\\x1b[0m',\n green: '\\x1b[32m%s\\x1b[0m',\n red: '\\x1b[31m%s\\x1b[0m',\n yellow: '\\x1b[33m%s\\x1b[0m'\n};\n\nexport const successMsg = (outDir: string, filename: string) =>\n ` ✔ Done. Check your new sitemap here: ./${outDir}/${filename}`;\n\nexport const errorMsgWrite = (outDir: string, filename: string) =>\n ` × File '${outDir}/${filename}' could not be created.`;\n\nexport const errorMsgGeneration = ` × Sitemap generation failed.`;\n\nexport const errorMsgFolder = (outDir: string) =>\n ` × Folder '${outDir}/' doesn't exist.\\n` +\n ` Make sure your build completed successfully and the output folder was created.\\n` +\n ` If you are using SvelteKit, ensure you are using adapter-static and your outDir matches the adapter's output folder. See https://github.com/bartholomej/svelte-sitemap#-error-missing-folder`;\n\nexport const errorMsgHtmlFiles = (outDir: string) =>\n ` × There is no static html file in your '${outDir}/' folder.\\n` +\n ` This generator requires static HTML files to scan. If you are using adapter-static, make sure you have prerendering enabled.\\n` +\n ` If you are building a fully dynamic SSR site, you should generate your sitemap dynamically (e.g., via a +server.ts route) instead. See https://github.com/bartholomej/svelte-sitemap#-error-missing-html-files`;\n"],"mappings":";AAAA,MAAa,YAAY;CACvB,aAAa;CACb,OAAO;CACP,KAAK;CACL,QAAQ;AACV;AAEA,MAAa,cAAc,QAAgB,aACzC,4CAA4C,OAAO,GAAG;AAExD,MAAa,iBAAiB,QAAgB,aAC5C,aAAa,OAAO,GAAG,SAAS;AAElC,MAAa,qBAAqB;AAElC,MAAa,kBAAkB,WAC7B,eAAe,OAAO;AAIxB,MAAa,qBAAqB,WAChC,6CAA6C,OAAO"}
package/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import { Arguments, ChangeFreq, Options, OptionsSvelteSitemap, PagesJson } from "./dto/global.interface.js";
2
+ import { svelteSitemap } from "./vite.js";
2
3
 
3
4
  //#region src/index.d.ts
5
+ declare const printIntro: () => void;
4
6
  declare const createSitemap: (options: OptionsSvelteSitemap) => Promise<void>;
5
7
  //#endregion
6
- export { type Arguments, type ChangeFreq, type Options, type OptionsSvelteSitemap, type PagesJson, createSitemap };
8
+ export { type Arguments, type ChangeFreq, type Options, type OptionsSvelteSitemap, type PagesJson, createSitemap, printIntro, svelteSitemap };
7
9
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -1,8 +1,17 @@
1
- import "./const.js";
1
+ import { APP_NAME } from "./const.js";
2
2
  import { cliColors, errorMsgWrite } from "./helpers/vars.helper.js";
3
3
  import { prepareData, writeSitemap } from "./helpers/global.helper.js";
4
+ import { svelteSitemap } from "./vite.js";
4
5
  //#region src/index.ts
6
+ let introPrinted = false;
7
+ const printIntro = () => {
8
+ if (!introPrinted) {
9
+ console.log(cliColors.cyanAndBold, `> Using ${APP_NAME}`);
10
+ introPrinted = true;
11
+ }
12
+ };
5
13
  const createSitemap = async (options) => {
14
+ printIntro();
6
15
  if (options?.debug) console.log("OPTIONS", options);
7
16
  const json = await prepareData(options.domain, options);
8
17
  if (options?.debug) console.log("RESULT", json);
@@ -10,6 +19,6 @@ const createSitemap = async (options) => {
10
19
  else console.error(cliColors.red, errorMsgWrite(options.outDir ?? "build", "sitemap.xml"));
11
20
  };
12
21
  //#endregion
13
- export { createSitemap };
22
+ export { createSitemap, printIntro, svelteSitemap };
14
23
 
15
24
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { OUT_DIR } from './const.js';\nimport type { OptionsSvelteSitemap } from './dto/index.js';\nimport { prepareData, writeSitemap } from './helpers/global.helper.js';\nimport { cliColors, errorMsgWrite } from './helpers/vars.helper.js';\n\nexport const createSitemap = async (options: OptionsSvelteSitemap): Promise<void> => {\n if (options?.debug) {\n console.log('OPTIONS', options);\n }\n\n const json = await prepareData(options.domain, options);\n\n if (options?.debug) {\n console.log('RESULT', json);\n }\n\n if (json.length) {\n writeSitemap(json, options, options.domain);\n } else {\n console.error(cliColors.red, errorMsgWrite(options.outDir ?? OUT_DIR, 'sitemap.xml'));\n }\n};\n\nexport type * from './dto/index.js';\n"],"mappings":";;;;AAKA,MAAa,gBAAgB,OAAO,YAAiD;CACnF,IAAI,SAAS,OACX,QAAQ,IAAI,WAAW,OAAO;CAGhC,MAAM,OAAO,MAAM,YAAY,QAAQ,QAAQ,OAAO;CAEtD,IAAI,SAAS,OACX,QAAQ,IAAI,UAAU,IAAI;CAG5B,IAAI,KAAK,QACP,aAAa,MAAM,SAAS,QAAQ,MAAM;MAE1C,QAAQ,MAAM,UAAU,KAAK,cAAc,QAAQ,UAAA,SAAmB,aAAa,CAAC;AAExF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { APP_NAME, OUT_DIR } from './const.js';\nimport type { OptionsSvelteSitemap } from './dto/index.js';\nimport { prepareData, writeSitemap } from './helpers/global.helper.js';\nimport { cliColors, errorMsgWrite } from './helpers/vars.helper.js';\n\nlet introPrinted = false;\n\nexport const printIntro = (): void => {\n if (!introPrinted) {\n console.log(cliColors.cyanAndBold, `> Using ${APP_NAME}`);\n introPrinted = true;\n }\n};\n\nexport const createSitemap = async (options: OptionsSvelteSitemap): Promise<void> => {\n printIntro();\n\n if (options?.debug) {\n console.log('OPTIONS', options);\n }\n\n const json = await prepareData(options.domain, options);\n\n if (options?.debug) {\n console.log('RESULT', json);\n }\n\n if (json.length) {\n writeSitemap(json, options, options.domain);\n } else {\n console.error(cliColors.red, errorMsgWrite(options.outDir ?? OUT_DIR, 'sitemap.xml'));\n }\n};\n\nexport { svelteSitemap } from './vite.js';\nexport type * from './dto/index.js';\n"],"mappings":";;;;;AAKA,IAAI,eAAe;AAEnB,MAAa,mBAAyB;CACpC,IAAI,CAAC,cAAc;EACjB,QAAQ,IAAI,UAAU,aAAa,WAAW,UAAU;EACxD,eAAe;CACjB;AACF;AAEA,MAAa,gBAAgB,OAAO,YAAiD;CACnF,WAAW;CAEX,IAAI,SAAS,OACX,QAAQ,IAAI,WAAW,OAAO;CAGhC,MAAM,OAAO,MAAM,YAAY,QAAQ,QAAQ,OAAO;CAEtD,IAAI,SAAS,OACX,QAAQ,IAAI,UAAU,IAAI;CAG5B,IAAI,KAAK,QACP,aAAa,MAAM,SAAS,QAAQ,MAAM;MAE1C,QAAQ,MAAM,UAAU,KAAK,cAAc,QAAQ,UAAA,SAAmB,aAAa,CAAC;AAExF"}
package/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "3.3.0-next.0";
2
+ var version = "3.3.0-next.2";
3
3
  //#endregion
4
4
  export { version };
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-sitemap",
3
- "version": "3.3.0-next.0",
3
+ "version": "3.3.0-next.2",
4
4
  "type": "module",
5
5
  "description": "Small helper which scans your Svelte routes folder and generates static sitemap.xml",
6
6
  "author": "BART! <bart@bartweb.cz>",
package/vite.js CHANGED
@@ -1,10 +1,18 @@
1
1
  import { createSitemap } from "./index.js";
2
2
  //#region src/vite.ts
3
3
  function svelteSitemap(options) {
4
+ let isSvelteKit = false;
5
+ let isSSR = false;
4
6
  return {
5
7
  name: "svelte-sitemap",
6
8
  apply: "build",
9
+ enforce: "post",
10
+ configResolved(config) {
11
+ isSvelteKit = config.plugins.some((p) => p.name.includes("sveltekit") || p.name.startsWith("sveltekit:"));
12
+ isSSR = !!config.build?.ssr;
13
+ },
7
14
  closeBundle: async () => {
15
+ if (isSvelteKit && !isSSR) return;
8
16
  await createSitemap(options);
9
17
  }
10
18
  };
package/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport type { OptionsSvelteSitemap } from './dto/index.js';\nimport { createSitemap } from './index.js';\n\nexport function svelteSitemap(options: OptionsSvelteSitemap): Plugin {\n return {\n name: 'svelte-sitemap',\n apply: 'build',\n closeBundle: async () => {\n await createSitemap(options);\n }\n };\n}\n"],"mappings":";;AAIA,SAAgB,cAAc,SAAuC;CACnE,OAAO;EACL,MAAM;EACN,OAAO;EACP,aAAa,YAAY;GACvB,MAAM,cAAc,OAAO;EAC7B;CACF;AACF"}
1
+ {"version":3,"file":"vite.js","names":[],"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport type { OptionsSvelteSitemap } from './dto/index.js';\nimport { createSitemap } from './index.js';\n\nexport function svelteSitemap(options: OptionsSvelteSitemap): Plugin {\n let isSvelteKit = false;\n let isSSR = false;\n\n return {\n name: 'svelte-sitemap',\n apply: 'build',\n enforce: 'post',\n configResolved(config) {\n isSvelteKit = config.plugins.some(\n (p) => p.name.includes('sveltekit') || p.name.startsWith('sveltekit:')\n );\n isSSR = !!config.build?.ssr;\n },\n closeBundle: async () => {\n if (isSvelteKit && !isSSR) {\n return;\n }\n await createSitemap(options);\n }\n };\n}\n"],"mappings":";;AAIA,SAAgB,cAAc,SAAuC;CACnE,IAAI,cAAc;CAClB,IAAI,QAAQ;CAEZ,OAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;EACT,eAAe,QAAQ;GACrB,cAAc,OAAO,QAAQ,MAC1B,MAAM,EAAE,KAAK,SAAS,WAAW,KAAK,EAAE,KAAK,WAAW,YAAY,CACvE;GACA,QAAQ,CAAC,CAAC,OAAO,OAAO;EAC1B;EACA,aAAa,YAAY;GACvB,IAAI,eAAe,CAAC,OAClB;GAEF,MAAM,cAAc,OAAO;EAC7B;CACF;AACF"}