Skip to content

Commit

Permalink
fix: add SeoKit props for more flexible runtime overrides
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
harlan-zw committed Feb 2, 2023
1 parent 4d9e509 commit c89a90d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

</div>
<div>
<SeoKit />
<SeoKit :site-description="'test'" />
</div>
<div>
<NuxtPage />
Expand Down
39 changes: 27 additions & 12 deletions layer/components/SeoKit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ import { resolveAbsoluteInternalLink } from '../composables/internalLinks'
import { useAppConfig, useRuntimeConfig } from '#app'
import * as config from '#nuxt-seo-kit/config'
interface SeoKitOptions {
siteUrl?: string
siteName?: string
siteDescription?: string
siteImage?: string
indexable?: boolean
titleSeparator?: string
trailingSlash?: boolean
language?: string
}
const props = defineProps<{
siteUrl?: string
siteName?: string
siteDescription?: string
siteImage?: string
titleSeparator?: string
language?: string
}>()
const runtimeConfig = useRuntimeConfig().public
const appConfig = useAppConfig()
Expand All @@ -18,31 +38,26 @@ const SeoKitPublicRuntimeConfigKeys = [
'language',
] as const
interface SeoKitOptions {
siteUrl: string
siteName: string
siteDescription: string
siteImage: string
indexable: boolean
titleSeparator: string
trailingSlash: boolean
language: string
}
const siteMeta = computed<SeoKitOptions>(() => {
const runtimeConfigExtract = {}
for (const k of SeoKitPublicRuntimeConfigKeys) {
if (runtimeConfig[k])
// @ts-expect-error untyped
runtimeConfigExtract[k] = runtimeConfig[k]
}
const propExtract = {}
for (const k of SeoKitPublicRuntimeConfigKeys) {
if (props[k])
// @ts-expect-error untyped
propExtract[k] = props[k]
}
return {
...config,
...runtimeConfigExtract,
// app config has the highest priority
// @ts-expect-error untyped
...appConfig.site,
...propExtract,
}
})
Expand Down

0 comments on commit c89a90d

Please sign in to comment.