Skip to content

Commit 850d766

Browse files
committed
fix rss feed
1 parent f05d3cb commit 850d766

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/Post.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ function visitBackmatter(node: any, fn) {
501501
}
502502
}
503503

504-
function postBackmatter(post) {
504+
export function postBackmatter(post: {+body: string}): Object {
505505
const backmatter = {};
506506
const ast = parseMarkdown(post.body);
507507
visitBackmatter(ast, (node) => {
@@ -514,7 +514,13 @@ function postBackmatter(post) {
514514
return backmatter;
515515
}
516516

517-
export function computePostDate({backmatter, createdAt}): Date {
517+
export function computePostDate({
518+
backmatter,
519+
createdAt,
520+
}: {
521+
backmatter: Object,
522+
createdAt: string,
523+
}): Date {
518524
if (backmatter.publishedDate) {
519525
return new Date(backmatter.publishedDate);
520526
}

src/RssFeed.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Feed} from 'feed';
66
import graphql from 'babel-plugin-relay/macro';
77
import {createEnvironment} from './Environment';
88
import {fetchQuery} from 'react-relay/hooks';
9-
import {computePostDate, postPath} from './Post';
9+
import {postBackmatter, computePostDate, postPath} from './Post';
1010
import {RssMarkdownRenderer} from './MarkdownRenderer';
1111
import {ServerStyleSheet} from 'styled-components';
1212
import inlineCss from 'inline-css/lib/inline-css';
@@ -68,6 +68,13 @@ function removeTrailingSlash(s: ?string): string {
6868
return s;
6969
}
7070

71+
function postDate(post) {
72+
return computePostDate({
73+
backmatter: postBackmatter(post),
74+
createdAt: post.createdAt,
75+
});
76+
}
77+
7178
export async function buildFeed({
7279
basePath,
7380
siteHostname,
@@ -96,13 +103,13 @@ export async function buildFeed({
96103

97104
const feed = new Feed({
98105
title: config.title,
99-
description: config.description,
106+
description: config.description || '',
100107
id: baseUrl,
101108
link: baseUrl,
102109
language: 'en',
103110
image: `${baseUrl}/logo.png`,
104111
favicon: `${baseUrl}/favicon.ico`,
105-
updated: latestPost ? computePostDate(latestPost) : null,
112+
updated: latestPost ? postDate(latestPost) : null,
106113
generator: '',
107114
feedLinks: {
108115
json: `${baseUrl}/feed.json`,
@@ -127,7 +134,7 @@ export async function buildFeed({
127134
}
128135
: null,
129136
),
130-
date: computePostDate(post),
137+
date: postDate(post),
131138
});
132139
}
133140
}

0 commit comments

Comments
 (0)