Skip to content

Commit

Permalink
perf(theme): 优化分类、标签计算逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Mar 8, 2024
1 parent ee30acb commit f2860d9
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion theme/src/client/composables/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]] ?? [],
}))
})

Expand Down
2 changes: 2 additions & 0 deletions theme/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions theme/src/node/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -183,7 +193,6 @@ export function setupPlugins(
align: true,
mark: true,
tasklist: true,
demo: true,
attrs: true,
sup: true,
sub: true,
Expand All @@ -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 }))

Expand Down
12 changes: 9 additions & 3 deletions theme/src/node/setupPages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions theme/src/shared/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==================================== */
Expand Down

0 comments on commit f2860d9

Please sign in to comment.