import { dedupeHead, isString, resolveLocalePath } from '@vuepress/shared' import { reactive } from 'vue' import { LANG_DEFAULT, LAYOUT_NAME_DEFAULT } from './constants.js' import type { ClientConfig, Layouts, PageData, PageFrontmatter, PageHead, PageHeadTitle, PageLang, PageLayout, RouteLocale, SiteData, SiteLocaleData, } from './types/index.js' /** * Resolver methods to get global computed * * Users can override corresponding method for advanced customization * * @experimental - This is an experimental API and may be changed in minor versions */ export const resolvers = reactive({ /** * Resolve layouts component map */ resolveLayouts: (clientConfigs: ClientConfig[]): Layouts => clientConfigs.reduce( (prev, item) => ({ ...prev, ...item.layouts, }), {}, ) as Layouts, /** * Merge the head config in frontmatter and site locale * * Frontmatter should take priority over site locale */ resolvePageHead: ( pageHeadTitle: PageHeadTitle, pageFrontmatter: PageFrontmatter, siteLocaleDate: SiteLocaleData, ): PageHead => { const description = isString(pageFrontmatter.description) ? pageFrontmatter.description : siteLocaleDate.description const head: PageHead = [ ...(Array.isArray(pageFrontmatter.head) ? pageFrontmatter.head : []), ...siteLocaleDate.head, ['title', {}, pageHeadTitle], ['meta', { name: 'description', content: description }], ] return dedupeHead(head) }, /** * Resolve the content of page head title * * It would be used as the content of the `