|
| 1 | +import type { APIRoute } from "astro" |
| 2 | +import { getCollection } from "astro:content" |
| 3 | +import { resourceTabs, ALL_RESOURCES } from "~/components/resources/tags" |
| 4 | +import { sitemapResponse, formatLastMod, gitLastModified } from "~/utils/sitemap.ts" |
| 5 | + |
| 6 | +export const GET: APIRoute = async () => { |
| 7 | + const pageEntries = Object.entries( |
| 8 | + import.meta.glob<{ url?: string }>("../resources/**/*.astro", { eager: true }), |
| 9 | + ) |
| 10 | + |
| 11 | + const pageUrls = pageEntries |
| 12 | + .filter(([_, mod]) => mod.url && mod.url.indexOf("[") === -1) |
| 13 | + .map(([globPath, mod]) => { |
| 14 | + const filePath = globPath.replace(/^\.\.\//, "src/pages/") |
| 15 | + return { |
| 16 | + loc: `https://kestra.io${mod.url}`, |
| 17 | + lastmod: formatLastMod(gitLastModified(filePath)), |
| 18 | + } |
| 19 | + }) |
| 20 | + |
| 21 | + const tagUrls = Array.from(resourceTabs.keys()) |
| 22 | + .filter((tag) => tag !== ALL_RESOURCES) |
| 23 | + .map((tag) => ({ loc: `https://kestra.io/resources/${tag}` })) |
| 24 | + |
| 25 | + const articles = await getCollection("resources") |
| 26 | + |
| 27 | + const articleUrls = articles |
| 28 | + .filter((post) => !post.data.href) |
| 29 | + .map((post) => { |
| 30 | + let lastmod = formatLastMod((post.data as any).date ?? null) |
| 31 | + if (!lastmod && (post as any).filePath) { |
| 32 | + lastmod = formatLastMod(gitLastModified((post as any).filePath)) |
| 33 | + } |
| 34 | + return { |
| 35 | + loc: `https://kestra.io/resources/${post.data.tag}/${post.id.toLowerCase()}`, |
| 36 | + lastmod, |
| 37 | + } |
| 38 | + }) |
| 39 | + |
| 40 | + return sitemapResponse([...pageUrls, ...tagUrls, ...articleUrls]) |
| 41 | +} |
0 commit comments