Skip to content

Commit

Permalink
feat(vitepress, vitesse): support legacy user config
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Aug 18, 2022
1 parent a972d1b commit 71162ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions packages/vite/src/vitepress.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { createSchemaOrg } from '@vueuse/schema-org'
import { createSchemaOrg, resolveUserConfig } from '@vueuse/schema-org'
import type { EnhanceAppContext } from 'vitepress'
import { createHead } from '@vueuse/head'
import { watch } from 'vue'
import type { MetaInput } from './'
import type { UserConfig } from '@vueuse/schema-org'

export function installSchemaOrg(ctx: EnhanceAppContext, config: UserConfig) {
const resolvedConfig = resolveUserConfig(config)

export function installSchemaOrg(ctx: EnhanceAppContext, meta: MetaInput) {
// check if `createHead` has already been done
let head = ctx.app._context.provides.usehead
if (!head) {
Expand All @@ -19,7 +21,7 @@ export function installSchemaOrg(ctx: EnhanceAppContext, meta: MetaInput) {
...ctx.siteData.value,
...ctx.router.route.data,
...ctx.router.route.data.frontmatter,
...meta,
...resolvedConfig.meta,
}
},
updateHead(fn) {
Expand Down
10 changes: 6 additions & 4 deletions packages/vite/src/vitesse.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { createSchemaOrg } from '@vueuse/schema-org'
import { createSchemaOrg, resolveUserConfig } from '@vueuse/schema-org'
import type { ViteSSGContext } from 'vite-ssg'
import type { MetaInput } from './'
import type { UserConfig } from '@vueuse/schema-org'

export function installSchemaOrg(ctx: ViteSSGContext, meta: MetaInput) {
export function installSchemaOrg(ctx: ViteSSGContext, config: UserConfig) {
const ssr = !ctx.isClient

const resolvedConfig = resolveUserConfig(config)

const client = createSchemaOrg({
updateHead(fn) {
ctx.head?.addHeadObjs(fn)
Expand All @@ -23,7 +25,7 @@ export function installSchemaOrg(ctx: ViteSSGContext, meta: MetaInput) {

return {
path: ctx.router.currentRoute.value.path,
...meta ?? {},
...resolvedConfig.meta,
...ctx.router.currentRoute.value.meta,
}
},
Expand Down

0 comments on commit 71162ca

Please sign in to comment.