@@ -20,16 +20,32 @@ export interface ModuleOptions {
2020 * @default false
2121 */
2222 client ?: boolean
23-
2423 /**
2524 * Should full schema types from `schema-dts` be used over a simplified version.
25+ *
2626 * @default false
2727 */
2828 full ?: boolean
2929 /**
30- * Metadata for the schema.org generation
30+ * Extra default metadata for the schema.org generation, you can use this as an alternative to the other meta.
3131 */
3232 meta ?: MetaInput
33+ /**
34+ * The production URL of your site. This allows the client to generate all URLs for you and is important to set correctly.
35+ */
36+ canonicalHost ?: `https://${string } `
37+ /**
38+ * Will set the `isLanguage` to this value for any Schema which uses it. Should be a valid language code, i.e `en-AU`
39+ */
40+ defaultLanguage ?: string
41+ /**
42+ * Will set the `priceCurrency` for [Product](/schema/product) Offer Schema. Should be a valid currency code, i.e `AUD`
43+ */
44+ defaultCurrency ?: string
45+ /**
46+ * @deprecated You can remove this option, it doesn't do anything now.
47+ */
48+ debug ?: boolean
3349}
3450
3551export interface ModuleHooks {
@@ -49,12 +65,29 @@ export default defineNuxtModule<ModuleOptions>({
4965 async setup ( moduleOptions , nuxt ) {
5066 const { resolve, resolvePath } = createResolver ( import . meta. url )
5167
68+ moduleOptions . meta = moduleOptions . meta || { } as MetaInput
69+ if ( ! moduleOptions . meta . host && moduleOptions . canonicalHost )
70+ moduleOptions . meta . host = moduleOptions . canonicalHost
71+ if ( ! moduleOptions . meta . inLanguage && moduleOptions . defaultLanguage )
72+ moduleOptions . meta . inLanguage = moduleOptions . canonicalHost
73+ if ( ! moduleOptions . meta . currency && moduleOptions . defaultCurrency )
74+ moduleOptions . meta . currency = moduleOptions . canonicalHost
75+
76+ // spa we can read the window.origin as a fallback
77+ if ( nuxt . options . ssr && ! moduleOptions . canonicalHost && ! moduleOptions . meta ?. host ) {
78+ console . warn ( 'WARN [nuxt-schema-org] Please provide a `canonicalHost` to use this module with SSR enabled.' )
79+ return
80+ }
81+
5282 // avoid unwanted behavior with different package managers
5383 const schemaOrgPath = dirname ( await resolvePath ( Pkg ) )
5484
5585 const moduleRuntimeDir = resolve ( './runtime' )
5686 nuxt . options . build . transpile . push ( ...[ moduleRuntimeDir , AliasRuntime ] )
5787
88+ // if ssr is disabled we need to inject the client
89+ if ( ! nuxt . options . ssr )
90+ moduleOptions . client = true
5891 // enable client in dev mode
5992 if ( typeof moduleOptions . client === 'undefined' )
6093 moduleOptions . client = ! ! nuxt . options . dev
0 commit comments