feat: add sitemap endpoint
This commit is contained in:
parent
01fe61261c
commit
4095158e7b
1 changed files with 5 additions and 10 deletions
|
|
@ -1,20 +1,15 @@
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
import yaml from 'js-yaml';
|
|
||||||
import bookmarksRaw from '../data/bookmarks.yaml?raw';
|
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import type { APIContext } from 'astro';
|
import type { APIContext } from 'astro';
|
||||||
|
|
||||||
interface Bookmark {
|
const SUBDOMAINS = [
|
||||||
date: string;
|
'https://penfield.wynne.rs/',
|
||||||
title: string;
|
];
|
||||||
url: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function GET(context: APIContext) {
|
export async function GET(context: APIContext) {
|
||||||
const site = context.site?.origin ?? 'https://wynne.rs';
|
const site = context.site?.origin ?? 'https://wynne.rs';
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts');
|
||||||
const bookmarks = yaml.load(bookmarksRaw) as Bookmark[];
|
|
||||||
|
|
||||||
const txtDir = path.join(process.cwd(), 'public/txt');
|
const txtDir = path.join(process.cwd(), 'public/txt');
|
||||||
const txtFiles = fs.existsSync(txtDir)
|
const txtFiles = fs.existsSync(txtDir)
|
||||||
|
|
@ -29,9 +24,9 @@ export async function GET(context: APIContext) {
|
||||||
...txtFiles.map(txt => `/txt/${txt}`),
|
...txtFiles.map(txt => `/txt/${txt}`),
|
||||||
'/bookmarks',
|
'/bookmarks',
|
||||||
'/guestbook',
|
'/guestbook',
|
||||||
].map(path => `${site}${path}`);
|
].map(p => `${site}${p}`);
|
||||||
|
|
||||||
return new Response(urls.join('\n'), {
|
return new Response([...urls, ...SUBDOMAINS].join('\n'), {
|
||||||
headers: { 'Content-Type': 'text/plain' },
|
headers: { 'Content-Type': 'text/plain' },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue