feat(content-blog): support json feed (#6126)

* feat(content-blog): support json feed

* feat(content-blog): support json feed

* feat(content-blog): add json type to default feed options

* Refactors, docs, validation

* Fix test

* Ammend docs

* Add API doc

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
不郑 2021-12-18 22:47:40 +08:00 committed by GitHub
parent 06bd44c693
commit 7e5f6bb805
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 165 additions and 30 deletions

View file

@ -50,7 +50,7 @@ async function testGenerateFeeds(
}
describe('blogFeed', () => {
(['atom', 'rss'] as const).forEach((feedType) => {
(['atom', 'rss', 'json'] as const).forEach((feedType) => {
describe(`${feedType}`, () => {
test('should not show feed without posts', async () => {
const siteDir = __dirname;
@ -117,8 +117,22 @@ describe('blogFeed', () => {
defaultReadingTime({content}),
} as PluginOptions,
);
const feedContent =
feed && (feedType === 'rss' ? feed.rss2() : feed.atom1());
let feedContent = '';
switch (feedType) {
case 'rss':
feedContent = feed.rss2();
break;
case 'json':
feedContent = feed.json1();
break;
case 'atom':
feedContent = feed.atom1();
break;
default:
break;
}
expect(feedContent).toMatchSnapshot();
});
});