feat: make tags route path configurable (#5545)

This commit is contained in:
Alexey Pyltsyn 2021-09-21 20:19:18 +03:00 committed by GitHub
parent ba402e9e63
commit 29e06d0677
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 4 deletions

View file

@ -52,6 +52,7 @@ describe('blogFeed', () => {
{
path: 'invalid-blog-path',
routeBasePath: 'blog',
tagsBasePath: 'tags',
authorsMapPath: 'authors.yml',
include: ['*.md', '*.mdx'],
feedOptions: {
@ -86,6 +87,7 @@ describe('blogFeed', () => {
{
path: 'blog',
routeBasePath: 'blog',
tagsBasePath: 'tags',
authorsMapPath: 'authors.yml',
include: DEFAULT_OPTIONS.include,
exclude: DEFAULT_OPTIONS.exclude,

View file

@ -183,7 +183,13 @@ async function processBlogSourceFile(
siteDir,
i18n,
} = context;
const {routeBasePath, truncateMarker, showReadingTime, editUrl} = options;
const {
routeBasePath,
tagsBasePath: tagsRouteBasePath,
truncateMarker,
showReadingTime,
editUrl,
} = options;
// Lookup in localized folder in priority
const blogDirPath = await getFolderContainingFile(
@ -267,7 +273,11 @@ async function processBlogSourceFile(
return undefined;
}
const tagsBasePath = normalizeUrl([baseUrl, options.routeBasePath, 'tags']); // make this configurable?
const tagsBasePath = normalizeUrl([
baseUrl,
routeBasePath,
tagsRouteBasePath,
]);
const authors = getBlogPostAuthors({authorsMap, frontMatter});
return {

View file

@ -124,6 +124,7 @@ export default function pluginContentBlog(
const {
postsPerPage: postsPerPageOption,
routeBasePath,
tagsBasePath,
blogDescription,
blogTitle,
blogSidebarTitle,
@ -201,7 +202,7 @@ export default function pluginContentBlog(
const blogTags: BlogTags = getBlogTags(blogPosts);
const tagsPath = normalizeUrl([baseBlogUrl, 'tags']);
const tagsPath = normalizeUrl([baseBlogUrl, tagsBasePath]);
const blogTagsListPath =
Object.keys(blogTags).length > 0 ? tagsPath : null;

View file

@ -36,6 +36,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
include: ['**/*.{md,mdx}'],
exclude: GlobExcludeDefault,
routeBasePath: 'blog',
tagsBasePath: 'tags',
archiveBasePath: 'archive',
path: 'blog',
editLocalizedFiles: false,
@ -49,6 +50,7 @@ export const PluginOptionSchema = Joi.object<PluginOptions>({
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
// .allow('')
.default(DEFAULT_OPTIONS.routeBasePath),
tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
postsPerPage: Joi.alternatives()

View file

@ -35,6 +35,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
id?: string;
path: string;
routeBasePath: string;
tagsBasePath: string;
archiveBasePath: string;
include: string[];
exclude: string[];