-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-rss.js
68 lines (62 loc) · 1.91 KB
/
build-rss.js
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
58
59
60
61
62
63
64
65
66
67
68
import fs from 'fs'
import path from 'path'
import ReactDOMServer from 'react-dom/server'
import { MDXProvider } from '@mdx-js/react'
import { Feed } from 'feed'
import { MDXComponents } from '@/components/mdx/index'
import { getAllPublishedEssays } from '@/utils/essay/getAllEssayPreviews'
import { getAllPublishedTutorials } from '@/utils/tutorial/getAllTutorialPreviews'
const siteUrl = 'https://akshaykadam.com'
const author = {
name: 'Akshay Kadam',
email: '[email protected]',
link: 'https://twitter.com/@deadcoder0904',
}
const feed = new Feed({
title: 'Akshay Kadam',
description: 'Posts about Startups, Entrepreneurship, SaaS, Tech & much more.',
id: siteUrl,
link: siteUrl,
language: 'en',
image: `${siteUrl}/favicon-32x32.png`,
favicon: `${siteUrl}/favicon.ico`,
copyright: 'All rights reserved 2020, Akshay Kadam',
feedLinks: {
json: `${siteUrl}/json`,
atom: `${siteUrl}/atom`,
},
author,
})
const posts = [...getAllPublishedEssays(), ...getAllPublishedTutorials()]
posts.forEach(({ slug, module: { meta, default: Content } }) => {
const mdx = (
<MDXProvider components={MDXComponents}>
<Content />
</MDXProvider>
)
const html = ReactDOMServer.renderToStaticMarkup(mdx)
const postText = `<div style="margin-top=55px; font-style: italic;">(The post <a href="${siteUrl}/${slug}">${meta.title}</a> appeared first on <a href="${siteUrl}">Akshay Kadam's Blog</a>.)</div>`
feed.addItem({
title: meta.title,
id: meta.title,
link: slug,
comments: meta.discussion,
description: meta.description,
content: html + postText,
author,
date: new Date(meta.date),
image: siteUrl + meta.image,
extensions: [
{
name: '_comments',
objects: {
about: 'link to discussions forum',
comments: meta.discussion,
},
},
],
})
})
fs.writeFileSync('./out/feed.xml', feed.rss2())
fs.writeFileSync('./out/atom.xml', feed.atom1())
fs.writeFileSync('./out/feed.json', feed.json1())