Skip to content

Commit af00784

Browse files
committed
add rss feeds
1 parent 146e185 commit af00784

File tree

9 files changed

+198
-1
lines changed

9 files changed

+198
-1
lines changed

apps/codingcatdev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"eslint": "^8.35.0",
3434
"eslint-config-prettier": "^8.6.0",
3535
"eslint-plugin-svelte3": "^4.0.0",
36+
"feed": "^4.2.2",
3637
"firebase-admin": "^11.5.0",
3738
"flexsearch": "^0.7.31",
3839
"marked": "^4.2.12",

apps/codingcatdev/src/lib/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface Podcast extends Content {
3636

3737
export interface Author {
3838
id: string;
39-
displayName?: string;
39+
name?: string;
4040
slug: string;
4141
}
4242

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { listContent, parseModules } from '$lib/server/content';
2+
import { ContentType } from '$lib/types';
3+
import { buildFeed } from '../rss';
4+
5+
6+
const contentType = ContentType.post;
7+
8+
/** @type {import('./$types').RequestHandler} */
9+
export const GET = async () => {
10+
const modules = import.meta.glob(['../../../content/post/*.md']);
11+
const contentItems = await parseModules(modules);
12+
13+
//xml rss feed response
14+
return new Response(
15+
buildFeed({
16+
contentType, contents: (await listContent({ contentItems, limit: 10000 })).content
17+
}).rss2(),
18+
{
19+
headers: {
20+
'content-type': 'application/rss+xml', 'cache-control': 'max-age=0, s-maxage=3600',
21+
},
22+
}
23+
)
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { listContent, parseModules } from '$lib/server/content';
2+
import { ContentType } from '$lib/types';
3+
import { buildFeed } from '../rss';
4+
5+
6+
const contentType = ContentType.post;
7+
8+
/** @type {import('./$types').RequestHandler} */
9+
export const GET = async () => {
10+
const modules = await import.meta.glob(['../../../content/course/*/*.md']);
11+
const contentItems = await parseModules(modules);
12+
13+
//xml rss feed response
14+
return new Response(
15+
buildFeed({
16+
contentType, contents: (await listContent({ contentItems, limit: 10000 })).content
17+
}).rss2(),
18+
{
19+
headers: {
20+
'content-type': 'application/rss+xml', 'cache-control': 'max-age=0, s-maxage=3600',
21+
},
22+
}
23+
)
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { listContent, parseModules } from '$lib/server/content';
2+
import { ContentType } from '$lib/types';
3+
import { buildFeed } from '../rss';
4+
5+
6+
const contentType = ContentType.post;
7+
8+
/** @type {import('./$types').RequestHandler} */
9+
export const GET = async () => {
10+
const modules = import.meta.glob(['../../../content/podcast/*.md']);
11+
const contentItems = await parseModules(modules);
12+
13+
//xml rss feed response
14+
return new Response(
15+
buildFeed({
16+
contentType, contents: (await listContent({ contentItems, limit: 10000 })).content
17+
}).rss2(),
18+
{
19+
headers: {
20+
'content-type': 'application/rss+xml', 'cache-control': 'max-age=0, s-maxage=3600',
21+
},
22+
}
23+
)
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { listContent, parseModules } from '$lib/server/content';
2+
import { ContentType } from '$lib/types';
3+
import { buildFeed } from '../rss';
4+
5+
6+
const contentType = ContentType.post;
7+
8+
/** @type {import('./$types').RequestHandler} */
9+
export const GET = async () => {
10+
const modules = import.meta.glob(['../../../content/schedule/*.md']);
11+
const contentItems = await parseModules(modules);
12+
13+
//xml rss feed response
14+
return new Response(
15+
buildFeed({
16+
contentType, contents: (await listContent({ contentItems, limit: 10000 })).content
17+
}).rss2(),
18+
{
19+
headers: {
20+
'content-type': 'application/rss+xml', 'cache-control': 'max-age=0, s-maxage=3600',
21+
},
22+
}
23+
)
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { listContent, parseModules } from '$lib/server/content';
2+
import { ContentType } from '$lib/types';
3+
import { buildFeed } from '../rss';
4+
5+
6+
const contentType = ContentType.post;
7+
8+
/** @type {import('./$types').RequestHandler} */
9+
export const GET = async () => {
10+
const modules = import.meta.glob(['../../../content/tutorial/*.md']);
11+
const contentItems = await parseModules(modules);
12+
13+
//xml rss feed response
14+
return new Response(
15+
buildFeed({
16+
contentType, contents: (await listContent({ contentItems, limit: 10000 })).content
17+
}).rss2(),
18+
{
19+
headers: {
20+
'content-type': 'application/rss+xml', 'cache-control': 'max-age=0, s-maxage=3600',
21+
},
22+
}
23+
)
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import type { Content, ContentType } from "$lib/types";
2+
import { Feed } from 'feed';
3+
4+
const site = 'https://codingcat.dev';
5+
6+
7+
export const buildFeed = ({
8+
contents,
9+
contentType,
10+
}: {
11+
contents: Content[];
12+
contentType: ContentType;
13+
}) => {
14+
const feed = new Feed({
15+
title: `${site} - ${contentType} feed`,
16+
description: `${site} - ${contentType} feed`,
17+
id: `${site}`,
18+
link: `${site}`,
19+
language: 'en', // optional, used only in RSS 2.0, possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
20+
image: `https://media.codingcat.dev/image/upload/f_png,c_thumb,g_face,w_1200,h_630/dev-codingcatdev-photo/v60h88eohd7ufghkspgo.png`,
21+
favicon: `${site}/favicon.ico`,
22+
copyright: `All rights reserved 2021, ${site}`,
23+
updated: new Date(),
24+
feedLinks: {
25+
rss2: `${site}/blog/rss.xml`,
26+
},
27+
author: {
28+
name: 'Alex Patterson',
29+
email: 'alex@codingcat.dev',
30+
link: `${site}`,
31+
},
32+
});
33+
34+
for (const content of contents) {
35+
feed.addItem({
36+
title: content.title || '',
37+
link: `${site}/${contentType}/${content.slug}`,
38+
description: `${content.excerpt}`,
39+
image: content.cover || feed.items.at(0)?.image,
40+
date: content.start || new Date(),
41+
author: content?.authors ? content.authors?.map((author) => {
42+
return {
43+
name: author.name,
44+
link: `${site}/authors/${author.slug}`,
45+
};
46+
})
47+
: [{
48+
name: 'Alex Patterson',
49+
email: 'alex@codingcat.dev',
50+
link: `${site}`,
51+
}],
52+
});
53+
}
54+
return feed;
55+
};

pnpm-lock.yaml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)