perf(theme): 优化分类、标签计算逻辑

This commit is contained in:
pengzhanbo 2024-03-09 00:35:25 +08:00
parent ee30acbc15
commit f2860d96da
5 changed files with 24 additions and 10 deletions

View File

@ -197,7 +197,7 @@ export function useTags() {
return Object.keys(tagMap).map(tag => ({
name: tag,
count: tagMap[tag] > 99 ? '99+' : tagMap[tag],
colors: extraData.value.tagsColorsPreset[extraData.value.tagsColors[tag]],
colors: extraData.value.tagsColorsPreset[extraData.value.tagsColors[tag]] ?? [],
}))
})

View File

@ -5,6 +5,8 @@ export { default as plumeClientConfig } from './config.js'
export { default as Layout } from './layouts/Layout.vue'
export { default as NotFound } from './layouts/NotFound.vue'
export { default as HomeBox } from './components/Home/HomeBox.vue'
export {
useDarkMode,
useThemeData,

View File

@ -107,8 +107,18 @@ export function setupPlugins(
...customContainers,
]
if (options.readingTime !== false)
plugins.push(readingTimePlugin(options.readingTime || {}))
if (options.readingTime !== false) {
plugins.push(readingTimePlugin({
locales: {
'/zh/': {
word: '$word字',
less1Minute: '小于1分钟',
time: '大约$time分钟',
},
},
...options.readingTime,
}))
}
if (options.nprogress !== false)
plugins.push(nprogressPlugin())
@ -183,7 +193,6 @@ export function setupPlugins(
align: true,
mark: true,
tasklist: true,
demo: true,
attrs: true,
sup: true,
sub: true,
@ -203,7 +212,6 @@ export function setupPlugins(
plugins.push(baiduTongjiPlugin(options.baiduTongji))
const hostname = resolveLocaleOptions(localeOptions, 'hostname')
if (options.sitemap !== false && hostname && isProd)
plugins.push(sitemapPlugin({ hostname }))

View File

@ -80,14 +80,20 @@ export function autoCategory(
options: PlumeThemeLocaleOptions,
) {
const pagePath = page.filePathRelative
if (page.frontmatter.type || !pagePath)
return
const locales = Object.keys(resolvedAppLocales(app))
const notesLinks: string[] = []
for (const [, locale] of locales.entries()) {
const notes = options.locales?.[locale]?.notes
if (notes && notes.link)
notesLinks.push(path.join(locale, notes.link).replace(/\\+/g, '/'))
const config = options.locales?.[locale]?.notes
if (config && config.notes) {
notesLinks.push(
...config.notes.map(
note => path.join(locale, config.link || '', note.link).replace(/\\+/g, '/'),
),
)
}
}
if (notesLinks.some(link => page.path.startsWith(link)))
return

View File

@ -95,8 +95,6 @@ export interface PlumeThemeHomeProfile extends PlumeHomeConfigBase {
export interface PlumeThemeHomeCustom extends PlumeHomeConfigBase {
type: 'custom'
backgroundImage?: string | { light: string, dark: string }
backgroundAttachment?: 'fixed' | 'local'
}
/* =============================== Home end ==================================== */