Skip to content

Commit

Permalink
fix(content): avoid parsing invalid videos in markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Jan 19, 2025
1 parent 213e987 commit 93b7396
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/runtime/server/plugins/nuxt-content-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSimpleSitemapRuntimeConfig } from '../utils'
import { defineNitroPlugin } from '#imports'

export default defineNitroPlugin((nitroApp: NitroApp) => {
const { discoverImages, discoverVideos, isNuxtContentDocumentDriven } = useSimpleSitemapRuntimeConfig()
const { discoverImages, isNuxtContentDocumentDriven } = useSimpleSitemapRuntimeConfig()
// @ts-expect-error untyped
nitroApp.hooks.hook('content:file:afterParse', async (content: ParsedContent) => {
const validExtensions = ['md', 'mdx']
Expand All @@ -23,27 +23,15 @@ export default defineNitroPlugin((nitroApp: NitroApp) => {
.map(i => ({ loc: i.props!.src })) || [])
}

// add any top level videos
let videos: SitemapUrl['videos'] = []
if (discoverVideos) {
videos = (content.body?.children
?.filter(c =>
c.tag && c.props?.src && ['video'].includes(c.tag.toLowerCase()),
)
.map(i => ({ content_loc: i.props!.src })) || [])
}

const sitemapConfig = typeof content.sitemap === 'object' ? content.sitemap : {}
const lastmod = content.modifiedAt || content.updatedAt
const defaults: Partial<SitemapUrl> = {}
if (isNuxtContentDocumentDriven)
defaults.loc = content._path
if (content.path) // automatically set when document driven
defaults.loc = content.path
if (images.length > 0)
if (images?.length)
defaults.images = images
if (videos.length > 0)
defaults.videos = videos
if (lastmod)
defaults.lastmod = lastmod
const definition = defu(sitemapConfig, defaults) as Partial<SitemapUrl>
Expand Down

0 comments on commit 93b7396

Please sign in to comment.