forked from joshwcomeau/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrss-plugin-config.js
93 lines (85 loc) · 2.75 KB
/
rss-plugin-config.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// gatsby-plugin-feed config
module.exports = {
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allMdx } }) => {
const data = allMdx.edges
.filter(edge => {
const { isPublished } = edge.node.frontmatter;
return isPublished;
})
.map(edge => {
const { siteUrl } = site.siteMetadata;
const {
slug,
abstract,
publishedOn,
interactive,
} = edge.node.frontmatter;
const postUrl = `${siteUrl}/posts/${slug}`;
let html;
if (interactive) {
html = `<div style="margin-top: 50px; font-style: italic;">This post features interactive elements, and cannot be displayed in an RSS reader. <strong><a href="${postUrl}">View it on joshwcomeau.com</a></strong>.</div>`;
} else {
const disclaimer = `${abstract}<div style="margin-top: 50px; font-style: italic;"><strong><a href="${postUrl}">View the original post</a>.</strong></div><br /><br />`;
// Hacky workaround for https://github.com/gaearon/overreacted.io/issues/65
html = edge.node.html
.replace(/href="\//g, `href="${siteUrl}/`)
.replace(/src="\//g, `src="${siteUrl}/`)
.replace(/"\/static\//g, `"${siteUrl}/static/`)
.replace(/,\s*\/static\//g, `,${siteUrl}/static/`);
html = disclaimer + html;
}
return Object.assign({}, edge.node.frontmatter, {
description: abstract,
date: publishedOn,
url: postUrl,
guid: postUrl,
custom_elements: [{ 'content:encoded': html }],
});
});
return data;
},
query: `
{
allMdx(
limit: 1000,
sort: { order: DESC, fields: [frontmatter___publishedOn] }
) {
edges {
node {
excerpt
html
frontmatter {
title
slug
publishedOn
abstract
isPublished
interactive
}
}
}
}
}
`,
output: '/rss.xml',
title: "Josh Comeau's blog",
},
],
},
};