-
-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Currently this package scans the src/routes
folder to generate the sitemap. This works fine for normal pages, but it doesn't work for dynamically generated pages like [slug].svelte
, etc.
Instead, we should scan the build
folder. Here's a demo script that does this:
import fs from "fs";
import fg from "fast-glob";
import { create } from "xmlbuilder2";
import pkg from "./package.json";
const getUrl = (url) => {
const trimmed = url.slice(6).replace("index.html", "");
return `${pkg.url}/${trimmed}`;
};
async function createSitemap() {
const sitemap = create({ version: "1.0" }).ele("urlset", {
xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9"
});
const pages = await fg(["build/**/*.html"]);
pages.forEach((page) => {
const url = sitemap.ele("url");
url.ele("loc").txt(getUrl(page));
url.ele("changefreq").txt("weekly");
});
const xml = sitemap.end({ prettyPrint: true });
fs.writeFileSync("build/sitemap.xml", xml);
}
createSitemap();
We should use a method like this instead of routes, as it will capture the actual output from Svelte, which can differ greatly from the source files.
madeleineostoja and bartholomej
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request