mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 16:17:25 +02:00
feat: make tags route path configurable (#5545)
This commit is contained in:
parent
ba402e9e63
commit
29e06d0677
11 changed files with 28 additions and 4 deletions
|
@ -52,6 +52,7 @@ describe('blogFeed', () => {
|
||||||
{
|
{
|
||||||
path: 'invalid-blog-path',
|
path: 'invalid-blog-path',
|
||||||
routeBasePath: 'blog',
|
routeBasePath: 'blog',
|
||||||
|
tagsBasePath: 'tags',
|
||||||
authorsMapPath: 'authors.yml',
|
authorsMapPath: 'authors.yml',
|
||||||
include: ['*.md', '*.mdx'],
|
include: ['*.md', '*.mdx'],
|
||||||
feedOptions: {
|
feedOptions: {
|
||||||
|
@ -86,6 +87,7 @@ describe('blogFeed', () => {
|
||||||
{
|
{
|
||||||
path: 'blog',
|
path: 'blog',
|
||||||
routeBasePath: 'blog',
|
routeBasePath: 'blog',
|
||||||
|
tagsBasePath: 'tags',
|
||||||
authorsMapPath: 'authors.yml',
|
authorsMapPath: 'authors.yml',
|
||||||
include: DEFAULT_OPTIONS.include,
|
include: DEFAULT_OPTIONS.include,
|
||||||
exclude: DEFAULT_OPTIONS.exclude,
|
exclude: DEFAULT_OPTIONS.exclude,
|
||||||
|
|
|
@ -183,7 +183,13 @@ async function processBlogSourceFile(
|
||||||
siteDir,
|
siteDir,
|
||||||
i18n,
|
i18n,
|
||||||
} = context;
|
} = context;
|
||||||
const {routeBasePath, truncateMarker, showReadingTime, editUrl} = options;
|
const {
|
||||||
|
routeBasePath,
|
||||||
|
tagsBasePath: tagsRouteBasePath,
|
||||||
|
truncateMarker,
|
||||||
|
showReadingTime,
|
||||||
|
editUrl,
|
||||||
|
} = options;
|
||||||
|
|
||||||
// Lookup in localized folder in priority
|
// Lookup in localized folder in priority
|
||||||
const blogDirPath = await getFolderContainingFile(
|
const blogDirPath = await getFolderContainingFile(
|
||||||
|
@ -267,7 +273,11 @@ async function processBlogSourceFile(
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagsBasePath = normalizeUrl([baseUrl, options.routeBasePath, 'tags']); // make this configurable?
|
const tagsBasePath = normalizeUrl([
|
||||||
|
baseUrl,
|
||||||
|
routeBasePath,
|
||||||
|
tagsRouteBasePath,
|
||||||
|
]);
|
||||||
const authors = getBlogPostAuthors({authorsMap, frontMatter});
|
const authors = getBlogPostAuthors({authorsMap, frontMatter});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -124,6 +124,7 @@ export default function pluginContentBlog(
|
||||||
const {
|
const {
|
||||||
postsPerPage: postsPerPageOption,
|
postsPerPage: postsPerPageOption,
|
||||||
routeBasePath,
|
routeBasePath,
|
||||||
|
tagsBasePath,
|
||||||
blogDescription,
|
blogDescription,
|
||||||
blogTitle,
|
blogTitle,
|
||||||
blogSidebarTitle,
|
blogSidebarTitle,
|
||||||
|
@ -201,7 +202,7 @@ export default function pluginContentBlog(
|
||||||
|
|
||||||
const blogTags: BlogTags = getBlogTags(blogPosts);
|
const blogTags: BlogTags = getBlogTags(blogPosts);
|
||||||
|
|
||||||
const tagsPath = normalizeUrl([baseBlogUrl, 'tags']);
|
const tagsPath = normalizeUrl([baseBlogUrl, tagsBasePath]);
|
||||||
|
|
||||||
const blogTagsListPath =
|
const blogTagsListPath =
|
||||||
Object.keys(blogTags).length > 0 ? tagsPath : null;
|
Object.keys(blogTags).length > 0 ? tagsPath : null;
|
||||||
|
|
|
@ -36,6 +36,7 @@ export const DEFAULT_OPTIONS: PluginOptions = {
|
||||||
include: ['**/*.{md,mdx}'],
|
include: ['**/*.{md,mdx}'],
|
||||||
exclude: GlobExcludeDefault,
|
exclude: GlobExcludeDefault,
|
||||||
routeBasePath: 'blog',
|
routeBasePath: 'blog',
|
||||||
|
tagsBasePath: 'tags',
|
||||||
archiveBasePath: 'archive',
|
archiveBasePath: 'archive',
|
||||||
path: 'blog',
|
path: 'blog',
|
||||||
editLocalizedFiles: false,
|
editLocalizedFiles: false,
|
||||||
|
@ -49,6 +50,7 @@ export const PluginOptionSchema = Joi.object<PluginOptions>({
|
||||||
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
||||||
// .allow('')
|
// .allow('')
|
||||||
.default(DEFAULT_OPTIONS.routeBasePath),
|
.default(DEFAULT_OPTIONS.routeBasePath),
|
||||||
|
tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
|
||||||
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
|
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
|
||||||
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
|
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
|
||||||
postsPerPage: Joi.alternatives()
|
postsPerPage: Joi.alternatives()
|
||||||
|
|
|
@ -35,6 +35,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
|
||||||
id?: string;
|
id?: string;
|
||||||
path: string;
|
path: string;
|
||||||
routeBasePath: string;
|
routeBasePath: string;
|
||||||
|
tagsBasePath: string;
|
||||||
archiveBasePath: string;
|
archiveBasePath: string;
|
||||||
include: string[];
|
include: string[];
|
||||||
exclude: string[];
|
exclude: string[];
|
||||||
|
|
|
@ -40,6 +40,7 @@ describe('normalizeDocsPluginOptions', () => {
|
||||||
const userOptions = {
|
const userOptions = {
|
||||||
path: 'my-docs', // Path to data on filesystem, relative to site dir.
|
path: 'my-docs', // Path to data on filesystem, relative to site dir.
|
||||||
routeBasePath: 'my-docs', // URL Route.
|
routeBasePath: 'my-docs', // URL Route.
|
||||||
|
tagsBasePath: 'tags', // URL Tags Route.
|
||||||
homePageId: 'home', // Document id for docs home page.
|
homePageId: 'home', // Document id for docs home page.
|
||||||
include: ['**/*.{md,mdx}'], // Extensions to include.
|
include: ['**/*.{md,mdx}'], // Extensions to include.
|
||||||
exclude: GlobExcludeDefault,
|
exclude: GlobExcludeDefault,
|
||||||
|
|
|
@ -26,6 +26,7 @@ import {
|
||||||
export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
|
export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id' | 'sidebarPath'> = {
|
||||||
path: 'docs', // Path to data on filesystem, relative to site dir.
|
path: 'docs', // Path to data on filesystem, relative to site dir.
|
||||||
routeBasePath: 'docs', // URL Route.
|
routeBasePath: 'docs', // URL Route.
|
||||||
|
tagsBasePath: 'tags', // URL Tags Route.
|
||||||
homePageId: undefined, // TODO remove soon, deprecated
|
homePageId: undefined, // TODO remove soon, deprecated
|
||||||
include: ['**/*.{md,mdx}'], // Extensions to include.
|
include: ['**/*.{md,mdx}'], // Extensions to include.
|
||||||
exclude: GlobExcludeDefault,
|
exclude: GlobExcludeDefault,
|
||||||
|
@ -73,6 +74,7 @@ export const OptionsSchema = Joi.object({
|
||||||
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
// '' not allowed, see https://github.com/facebook/docusaurus/issues/3374
|
||||||
// .allow('') ""
|
// .allow('') ""
|
||||||
.default(DEFAULT_OPTIONS.routeBasePath),
|
.default(DEFAULT_OPTIONS.routeBasePath),
|
||||||
|
tagsBasePath: Joi.string().default(DEFAULT_OPTIONS.tagsBasePath),
|
||||||
homePageId: Joi.string().optional(),
|
homePageId: Joi.string().optional(),
|
||||||
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
|
include: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.include),
|
||||||
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
|
exclude: Joi.array().items(Joi.string()).default(DEFAULT_OPTIONS.exclude),
|
||||||
|
|
|
@ -101,6 +101,7 @@ export type PluginOptions = MetadataOptions &
|
||||||
disableVersioning: boolean;
|
disableVersioning: boolean;
|
||||||
includeCurrentVersion: boolean;
|
includeCurrentVersion: boolean;
|
||||||
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
sidebarItemsGenerator: SidebarItemsGeneratorOption;
|
||||||
|
tagsBasePath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SidebarItemBase = {
|
export type SidebarItemBase = {
|
||||||
|
|
|
@ -349,6 +349,7 @@ function createVersionMetadata({
|
||||||
| 'path'
|
| 'path'
|
||||||
| 'sidebarPath'
|
| 'sidebarPath'
|
||||||
| 'routeBasePath'
|
| 'routeBasePath'
|
||||||
|
| 'tagsBasePath'
|
||||||
| 'versions'
|
| 'versions'
|
||||||
| 'editUrl'
|
| 'editUrl'
|
||||||
| 'editCurrentVersion'
|
| 'editCurrentVersion'
|
||||||
|
@ -400,7 +401,7 @@ function createVersionMetadata({
|
||||||
|
|
||||||
// the path that will be used to refer the docs tags
|
// the path that will be used to refer the docs tags
|
||||||
// example below will be using /docs/tags
|
// example below will be using /docs/tags
|
||||||
const tagsPath = normalizeUrl([versionPath, 'tags']);
|
const tagsPath = normalizeUrl([versionPath, options.tagsBasePath]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
versionName,
|
versionName,
|
||||||
|
@ -561,6 +562,7 @@ export function readVersionsMetadata({
|
||||||
| 'path'
|
| 'path'
|
||||||
| 'sidebarPath'
|
| 'sidebarPath'
|
||||||
| 'routeBasePath'
|
| 'routeBasePath'
|
||||||
|
| 'tagsBasePath'
|
||||||
| 'includeCurrentVersion'
|
| 'includeCurrentVersion'
|
||||||
| 'disableVersioning'
|
| 'disableVersioning'
|
||||||
| 'lastVersion'
|
| 'lastVersion'
|
||||||
|
|
|
@ -36,6 +36,7 @@ Accepted fields:
|
||||||
| `blogSidebarCount` | <code>number \| 'ALL'</code> | `5` | Number of blog post elements to show in the blog sidebar. `'ALL'` to show all blog posts; `0` to disable |
|
| `blogSidebarCount` | <code>number \| 'ALL'</code> | `5` | Number of blog post elements to show in the blog sidebar. `'ALL'` to show all blog posts; `0` to disable |
|
||||||
| `blogSidebarTitle` | `string` | `'Recent posts'` | Title of the blog sidebar. |
|
| `blogSidebarTitle` | `string` | `'Recent posts'` | Title of the blog sidebar. |
|
||||||
| `routeBasePath` | `string` | `'blog'` | URL route for the blog section of your site. **DO NOT** include a trailing slash. Use `/` to put the blog at root path. |
|
| `routeBasePath` | `string` | `'blog'` | URL route for the blog section of your site. **DO NOT** include a trailing slash. Use `/` to put the blog at root path. |
|
||||||
|
| `tagsBasePath` | `string` | `'tags'` | URL route for the tags list page of your site. It is prepended to the `routeBasePath`. |
|
||||||
| `archiveBasePath` | `string` | `'/archive'` | URL route for the archive blog section of your site. It is prepended to the `routeBasePath`. **DO NOT** include a trailing slash. |
|
| `archiveBasePath` | `string` | `'/archive'` | URL route for the archive blog section of your site. It is prepended to the `routeBasePath`. **DO NOT** include a trailing slash. |
|
||||||
| `include` | `string[]` | `['**/*.{md,mdx}']` | Matching files will be included and processed. |
|
| `include` | `string[]` | `['**/*.{md,mdx}']` | Matching files will be included and processed. |
|
||||||
| `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. |
|
| `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. |
|
||||||
|
|
|
@ -33,6 +33,7 @@ Accepted fields:
|
||||||
| `editLocalizedFiles` | `boolean` | `false` | The edit URL will target the localized file, instead of the original unlocalized file. Ignored when `editUrl` is a function. |
|
| `editLocalizedFiles` | `boolean` | `false` | The edit URL will target the localized file, instead of the original unlocalized file. Ignored when `editUrl` is a function. |
|
||||||
| `editCurrentVersion` | `boolean` | `false` | The edit URL will always target the current version doc instead of older versions. Ignored when `editUrl` is a function. |
|
| `editCurrentVersion` | `boolean` | `false` | The edit URL will always target the current version doc instead of older versions. Ignored when `editUrl` is a function. |
|
||||||
| `routeBasePath` | `string` | `'docs'` | URL route for the docs section of your site. **DO NOT** include a trailing slash. Use `/` for shipping docs without base path. |
|
| `routeBasePath` | `string` | `'docs'` | URL route for the docs section of your site. **DO NOT** include a trailing slash. Use `/` for shipping docs without base path. |
|
||||||
|
| `tagsBasePath` | `string` | `'tags'` | URL route for the tags list page of your site. It is prepended to the `routeBasePath`. |
|
||||||
| `include` | `string[]` | `['**/*.{md,mdx}']` | Matching files will be included and processed. |
|
| `include` | `string[]` | `['**/*.{md,mdx}']` | Matching files will be included and processed. |
|
||||||
| `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. |
|
| `exclude` | `string[]` | _See example configuration_ | No route will be created for matching files. |
|
||||||
| `sidebarPath` | <code>false \| string</code> | `undefined` (creates autogenerated sidebar) | Path to sidebar configuration. |
|
| `sidebarPath` | <code>false \| string</code> | `undefined` (creates autogenerated sidebar) | Path to sidebar configuration. |
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue