Skip to content

Commit

Permalink
fix: support nuxt/content sitemap yaml key
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jul 7, 2023
1 parent 86b4e4f commit 0a3ed79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .playground/content/foo.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
---
sitemap:
priority: 0.5
---

# foo
5 changes: 3 additions & 2 deletions src/runtime/plugins/nuxt-content.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { NitroAppPlugin } from 'nitropack'
import { prefixStorage } from 'unstorage'
import { defu } from 'defu'
import type { ModuleRuntimeConfig } from '../types'
import { useRuntimeConfig, useStorage } from '#imports'

export const NuxtContentSimpleSitemapPlugin: NitroAppPlugin = (nitroApp) => {
const { moduleConfig } = useRuntimeConfig()['nuxt-simple-sitemap'] as any as ModuleRuntimeConfig
const contentStorage = prefixStorage(useStorage(), 'content:source')
nitroApp.hooks.hook('content:file:afterParse', async (content) => {
if (content._extension !== 'md')
if (content._extension !== 'md' || content.sitemap === false || content.indexable === false)
return
// add any top level images
let images = []
Expand All @@ -24,7 +25,7 @@ export const NuxtContentSimpleSitemapPlugin: NitroAppPlugin = (nitroApp) => {
const meta = await contentStorage.getMeta(content._id)
lastmod = content.modifiedAt || meta?.mtime
}
content._sitemap = { loc: content._path, lastmod, images }
content.sitemap = defu(content.sitemap, { loc: content._path, lastmod, images })
return content
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/routes/document-driven-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { serverQueryContent } from '#content/server'

export default defineEventHandler(async (e) => {
const contentList = await serverQueryContent(e).find()
return contentList.map(c => c._sitemap).filter(Boolean)
return contentList.map(c => c.sitemap).filter(Boolean)
})

0 comments on commit 0a3ed79

Please sign in to comment.