From 353a12537b72795e36d3ab9b772af0563d7099f4 Mon Sep 17 00:00:00 2001 From: markshawn2020 Date: Tue, 6 Sep 2022 20:11:51 +0800 Subject: [PATCH] enhance: fallback sidebar title to dirname if index/readme --- packages/docusaurus-plugin-content-docs/src/docs.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-plugin-content-docs/src/docs.ts b/packages/docusaurus-plugin-content-docs/src/docs.ts index 7d13e40eb8..fa75db354c 100644 --- a/packages/docusaurus-plugin-content-docs/src/docs.ts +++ b/packages/docusaurus-plugin-content-docs/src/docs.ts @@ -238,7 +238,12 @@ async function doProcessDocMetadata({ // Note: the title is used by default for page title, sidebar label, // pagination buttons... frontMatter.title should be used in priority over // contentTitle (because it can contain markdown/JSX syntax) - const title: string = frontMatter.title ?? contentTitle ?? baseID; + // if filename is `index` or `readme`, then use the parent directory name + const derivedNameFromPath = /^(?:index|readme)$/i.test(baseID) + ? path.basename(sourceDirName) + : unprefixedFileName; + const title: string = + frontMatter.title ?? contentTitle ?? derivedNameFromPath; const description: string = frontMatter.description ?? excerpt ?? '';