Skip to content

Commit 6623198

Browse files
committed
docs(readme): add config file instructions
1 parent a6eaeea commit 6623198

File tree

2 files changed

+50
-9
lines changed

2 files changed

+50
-9
lines changed

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,30 @@ npm install svelte-sitemap --save-dev
2020

2121
## Usage
2222

23-
> Use this library as a `postbuild` hook in your `package.json` file.
23+
### Config file method (recommended)
24+
25+
Create config file `svelte-sitemap.cjs` in the root of your project:
26+
27+
`svelte-sitemap.cjs`
28+
29+
```js
30+
module.exports = {
31+
domain: 'https://www.example.com'
32+
// ...more options
33+
};
34+
```
35+
36+
Add `svelte-sitemap` as your postbuild script in `package.json` file:
37+
38+
`package.json`
39+
40+
```json
41+
{
42+
"postbuild": "npx svelte-sitemap"
43+
}
44+
```
45+
46+
### Alternative 1: CLI method
2447

2548
File: `package.json`
2649

@@ -35,7 +58,7 @@ File: `package.json`
3558

3659
It scans your routes in `build/` folder and generates `build/sitemap.xml` file.
3760

38-
### Alternative usage: TypeScript or JavaScript method
61+
### Alternative 2: TypeScript or JavaScript method
3962

4063
> 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.
4164
@@ -49,6 +72,30 @@ createSitemap({ domain: 'https://example.com', debug: true });
4972

5073
And now you can run your script like this: `node my-script.js`
5174

75+
## Example
76+
77+
Use this library as a `postbuild` hook in your `package.json` with config file `svelte-sitemap.cjs` in your project root.
78+
79+
File: `package.json`
80+
81+
```json
82+
{
83+
"name": "my-project",
84+
"scripts": {
85+
"postbuild": "npx svelte-sitemap"
86+
}
87+
}
88+
```
89+
90+
File: `svelte-sitemap.cjs`
91+
92+
```typescript
93+
module.exports = {
94+
domain: 'https://www.example.com',
95+
trailingSlashes: true
96+
};
97+
```
98+
5299
## ⚙️ Options
53100

54101
| Option | Description | Default | Example |
@@ -136,6 +183,7 @@ yarn demo
136183
- svelte-sitemap is workaround for [this official SvelteKit issue](https://github.com/sveltejs/kit/issues/1142)
137184
- Brand new version is inspired by [Richard's article](https://r-bt.com/learning/sveltekit-sitemap/)
138185
- Thanks to [@auderer](https://github.com/auderer) because [his issue](https://github.com/bartholomej/svelte-sitemap/issues/1) changed the direction of this library
186+
- Config files inspired by [next-sitemap](https://github.com/iamvishnusankar/next-sitemap)
139187

140188
## 📝 License
141189

src/vars.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@ export const DOMAIN = 'https://example.com';
55
export const OUT_DIR = 'build';
66

77
export const CONFIG_FILE = 'svelte-sitemap.cjs';
8-
9-
// export const OPTIONS: Options = {
10-
// domain: DOMAIN,
11-
// resetTime: false,
12-
// debug: false,
13-
// changeFreq: 'weekly'
14-
// };

0 commit comments

Comments
 (0)