enhance: fallback sidebar title to dirname if index/readme

This commit is contained in:
markshawn2020 2022-09-06 20:11:51 +08:00
parent 36db64ed1d
commit 353a12537b

View file

@ -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 ?? '';