Skip to content

Commit

Permalink
fix: handle malformed og image paths
Browse files Browse the repository at this point in the history
Fixes #294
  • Loading branch information
harlan-zw committed Dec 23, 2024
1 parent bbf3fac commit 4bd7405
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/runtime/app/utils/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ export function ogImageCanonicalUrls(nuxtApp: NuxtApp) {

for (const tag of ctx.tags) {
if (tag.tag === 'meta' && (tag.props.property === 'og:image' || ['twitter:image:src', 'twitter:image'].includes(tag.props.name))) {
if (!tag.props.content) {
tag.props = {} // equivalent to removing
continue
}
// looking for:
// property og:image
// property twitter:image:src
if (!tag.props.content.startsWith('https')) {
if (!tag.props.content?.startsWith('https')) {
await nuxtApp.runWithContext(() => {
tag.props.content = toValue(withSiteUrl(tag.props.content, {
withBase: true,
Expand Down

0 comments on commit 4bd7405

Please sign in to comment.