CriticalMoments / CMSaasStarter

A modern SaaS template/boilerplate built with SvelteKit, Tailwind, and Supabase. Includes marketing page, blog, subscriptions, auth, user dashboard, user settings, pricing page, and more.
https://saasstarter.work
MIT License
1.32k stars 337 forks source link

Add sitemap #130

Closed jasongitmail closed 1 month ago

jasongitmail commented 1 month ago

This looks great. Hopefully templates like these will help the SvelteKit community to grow!

For SEO, it's missing a sitemap and robots.txt.

I might suggest Super Sitemap: https://github.com/jasongitmail/super-sitemap (I'm the author & searched deeply for a good one before building this.)

// /src/routes/sitemap.xml/+server.ts
import * as sitemap from 'super-sitemap';
import type { RequestHandler } from '@sveltejs/kit';

export const prerender = true;

export const GET: RequestHandler = async () => {
  return await sitemap.response({
    origin: 'https://example.com',
    excludeRoutePatterns: [
      '.*\\(admin\\).*', // i.e. exclude routes within admin group
    ],
  });
};

If you decide to add it, remember to include the (admin) group within the excludeRoutePatterns to omit those from your sitemap, and any others you might want to exclude.

Since your blog consists of svelte files, all those routes will be included automatically.

scosman commented 1 month ago

Want to make a PR? 😀

jasongitmail commented 1 month ago

Added a PR. Allows edits by maintainers.

You should run it and visit /sitemap.xml to confirm all routes you want to exclude are excluded, but otherwise it should work fine. I don't have Supabase set up to run CMSaasStarter successfully.

scosman commented 1 month ago

Thanks! I'll take a look soon!