mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-30 18:58:36 +02:00
refactor(v2): do not generate RSS files for empty feed (#4905)
This commit is contained in:
parent
526ce44933
commit
f71e83450f
4 changed files with 10 additions and 29 deletions
|
@ -1,18 +1,6 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`blogFeed atom can show feed without posts 1`] = `
|
exports[`blogFeed atom should not show feed without posts 1`] = `null`;
|
||||||
"<?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 shows feed item for each post 1`] = `
|
exports[`blogFeed atom shows feed item for each post 1`] = `
|
||||||
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
|
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
|
||||||
|
@ -49,20 +37,7 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
||||||
</feed>"
|
</feed>"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`blogFeed rss can show feed without posts 1`] = `
|
exports[`blogFeed rss should not show feed without posts 1`] = `null`;
|
||||||
"<?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 shows feed item for each post 1`] = `
|
exports[`blogFeed rss shows feed item for each post 1`] = `
|
||||||
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
|
"<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?>
|
||||||
|
|
|
@ -32,7 +32,7 @@ function getBlogContentPaths(siteDir: string): BlogContentPaths {
|
||||||
describe('blogFeed', () => {
|
describe('blogFeed', () => {
|
||||||
(['atom', 'rss'] as const).forEach((feedType) => {
|
(['atom', 'rss'] as const).forEach((feedType) => {
|
||||||
describe(`${feedType}`, () => {
|
describe(`${feedType}`, () => {
|
||||||
test('can show feed without posts', async () => {
|
test('should not show feed without posts', async () => {
|
||||||
const siteDir = __dirname;
|
const siteDir = __dirname;
|
||||||
const siteConfig = {
|
const siteConfig = {
|
||||||
title: 'Hello',
|
title: 'Hello',
|
||||||
|
|
|
@ -67,7 +67,7 @@ export async function generateBlogFeed(
|
||||||
}
|
}
|
||||||
const {siteConfig} = context;
|
const {siteConfig} = context;
|
||||||
const blogPosts = await generateBlogPosts(contentPaths, context, options);
|
const blogPosts = await generateBlogPosts(contentPaths, context, options);
|
||||||
if (blogPosts == null) {
|
if (!blogPosts.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,7 @@ export default function pluginContentBlog(
|
||||||
const {postsPerPage, routeBasePath} = options;
|
const {postsPerPage, routeBasePath} = options;
|
||||||
|
|
||||||
blogPosts = await generateBlogPosts(contentPaths, context, options);
|
blogPosts = await generateBlogPosts(contentPaths, context, options);
|
||||||
|
|
||||||
if (!blogPosts.length) {
|
if (!blogPosts.length) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -506,9 +507,14 @@ export default function pluginContentBlog(
|
||||||
},
|
},
|
||||||
|
|
||||||
injectHtmlTags() {
|
injectHtmlTags() {
|
||||||
|
if (!blogPosts.length) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
if (!options.feedOptions?.type) {
|
if (!options.feedOptions?.type) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const feedTypes = options.feedOptions.type;
|
const feedTypes = options.feedOptions.type;
|
||||||
const {
|
const {
|
||||||
siteConfig: {title},
|
siteConfig: {title},
|
||||||
|
|
Loading…
Add table
Reference in a new issue