README
sitemap.xml
generator
Svelte Small helper which scans your Svelte routes and generates static sitemap.xml
- TypeScript, JavaScript, CLI version
- Useful options
- Compatible with Svelte
adapter-static
- Workaround for this official SvelteKit issue
Install
via yarn
or npm
yarn add svelte-sitemap --dev
# npm install svelte-sitemap --save-dev
Usage
CLI method (recommended)
Run in your project root folder to see how it works.
I recommend using it as a postbuild hook. See this example.
yarn svelte-sitemap --domain https://example.com
# npx svelte-sitemap --domain https://example.com
It scans your routes in build/
folder and generates build/sitemap.xml
file
TypeScript or JavaScript method (optional)
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 as a postbuild hook.
import { createSitemap } from 'svelte-sitemap/src/index.js';
createSitemap('https://example.com', { debug: true });
And now you can run your script like this: node my-script.js
Example
Highly recommended to use as postbuild
hook in your package.json
{
"name": "my-project",
"scripts": {
"postbuild": "npx svelte-sitemap --domain https://mydomain.com"
}
}
⚙️ Options
Option | Description | default | example |
---|---|---|---|
-d, --domain | Use your domain [required] | https://example.com |
-d https://mydomain.com |
-o, --out-dir | Set custum build folder | build |
-o dist |
-i, --ignore | Ignore files or folders | [] | -i '**/admin/**' -i 'my-secret-page' |
-t, --trailing-slashes | Add trailing slashes | false | --trailing-slashes |
-r, --reset-time | Set lastModified time to now | false | -r |
-c, --change-freq | Set change frequency Option | - | --change-freq daily |
-h, --help | Display this usage info | - | -v |
-v, --version | Show version | - | -h |
--debug | Show some useful logs | - | --debug |
🙋 FAQ
How to exclude directory?
Let's say we want to ignore all
admin
folders and subfolders + just one exact pagepages/my-secret-page
npx svelte-sitemap --domain https://www.example.com --ignore 'pages/my-secret-page' --ignore '**/admin/**'
🤝 Contributing
I welcome you to customize this according to your needs ;)
Pull requests for any improvements would be great!
Feel free to check issues page.
Developing and debugging this library
git clone git@github.com:bartholomej/svelte-sitemap.git
cd svelte-sitemap
yarn
yarn start
Run demo locally
You can find and modify it in ./demo.ts
file
yarn demo
🙏 Credits
- svelte-sitemap is workaround for this official SvelteKit issue
- Brand new version is inspired by Richard's article
- Thanks to @auderer because his issue changed the direction of this library
⭐️ Show your support
Give a ⭐️ if this project helped you!
Or if you are brave enough consider making a donation for some 🍺 or 🍵 ;)
🕵️ Privacy Policy
I DO NOT STORE ANY DATA. PERIOD.
I physically can't. I have nowhere to store it. I don't even have a server database to store it. So even if Justin Bieber asked nicely to see your data, I wouldn't have anything to show him.
That's why, with this library, what happens on your device stays on your device till disappear.
📝 License
Copyright © 2022 Lukas Bartak
Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)
All contents are licensed under the MIT license.