Skip to content

Commit

Permalink
Use property attribute for OpenGraph title and image (#3213)
Browse files Browse the repository at this point in the history
Co-authored-by: Olga Bulat <[email protected]>
  • Loading branch information
obiwanpelosi and obulat authored Oct 24, 2023
1 parent 75f85ed commit 0987949
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frontend/src/constants/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const meta = [
name: "description",
content: DESCRIPTION,
},
{ hid: "og:title", name: "og:title", content: "Openverse" },
{ hid: "og:title", property: "og:title", content: "Openverse" },
{
hid: "og:image",
name: "og:image",
property: "og:image",
content: "/openverse-default.jpg",
},
{
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/utils/og.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { MetaInfo } from "vue-meta"
import type { MetaPropertyName } from "vue-meta/types/vue-meta"
import type {
MetaPropertyName,
MetaPropertyProperty,
} from "vue-meta/types/vue-meta"

export const createDetailPageMeta = ({
title,
Expand All @@ -18,18 +21,18 @@ export const createDetailPageMeta = ({
name: "robots",
content: "noindex",
},
] as MetaPropertyName[]
] as (MetaPropertyName | MetaPropertyProperty)[]
if (title) {
meta.push({
hid: "og:title",
name: "og:title",
property: "og:title",
content: title,
})
}
if (thumbnail && !isSensitive) {
meta.push({
hid: "og:image",
name: "og:image",
property: "og:image",
content: thumbnail,
})
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/test/playwright/e2e/seo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ test.describe("Page metadata", () => {
const metaRobots = page.locator('meta[name="robots"]')
await expect(metaRobots).toHaveAttribute("content", openversePage.robots)

const metaOgImage = page.locator('meta[name="og:image"]')
const metaOgImage = page.locator('meta[property="og:image"]')
await expect(metaOgImage).toHaveAttribute(
"content",
openversePage.ogImage
)

const metaOgTitle = page.locator('meta[name="og:title"]')
const metaOgTitle = page.locator('meta[property="og:title"]')
await expect(metaOgTitle).toHaveAttribute(
"content",
openversePage.ogTitle
Expand Down

0 comments on commit 0987949

Please sign in to comment.