Skip to content

Commit

Permalink
perf(theme): 优化 frontmatter 自动生成
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Jul 10, 2024
1 parent b92135e commit 329049e
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions theme/src/node/autoFrontmatter/resolveOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
Expand Down

0 comments on commit 329049e

Please sign in to comment.