-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathrenderRSSFeedToString.js
More file actions
57 lines (50 loc) · 1.34 KB
/
Copy pathrenderRSSFeedToString.js
File metadata and controls
57 lines (50 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Feed } from 'feed'
import { crawl, resolve } from 'navi'
import path from 'path'
import React from 'react'
import ReactDOMServer from 'react-dom/server'
import siteMetadata from './siteMetadata'
async function renderRSSFeed({ routes }) {
let publicURL = process.env.PUBLIC_URL || '/'
let { paths } = await crawl({
routes,
root: '/posts',
})
const feed = new Feed({
title: siteMetadata.title,
description: siteMetadata.description,
id: publicURL,
// TODO: set this based on the siteMap slugs
// updated: new Date(),
link: publicURL,
author: {
name: siteMetadata.author,
},
});
for (let pathname of paths.sort()) {
let route = await resolve({
routes,
url: pathname,
})
let meta = route.data || {}
let link = path.join(publicURL, pathname)
// Each post's content is just an MDX component, which can be rendered
// independently of the rest of the app.
let content = ReactDOMServer.renderToStaticMarkup(
React.createElement(route.views[route.views.length - 1].MDXComponent)
)
// todo: add a date
feed.addItem({
title: route.title,
id: link,
link: link,
description: meta.spoiler,
content,
author: {
name: siteMetadata.author,
}
})
}
return feed.rss2();
}
export default renderRSSFeed