Skip to content

Commit

Permalink
fix: require hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Dec 13, 2022
1 parent 0674a18 commit 718ac65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export default defineNuxtConfig({
]
}
},
sitemap: {
hostname: 'https://example.com',
},
routeRules: {
'/secret': { index: false },
'/about': { sitemap: { changefreq: 'daily', priority: 0.3 } }
Expand Down
6 changes: 4 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export default defineNuxtModule<ModuleOptions>({
}
},
setup(config, nuxt) {
// make sure a hostname is set so we can generate the sitemap
config.hostname = config.hostname || 'https://example.com'
const { resolve } = createResolver(import.meta.url)

// paths.d.ts
Expand Down Expand Up @@ -86,6 +84,10 @@ declare module 'nitropack' {
nuxt.hooks.hook('nitro:init', async (nitro: Nitro) => {
// tell the user if the sitemap isn't being generated
const logger = useLogger('nuxt-simple-sitemap')
if (!config.hostname) {
logger.warn('Please set a `hostname` in your `sitemap` config to use `nuxt-simple-sitemap`.')
return
}
if (!config.enabled) {
logger.warn('Sitemap generation is disabled. Set `sitemap.enabled` to `true` to enable it.')
return
Expand Down

0 comments on commit 718ac65

Please sign in to comment.