Skip to content

Commit

Permalink
fix: allow template params to be overidden by nuxt.config
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Nov 3, 2023
1 parent e5ff264 commit 5583d6e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ export default defineNuxtConfig({
name: 'SEO Experiments',
tagline: 'test',
debug: true,
titleSeparator: 'l',
},

app: {
seoMeta: {
description: 'Hi, welcome to the %envName v%app.version of %siteName.',
},
head: {
templateParams: {
separator: 'x',
},
title: '%site.tagline',
// DEV - My page title - My cool site
titleTemplate: '%s %separator %site.name',
Expand All @@ -32,7 +36,6 @@ export default defineNuxtConfig({
app: {
version: '1.3.4',
},
titleSeparator: '|',
envName: process.env.NODE_ENV === 'development' ? 'dev' : 'live',
},
},
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/plugins/siteConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ export default defineNuxtPlugin(() => {
const siteConfig = { ...useSiteConfig() } as Record<string, any>
delete siteConfig._context

const separator = siteConfig.separator || siteConfig.titleSeparator
const input: Head = {
meta: [],
templateParams: {
site: siteConfig,
separator,
titleSeparator: separator,
// support legacy
siteUrl: siteConfig.url,
siteName: siteConfig.name,
},
}
if (siteConfig.separator)
input.templateParams!.separator = siteConfig.separator
if (siteConfig.titleSeparator)
input.templateParams!.titleSeparator = siteConfig.titleSeparator
if (siteConfig.description) {
input.templateParams!.siteDescription = siteConfig.description
// we can setup a meta description
Expand All @@ -33,5 +34,5 @@ export default defineNuxtPlugin(() => {
},
)
}
head.push(input)
head.push(input, { tagPriority: 150 })
})

0 comments on commit 5583d6e

Please sign in to comment.