Skip to content

Commit

Permalink
add sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrJamal committed Mar 25, 2024
1 parent 3d2bcb5 commit 2eb9ef7
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/pages/sitemap.xml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { APIRoute } from 'astro'

const SITE = 'https://shrjamal.github.io/2048-3x3'
export const GET: APIRoute = async () => {
return new Response(
`<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${['/'].map((path) => getXMLEntry({ path, lastmod: '10 March 2024' })).join('')}
</urlset>
`,
{
headers: {
'content-type': 'application/xml',
},
},
)
}

function getXMLEntry({
path,
changeFreq = 'monthly',
priority = '0.5',
lastmod,
}: {
path: string
changeFreq?: string
priority?: string
lastmod?: string
}) {
return `
<url>
<loc>${SITE}${path}</loc>
${lastmod ? `<lastmod>${new Date(lastmod).toISOString()}</lastmod>` : ''}
${changeFreq ? `<changefreq>${changeFreq}</changefreq>` : ''}
${priority ? `<priority>${priority}</priority>` : ''}
</url>
`
}

0 comments on commit 2eb9ef7

Please sign in to comment.