feat: add twtxt support
This commit is contained in:
parent
30cdde0fc2
commit
c57e214020
1 changed files with 17 additions and 0 deletions
17
src/pages/twtxt.txt.js
Normal file
17
src/pages/twtxt.txt.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
|
export async function GET(context) {
|
||||||
|
const posts = await getCollection('posts');
|
||||||
|
// Sort posts by date (newest first)
|
||||||
|
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
|
||||||
|
|
||||||
|
const twtxt = posts.map(post => (
|
||||||
|
`${new Date(post.data.pubDate).toISOString()}\t${post.data.title} ${context.site}post/${post.slug}`
|
||||||
|
)).join('\n');
|
||||||
|
|
||||||
|
return new Response(twtxt, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'text/plain'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue