Skip to content

Commit

Permalink
fix: prefer defu for option merging
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jan 26, 2023
1 parent 20056c8 commit 874df5a
Showing 1 changed file with 27 additions and 46 deletions.
73 changes: 27 additions & 46 deletions modules/nuxt-seo-kit/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,55 +52,36 @@ export default defineNuxtModule<ModuleOptions>({
async setup(config, nuxt) {
const { resolve } = createResolver(import.meta.url)

nuxt.options.head = nuxt.options.head || {}
nuxt.options.head.ogTitleTemplate = nuxt.options.head.ogTitleTemplate || `%s ${config.titleSeparator} ${config.siteName}`

// configure nuxt-unhead
nuxt.options.unhead = defu(nuxt.options.unhead || {}, {
ogTitleTemplate: `%s ${config.titleSeparator} ${config.siteName}`,
})
// configure nuxt-simple-sitemap
nuxt.options.sitemap = nuxt.options.sitemap || {}
nuxt.options.sitemap.hostname = config.siteUrl
nuxt.options.sitemap.trailingSlash = config.trailingSlash

nuxt.options.sitemap = defu(nuxt.options.sitemap || {}, {
hostname: config.siteUrl,
trailingSlash: config.trailingSlash,
})
// configure nuxt-schema-org
nuxt.options.schemaOrg = nuxt.options.schemaOrg || {}
nuxt.options.schemaOrg.host = config.siteUrl
nuxt.options.schemaOrg.inLanguage = config.language

nuxt.options.ogImage = nuxt.options.ogImage || {}
nuxt.options.ogImage.host = config.siteUrl

nuxt.options.linkChecker = nuxt.options.linkChecker || {}
nuxt.options.linkChecker.host = config.siteUrl
nuxt.options.linkChecker.trailingSlash = config.trailingSlash

nuxt.options.robots = nuxt.options.robots || {}
nuxt.options.robots.indexable = config.indexable

nuxt.options.robots.sitemap = [
withBase('/sitemap.xml', config.siteUrl),
]

addTemplate({
filename: 'nuxt-seo-kit.d.ts',
getContents: () => {
return `// Generated by nuxt-seo-kit
declare module '#nuxt-seo-kit/config' {
const config : {
siteUrl: string
siteName: string
siteDescription: string
indexable: boolean
titleSeparator: string
trailingSlash: boolean
language: string
}
export default config
}
`
},
nuxt.options.schemaOrg = defu(nuxt.options.schemaOrg || {}, {
host: config.siteUrl,
inLanguage: config.language,
trailingSlash: config.trailingSlash,
})

nuxt.hooks.hook('prepare:types', ({ references }) => {
references.push({ path: resolve(nuxt.options.buildDir, 'nuxt-seo-kit.d.ts') })
// configure nuxt-og-image
nuxt.options.ogImage = defu(nuxt.options.ogImage || {}, {
host: config.siteUrl,
})
// configure nuxt-link-checker
nuxt.options.linkChecker = defu(nuxt.options.linkChecker || {}, {
host: config.siteUrl,
trailingSlash: config.trailingSlash,
})
// configure nuxt-simple-robots
nuxt.options.robots = defu(nuxt.options.robots || {}, {
indexable: config.indexable,
sitemap: [
withBase('/sitemap.xml', config.siteUrl),
],
})

nuxt.options.build.transpile.push(...[
Expand Down

0 comments on commit 874df5a

Please sign in to comment.