Code for my personal website

chore: create intial pages and content config

+86
+37
src/content/config.ts
··· 1 + import { defineCollection, z } from 'astro:content'; 2 + 3 + const blog = defineCollection({ 4 + type: 'content', 5 + schema: z.object({ 6 + title: z.string(), 7 + description: z.string(), 8 + date: z.coerce.date(), 9 + draft: z.boolean() 10 + }) 11 + }); 12 + 13 + const work = defineCollection({ 14 + type: 'content', 15 + schema: z.object({ 16 + company: z.string(), 17 + role: z.string(), 18 + dateStart: z.coerce.date(), 19 + dateEnd: z.union([z.coerce.date(), z.string()]) 20 + }) 21 + }); 22 + 23 + const projects = defineCollection({ 24 + type: 'content', 25 + schema: z.object({ 26 + title: z.string(), 27 + description: z.string(), 28 + date: z.coerce.date(), 29 + draft: z.boolean(), 30 + demoURL: z.string().optional(), 31 + repoURL: z.string().optional() 32 + }) 33 + }); 34 + 35 + const collections = { blog, work, projects }; 36 + 37 + export default collections;
+16
src/pages/robots.txt.ts
··· 1 + import type { APIRoute } from 'astro'; 2 + 3 + const robotsTxt = ` 4 + User-agent: * 5 + Allow: / 6 + 7 + Sitemap: ${new URL('sitemap-index.xml', import.meta.env.SITE).href} 8 + `.trim(); 9 + 10 + export const GET: APIRoute = () => { 11 + return new Response(robotsTxt, { 12 + headers: { 13 + 'Content-Type': 'text/plain; charset=utf-8' 14 + } 15 + }); 16 + };
+33
src/pages/rss.xml.ts
··· 1 + import rss from '@astrojs/rss'; 2 + import { getCollection } from 'astro:content'; 3 + import { HOME } from '@/config'; 4 + 5 + type Context = { 6 + site: string; 7 + }; 8 + 9 + export async function GET(context: Context) { 10 + const blog = (await getCollection('blog')).filter( 11 + (post: { data: { draft: boolean } }) => post.data.draft 12 + ); 13 + 14 + const projects = (await getCollection('projects')).filter( 15 + (project: { data: { draft: boolean } }) => project.data.draft 16 + ); 17 + 18 + const items = [...blog, ...projects].sort( 19 + (a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf() 20 + ); 21 + 22 + return rss({ 23 + title: HOME.TITLE, 24 + description: HOME.DESCRIPTION, 25 + site: context.site, 26 + items: items.map((item) => ({ 27 + title: item.data.title, 28 + description: item.data.description, 29 + pubDate: item.data.date, 30 + link: `/${item.collection}/${item.slug}/` 31 + })) 32 + }); 33 + }