Sveltekit Sitemap screenshot

Sveltekit Sitemap

Author Avatar Theme by Joonel
Updated: 19 Dec 2023
5 Stars

Original beynar's repo with fixes.

Categories

Overview

This product is a library designed to help generate and maintain dynamic sitemap.xml and robots.txt files for SvelteKit apps. It consists of a Vite plugin and a Svelte-kit hook. The plugin watches the routes folder and generates a typescript representation of it, while the hook delivers sitemap.xml and robots.txt responses based on the params and the typescript sitemap.

Features

  • Vite Plugin: A plugin that watches the routes folder and generates a typescript representation of the routes.
  • Svelte-kit Hook: A hook that delivers sitemap.xml and robots.txt responses based on the params and the typescript sitemap.
  • Custom Routes Definitions: Define custom routes definitions and robots directives.
  • Configurable: Configure the plugin to specify the routes directory and output file for the sitemap.

Installation

To use this library, follow these steps:

  1. Add the vite plugin:
// vite.config.js
import { sitemapPlugin } from 'sveltekit-sitemap';

export default {
  plugins: [
    svelte(),
    sitemapPlugin({
      routesDir: './src/routes',
      sitemapFile: './src/sitemap.ts',
    }),
  ],
};
  1. Use the hook with the generated sitemap and define your custom routes definitions and robots directives:
import { sitemapHook } from 'sveltekit-sitemap';

export function hooks() {
  sitemapHook({
    routes: getRoutes,
    robots: getRobots,
  });
}

Summary

The sveltekit-sitemap library is a useful tool for generating and maintaining dynamic sitemap.xml and robots.txt files for SvelteKit apps. It provides a Vite plugin for generating a typescript representation of the routes and a Svelte-kit hook for delivering the sitemap and robots.txt responses. The library is configurable and allows for the definition of custom routes and robots directives.