refactor(v2): do not generate RSS files for empty feed (#4905)

This commit is contained in:
Alexey Pyltsyn 2021-06-09 14:26:53 +03:00 committed by GitHub
parent 526ce44933
commit f71e83450f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 29 deletions

View file

@ -1,18 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`blogFeed atom can show feed without posts 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
<feed xmlns=\\"http://www.w3.org/2005/Atom\\">
<id>https://docusaurus.io/blog</id>
<title>Hello Blog</title>
<updated>2015-10-25T23:29:00.000Z</updated>
<generator>https://github.com/jpmonette/feed</generator>
<link rel=\\"alternate\\" href=\\"https://docusaurus.io/blog\\"/>
<subtitle>Hello Blog</subtitle>
<icon>https://docusaurus.io/image/favicon.ico</icon>
<rights>Copyright</rights>
</feed>"
`;
exports[`blogFeed atom should not show feed without posts 1`] = `null`;
exports[`blogFeed atom shows feed item for each post 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
@ -49,20 +37,7 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
</feed>"
`;
exports[`blogFeed rss can show feed without posts 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
<rss version=\\"2.0\\">
<channel>
<title>Hello Blog</title>
<link>https://docusaurus.io/blog</link>
<description>Hello Blog</description>
<lastBuildDate>Sun, 25 Oct 2015 23:29:00 GMT</lastBuildDate>
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
<generator>https://github.com/jpmonette/feed</generator>
<copyright>Copyright</copyright>
</channel>
</rss>"
`;
exports[`blogFeed rss should not show feed without posts 1`] = `null`;
exports[`blogFeed rss shows feed item for each post 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>

View file

@ -32,7 +32,7 @@ function getBlogContentPaths(siteDir: string): BlogContentPaths {
describe('blogFeed', () => {
(['atom', 'rss'] as const).forEach((feedType) => {
describe(`${feedType}`, () => {
test('can show feed without posts', async () => {
test('should not show feed without posts', async () => {
const siteDir = __dirname;
const siteConfig = {
title: 'Hello',

View file

@ -67,7 +67,7 @@ export async function generateBlogFeed(
}
const {siteConfig} = context;
const blogPosts = await generateBlogPosts(contentPaths, context, options);
if (blogPosts == null) {
if (!blogPosts.length) {
return null;
}

View file

@ -117,6 +117,7 @@ export default function pluginContentBlog(
const {postsPerPage, routeBasePath} = options;
blogPosts = await generateBlogPosts(contentPaths, context, options);
if (!blogPosts.length) {
return null;
}
@ -506,9 +507,14 @@ export default function pluginContentBlog(
},
injectHtmlTags() {
if (!blogPosts.length) {
return {};
}
if (!options.feedOptions?.type) {
return {};
}
const feedTypes = options.feedOptions.type;
const {
siteConfig: {title},