Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use property attribute for OpenGraph title and image #3213

Merged
merged 19 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading