diff --git a/src/constants.ts b/src/constants.ts index 313316b..09f0654 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,6 @@ export const templatesUrl = 'https://raw.githubusercontent.com/Lissy93/portainer-templates/main/templates.json'; +export const baseUrl = 'https://portainer-templates.as93.net'; + export const gitHubRepo = 'https://github.com/lissy93/portainer-templates'; \ No newline at end of file diff --git a/src/routes/sitemap.xml/+server.ts b/src/routes/sitemap.xml/+server.ts new file mode 100644 index 0000000..681c495 --- /dev/null +++ b/src/routes/sitemap.xml/+server.ts @@ -0,0 +1,41 @@ +import type { RequestHandler } from '@sveltejs/kit'; + +import { templatesUrl, baseUrl } from '$src/constants'; +import type { Template } from '$src/Types'; + +const fetchData = async () => { + const data = await fetch(templatesUrl).then((res) => res.json()); + return await data.templates.map((d: Template) => `${baseUrl}/${d.title.toLowerCase().replace(/[^a-zA-Z ]/g, "").replaceAll(' ', '-')}`); +}; + +const generationDate = () => { + const date = new Date(); + return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; +} + +export async function GET() { + const data = await fetchData(); + + const sitemap = ` + + + ${baseUrl} + ${generationDate()} + weekly + 1 + + ${data.map((url: string) => ` + + ${url} + ${generationDate()} + weekly + 0.8 + `) + .join('')} + `; + + return new Response(sitemap, { + headers: { 'Content-Type': 'application/xml' } + } + ); +}