Skip to content

Commit de38f18

Browse files
committed
docs(readme): add config file instructions
1 parent 78584b5 commit de38f18

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

README.md

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

2121
## Usage
2222

23-
### CLI method (recommended)
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+
### CLI method (Alternative 1)
2447

2548
Use this script as a **postbuild hook**. See this [example](#example).
2649

@@ -30,7 +53,7 @@ npx svelte-sitemap --domain https://example.com
3053

3154
It scans your routes in `build/` folder and generates `build/sitemap.xml` file
3255

33-
### Alternative: TypeScript or JavaScript method
56+
### Alternative 1: TypeScript or JavaScript method
3457

3558
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.
3659

@@ -46,17 +69,28 @@ And now you can run your script like this: `node my-script.js`
4669

4770
## Example
4871

49-
Use this library as a `postbuild` hook in your `package.json`
72+
Use this library as a `postbuild` hook in your `package.json` with config file `svelte-sitemap.cjs` in your project root.
73+
74+
File: `package.json`
5075

5176
```json
5277
{
5378
"name": "my-project",
5479
"scripts": {
55-
"postbuild": "npx svelte-sitemap --domain https://mydomain.com"
80+
"postbuild": "npx svelte-sitemap"
5681
}
5782
}
5883
```
5984

85+
File: `svelte-sitemap.cjs`
86+
87+
```typescript
88+
module.exports = {
89+
domain: 'https://www.example.com',
90+
trailingSlashes: true
91+
};
92+
```
93+
6094
## ⚙️ Options
6195

6296
| Option | Description | default | example |
@@ -138,6 +172,7 @@ yarn demo
138172
- svelte-sitemap is workaround for [this official SvelteKit issue](https://github.com/sveltejs/kit/issues/1142)
139173
- Brand new version is inspired by [Richard's article](https://r-bt.com/learning/sveltekit-sitemap/)
140174
- Thanks to [@auderer](https://github.com/auderer) because [his issue](https://github.com/bartholomej/svelte-sitemap/issues/1) changed the direction of this library
175+
- Config files inspired by [next-sitemap](https://github.com/iamvishnusankar/next-sitemap)
141176

142177
## 📝 License
143178

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)