-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getFeed } from "rss/utils" | ||
|
||
export async function GET() { | ||
const feed = await getFeed() | ||
const content = feed.json1() | ||
|
||
return new Response(content, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getFeed } from "rss/utils" | ||
|
||
export async function GET() { | ||
const feed = await getFeed() | ||
const content = feed.rss2() | ||
|
||
return new Response(content, { | ||
headers: { | ||
"Content-Type": "application/rss+xml", | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Feed } from "feed" | ||
import { cache } from "react" | ||
import { getAllPosts } from "lib/posts" | ||
import { siteMeta } from "lib/siteMeta" | ||
|
||
// Revalidate the data at most every hour | ||
export const revalidate = 3600 | ||
|
||
export const getFeed = cache(async () => { | ||
const posts = await getAllPosts() | ||
const author = { email: siteMeta.email, name: "Mark Skelton" } | ||
|
||
const feed = new Feed({ | ||
author, | ||
copyright: `All rights reserved ${new Date().getFullYear()}`, | ||
description: siteMeta.tagline, | ||
favicon: `${siteMeta.url}/favicon.ico`, | ||
feedLinks: { | ||
json: `${siteMeta.url}/rss/feed.json`, | ||
rss2: `${siteMeta.url}/rss/feed.xml`, | ||
}, | ||
id: siteMeta.url, | ||
image: `${siteMeta.url}/favicon.ico`, | ||
link: siteMeta.url, | ||
title: author.name, | ||
}) | ||
|
||
for (const post of posts) { | ||
const url = `${siteMeta.url}/blog/${post.slug}` | ||
// const html = ReactDOMServer.renderToStaticMarkup( | ||
// createElement(post.component, { isRssFeed: true }) | ||
// ) | ||
|
||
feed.addItem({ | ||
author: [author], | ||
// content: html, | ||
contributor: [author], | ||
date: new Date(post.date), | ||
description: post.description, | ||
id: post.slug, | ||
link: url, | ||
title: post.title, | ||
}) | ||
} | ||
|
||
return feed | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters