From 329049ec551805346be55e625b3323f2bac81e9b Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Thu, 11 Jul 2024 05:13:24 +0800 Subject: [PATCH] =?UTF-8?q?perf(theme):=20=E4=BC=98=E5=8C=96=20frontmatter?= =?UTF-8?q?=20=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../node/autoFrontmatter/resolveOptions.ts | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/theme/src/node/autoFrontmatter/resolveOptions.ts b/theme/src/node/autoFrontmatter/resolveOptions.ts index 37e1a25d2..ffd2d9f9e 100644 --- a/theme/src/node/autoFrontmatter/resolveOptions.ts +++ b/theme/src/node/autoFrontmatter/resolveOptions.ts @@ -2,7 +2,7 @@ import { path } from 'vuepress/utils' import { removeLeadingSlash, resolveLocalePath } from 'vuepress/shared' import { ensureLeadingSlash } from '@vuepress/helper' import { format } from 'date-fns' -import { uniq } from '@pengzhanbo/utils' +import { toArray, uniq } from '@pengzhanbo/utils' import type { AutoFrontmatter, AutoFrontmatterArray, @@ -194,6 +194,36 @@ export function resolveOptions( include: '**/{readme,README,index}.md', frontmatter: {}, }, + toArray(localeOptions.blog?.include).length + ? { + include: localeOptions.blog?.include, + frontmatter: { + ...options.title !== false + ? { + title(title: string, { relativePath }) { + if (title) + return title + const basename = path.basename(relativePath || '', '.md') + return basename + }, + } as AutoFrontmatterObject + : undefined, + ...baseFrontmatter, + ...options.permalink !== false + ? { + permalink(permalink: string, { relativePath }) { + if (permalink) + return permalink + const locale = resolveLocale(relativePath) + const prefix = withBase(articlePrefix, locale) + + return normalizePath(`${prefix}/${nanoid()}/`) + }, + } as AutoFrontmatterObject + : undefined, + }, + } + : '', { include: '*', frontmatter: { @@ -213,10 +243,7 @@ export function resolveOptions( permalink(permalink: string, { relativePath }) { if (permalink) return permalink - const locale = resolveLocale(relativePath) - const prefix = withBase(articlePrefix, locale) - - return normalizePath(`${prefix}/${nanoid()}/`) + return ensureLeadingSlash(normalizePath(relativePath.replace(/\.md$/, '/'))) }, } as AutoFrontmatterObject : undefined,