Skip to content

Commit

Permalink
✨ Add sitemap.xml again
Browse files Browse the repository at this point in the history
  • Loading branch information
Malte2036 committed Nov 15, 2024
1 parent 344787f commit dd4b98a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/routes/sitemap.xml/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { getQuestions } from '$lib/api/api';
import { QuestionType } from '$lib/model/question';

export async function GET() {
const types: QuestionType[] = Object.values(QuestionType);

const quizTypeLinks = types.map(
(t) =>
`
<url>
<loc>https://thw-tools.de/quiz/${t}/</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://thw-tools.de/quiz/${t}/listing/</loc>
<priority>0.8</priority>
</url>`
);

const singleQuestionLinks = await Promise.all(
types.map(async (t) => {
const questionIds = await getQuestions(t);
return questionIds
.sort((a, b) => a.number - b.number)
.map(
(q) =>
`
<url>
<loc>https://thw-tools.de/quiz/${t}/${q.number}/</loc>
<priority>0.6</priority>
</url>`
)
.join('');
})
);

return new Response(
`
<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="https://www.w3.org/1999/xhtml"
xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0"
xmlns:news="https://www.google.com/schemas/sitemap-news/0.9"
xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"
>
<url>
<loc>https://thw-tools.de/</loc>
<priority>1.00</priority>
</url>
<url>
<loc>https://thw-tools.de/clothing/</loc>
<priority>0.8</priority>
</url>
${quizTypeLinks.join('')}
${singleQuestionLinks.join('')}
</urlset>`.trim(),
{
headers: {
'Content-Type': 'application/xml'
}
}
);
}
2 changes: 1 addition & 1 deletion svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const config = {
? adapterStatic({
pages: 'build',
assets: 'build',
fallback: null,
fallback: '200.html',
precompress: false,
strict: true
})
Expand Down

0 comments on commit dd4b98a

Please sign in to comment.