Skip to content

Commit

Permalink
perf(theme): improve bulletin enablePage (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo authored Jan 21, 2025
1 parent 93a3da2 commit 8b9c50b
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions theme/src/node/pages/pageBulletin.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import type { Page } from 'vuepress/core'
import type { BulletinOptions, PlumeThemeLocaleOptions, PlumeThemePageData } from '../../shared/index.js'
import { isPlainObject } from '@vuepress/helper'
import type { PlumeThemeLocaleOptions, PlumeThemePageData } from '../../shared/index.js'
import { isFunction, isPlainObject } from '@vuepress/helper'

export function enableBulletin(
page: Page<PlumeThemePageData>,
options: PlumeThemeLocaleOptions,
) {
let enablePage: BulletinOptions['enablePage']
if (isPlainObject(options.bulletin) && options.bulletin.enablePage) {
enablePage = options.bulletin.enablePage
}
else if (options.locales) {
for (const locale of Object.keys(options.locales)) {
if (isPlainObject(options.locales[locale].bulletin) && options.locales[locale].bulletin.enablePage) {
enablePage = options.locales[locale].bulletin.enablePage
break
}
}
if (isPlainObject(options.bulletin)) {
const enablePage = options.bulletin.enablePage
page.data.bulletin = (isFunction(enablePage) ? enablePage(page) : enablePage) ?? true
}

if (typeof enablePage === 'function') {
page.data.bulletin = enablePage(page) ?? true
}

else {
page.data.bulletin = enablePage ?? !!options.bulletin
if (options.locales?.[page.pathLocale]) {
const bulletin = options.locales?.[page.pathLocale].bulletin
if (isPlainObject(bulletin)) {
const enablePage = bulletin.enablePage
page.data.bulletin = (isFunction(enablePage) ? enablePage(page) : enablePage) ?? true
}
}
}

0 comments on commit 8b9c50b

Please sign in to comment.