Skip to content

Commit

Permalink
fix(addons): InferSeoMetaPlugin adding og:title to body
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Sep 10, 2023
1 parent f82bd9e commit e1a60c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions packages/addons/src/plugins/inferSeoMetaPlugin.ts
Expand Up @@ -44,15 +44,16 @@ export interface InferSeoMetaPluginOptions {
const title = input.title
const description = resolvedMeta.find(meta => meta.name === 'description')?.content

const hasOgTitle = !!resolvedMeta.find(meta => meta.property === 'og:title')
const hasOgImage = !!resolvedMeta.find(meta => meta.property === 'og:image')
const hasTwitterCard = !!resolvedMeta.find(meta => meta.name === 'twitter:card')
const hasOgDescription = !!resolvedMeta.find(meta => meta.property === 'og:description')
const hasOgTitle = resolvedMeta.some(meta => meta.property === 'og:title')
const hasOgImage = resolvedMeta.some(meta => meta.property === 'og:image')
const hasTwitterCard = resolvedMeta.some(meta => meta.name === 'twitter:card')
const hasOgDescription = resolvedMeta.some(meta => meta.property === 'og:description')

// ensure meta exists
entry[inputKey].meta = input.meta || []
if (titleTemplate && !hasOgTitle) {
let newOgTitle = options?.ogTitle || titleTemplate
// entry must contain a title or titleTemplate
if (!hasOgTitle && (input.titleTemplate || input.title)) {
let newOgTitle = options?.ogTitle || titleTemplate || input.title
if (typeof newOgTitle === 'function')
newOgTitle = newOgTitle(title)

Expand Down
2 changes: 1 addition & 1 deletion test/unhead/hooks/infer-seo-meta.test.ts
Expand Up @@ -3,7 +3,7 @@ import { InferSeoMetaPlugin } from '@unhead/addons'
import { useDOMHead, useDelayedSerializedDom } from '../dom/util'

describe('hooks', () => {
it('delay dom', async () => {
it('infer-seo-meta', async () => {
const head = useDOMHead({
plugins: [
InferSeoMetaPlugin(),
Expand Down

0 comments on commit e1a60c2

Please sign in to comment.