-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(theme): improve bulletin
enablePage
(#438)
- Loading branch information
1 parent
93a3da2
commit 8b9c50b
Showing
1 changed file
with
11 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |