mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
feat(v2): generalize usage of _ prefix convention to exclude content files/folders (#5173)
* create a swizzleWarning partial for shared text * Generalize usage of _ prefix convention to exclude content files/folders * add api doc * MDX loader should not expect metadata/frontmatter on MDX partial files
This commit is contained in:
parent
0851e0e5bf
commit
8bdb3da233
40 changed files with 249 additions and 80 deletions
|
@ -0,0 +1,3 @@
|
|||
This is a partial in file/folder starting with _:
|
||||
|
||||
It should be excluded by default
|
|
@ -0,0 +1,3 @@
|
|||
This is a partial in file/folder starting with _:
|
||||
|
||||
It should be excluded by default
|
|
@ -0,0 +1,3 @@
|
|||
This is a partial in file/folder starting with \_:
|
||||
|
||||
It should be excluded by default
|
|
@ -7,12 +7,26 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<feed xmlns=\\"http://www.w3.org/2005/Atom\\">
|
||||
<id>https://docusaurus.io/myBaseUrl/blog</id>
|
||||
<title>Hello Blog</title>
|
||||
<updated>2020-02-27T00:00:00.000Z</updated>
|
||||
<updated>2020-08-16T00:00:00.000Z</updated>
|
||||
<generator>https://github.com/jpmonette/feed</generator>
|
||||
<link rel=\\"alternate\\" href=\\"https://docusaurus.io/myBaseUrl/blog\\"/>
|
||||
<subtitle>Hello Blog</subtitle>
|
||||
<icon>https://docusaurus.io/myBaseUrl/image/favicon.ico</icon>
|
||||
<rights>Copyright</rights>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[Complex Slug]]></title>
|
||||
<id>/hey/my super path/héllô</id>
|
||||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô\\"/>
|
||||
<updated>2020-08-16T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[complex url slug]]></summary>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[Simple Slug]]></title>
|
||||
<id>/simple/slug</id>
|
||||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/simple/slug\\"/>
|
||||
<updated>2020-08-15T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[simple url slug]]></summary>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[draft]]></title>
|
||||
<id>draft</id>
|
||||
|
@ -20,6 +34,12 @@ exports[`blogFeed atom shows feed item for each post 1`] = `
|
|||
<updated>2020-02-27T00:00:00.000Z</updated>
|
||||
<summary type=\\"html\\"><![CDATA[this post should not be published yet]]></summary>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[some heading]]></title>
|
||||
<id>some heading</id>
|
||||
<link href=\\"https://docusaurus.io/myBaseUrl/blog/heading-as-title\\"/>
|
||||
<updated>2019-01-02T00:00:00.000Z</updated>
|
||||
</entry>
|
||||
<entry>
|
||||
<title type=\\"html\\"><![CDATA[date-matter]]></title>
|
||||
<id>date-matter</id>
|
||||
|
@ -46,10 +66,24 @@ exports[`blogFeed rss shows feed item for each post 1`] = `
|
|||
<title>Hello Blog</title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog</link>
|
||||
<description>Hello Blog</description>
|
||||
<lastBuildDate>Thu, 27 Feb 2020 00:00:00 GMT</lastBuildDate>
|
||||
<lastBuildDate>Sun, 16 Aug 2020 00:00:00 GMT</lastBuildDate>
|
||||
<docs>https://validator.w3.org/feed/docs/rss2.html</docs>
|
||||
<generator>https://github.com/jpmonette/feed</generator>
|
||||
<copyright>Copyright</copyright>
|
||||
<item>
|
||||
<title><![CDATA[Complex Slug]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/hey/my super path/héllô</link>
|
||||
<guid>/hey/my super path/héllô</guid>
|
||||
<pubDate>Sun, 16 Aug 2020 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[complex url slug]]></description>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[Simple Slug]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/simple/slug</link>
|
||||
<guid>/simple/slug</guid>
|
||||
<pubDate>Sat, 15 Aug 2020 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[simple url slug]]></description>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[draft]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/draft</link>
|
||||
|
@ -57,6 +91,12 @@ exports[`blogFeed rss shows feed item for each post 1`] = `
|
|||
<pubDate>Thu, 27 Feb 2020 00:00:00 GMT</pubDate>
|
||||
<description><![CDATA[this post should not be published yet]]></description>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[some heading]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/heading-as-title</link>
|
||||
<guid>some heading</guid>
|
||||
<pubDate>Wed, 02 Jan 2019 00:00:00 GMT</pubDate>
|
||||
</item>
|
||||
<item>
|
||||
<title><![CDATA[date-matter]]></title>
|
||||
<link>https://docusaurus.io/myBaseUrl/blog/date-matter</link>
|
||||
|
|
|
@ -9,6 +9,7 @@ import path from 'path';
|
|||
import {generateBlogFeed} from '../blogUtils';
|
||||
import {LoadContext, I18n} from '@docusaurus/types';
|
||||
import {PluginOptions, BlogContentPaths} from '../types';
|
||||
import {DEFAULT_OPTIONS} from '../pluginOptionSchema';
|
||||
|
||||
const DefaultI18N: I18n = {
|
||||
currentLocale: 'en',
|
||||
|
@ -84,7 +85,8 @@ describe('blogFeed', () => {
|
|||
{
|
||||
path: 'blog',
|
||||
routeBasePath: 'blog',
|
||||
include: ['*r*.md', '*.mdx'], // skip no-date.md - it won't play nice with snapshots
|
||||
include: DEFAULT_OPTIONS.include,
|
||||
exclude: DEFAULT_OPTIONS.exclude,
|
||||
feedOptions: {
|
||||
type: [feedType],
|
||||
copyright: 'Copyright',
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import globby from 'globby';
|
||||
import chalk from 'chalk';
|
||||
import path from 'path';
|
||||
import readingTime from 'reading-time';
|
||||
|
@ -27,6 +26,7 @@ import {
|
|||
getFolderContainingFile,
|
||||
posixPath,
|
||||
replaceMarkdownLinks,
|
||||
Globby,
|
||||
} from '@docusaurus/utils';
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
import {validateBlogPostFrontMatter} from './blogFrontMatter';
|
||||
|
@ -127,6 +127,7 @@ export async function generateBlogPosts(
|
|||
): Promise<BlogPost[]> {
|
||||
const {
|
||||
include,
|
||||
exclude,
|
||||
routeBasePath,
|
||||
truncateMarker,
|
||||
showReadingTime,
|
||||
|
@ -138,8 +139,9 @@ export async function generateBlogPosts(
|
|||
}
|
||||
|
||||
const {baseUrl = ''} = siteConfig;
|
||||
const blogSourceFiles = await globby(include, {
|
||||
const blogSourceFiles = await Globby(include, {
|
||||
cwd: contentPaths.contentPath,
|
||||
ignore: exclude,
|
||||
});
|
||||
|
||||
const blogPosts: BlogPost[] = [];
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
reportMessage,
|
||||
posixPath,
|
||||
addTrailingPathSeparator,
|
||||
createMatcher,
|
||||
} from '@docusaurus/utils';
|
||||
import {
|
||||
STATIC_DIR_NAME,
|
||||
|
@ -459,9 +460,10 @@ export default function pluginContentBlog(
|
|||
beforeDefaultRemarkPlugins,
|
||||
beforeDefaultRehypePlugins,
|
||||
staticDir: path.join(siteDir, STATIC_DIR_NAME),
|
||||
// Note that metadataPath must be the same/in-sync as
|
||||
// the path from createData for each MDX.
|
||||
isMDXPartial: createMatcher(options.exclude),
|
||||
metadataPath: (mdxPath: string) => {
|
||||
// Note that metadataPath must be the same/in-sync as
|
||||
// the path from createData for each MDX.
|
||||
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
||||
return path.join(
|
||||
dataDir,
|
||||
|
|
|
@ -12,6 +12,7 @@ import {
|
|||
AdmonitionsSchema,
|
||||
URISchema,
|
||||
} from '@docusaurus/utils-validation';
|
||||
import {GlobExcludeDefault} from '@docusaurus/utils';
|
||||
|
||||
export const DEFAULT_OPTIONS = {
|
||||
feedOptions: {type: ['rss', 'atom']},
|
||||
|
@ -32,6 +33,7 @@ export const DEFAULT_OPTIONS = {
|
|||
blogSidebarTitle: 'Recent posts',
|
||||
postsPerPage: 10,
|
||||
include: ['*.md', '*.mdx'],
|
||||
exclude: GlobExcludeDefault,
|
||||
routeBasePath: 'blog',
|
||||
path: 'blog',
|
||||
editLocalizedFiles: false,
|
||||
|
@ -44,6 +46,7 @@ export const PluginOptionSchema = Joi.object({
|
|||
// .allow('')
|
||||
.default(DEFAULT_OPTIONS.routeBasePath),
|
||||
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
|
||||
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
|
||||
postsPerPage: Joi.number()
|
||||
.integer()
|
||||
.min(1)
|
||||
|
|
|
@ -39,6 +39,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
|
|||
path: string;
|
||||
routeBasePath: string;
|
||||
include: string[];
|
||||
exclude: string[];
|
||||
postsPerPage: number;
|
||||
blogListComponent: string;
|
||||
blogPostComponent: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue