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