Skip to content

Commit e67d2e5

Browse files
authored
Merge pull request #12234 from ethereum/og-images
Fix OG page images
2 parents 3ff7c30 + 25ab899 commit e67d2e5

File tree

20 files changed

+64
-44
lines changed

20 files changed

+64
-44
lines changed

public/content/roadmap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Ethereum roadmap
33
description: The path to more scalability, security and sustainability for Ethereum.
44
lang: en
55
template: roadmap
6-
image: /roadmap/roadmap-main.png
6+
image: /heroes/roadmap-hub-hero.jpg
77
alt: "Ethereum roadmap"
88
summaryPoints:
99
buttons:

public/content/translations/id/roadmap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Peta Perjalanan Ethereum
33
description: Jalan menuju peningkatan skalabilitas, keamanan, dan keberlanjutan Ethereum.
44
lang: id
55
template: roadmap
6-
image: /roadmap/roadmap-main.png
6+
image: /heroes/roadmap-hub-hero.jpg
77
alt: "Peta Perjalanan Ethereum"
88
summaryPoints:
99
buttons:

public/content/translations/it/roadmap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Roadmap di Ethereum
33
description: Il percorso verso una maggiore scalabilità, sicurezza e sostenibilità per Ethereum.
44
lang: it
55
template: roadmap
6-
image: /roadmap/roadmap-main.png
6+
image: /heroes/roadmap-hub-hero.jpg
77
alt: "Roadmap di Ethereum"
88
summaryPoints:
99
buttons:

public/content/translations/ru/roadmap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Дорожная карта Ethereum
33
description: Путь к большей масштабируемости, безопасности и экологичности Ethereum.
44
lang: ru
55
template: roadmap
6-
image: /roadmap/roadmap-main.png
6+
image: /heroes/roadmap-hub-hero.jpg
77
alt: "Дорожная карта Ethereum"
88
summaryPoints:
99
buttons:

public/content/translations/tr/roadmap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Ethereum yol haritası
33
description: Ethereum için daha ölçeklenebilir, güvenli ve sürdürülebilir olmanın yolu.
44
lang: tr
55
template: roadmap
6-
image: /roadmap/roadmap-main.png
6+
image: /heroes/roadmap-hub-hero.jpg
77
alt: "Ethereum yol haritası"
88
summaryPoints:
99
buttons:

public/content/translations/zh-tw/roadmap/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: 以太坊開發藍圖
33
description: 以太坊實現更高可擴容性、安全性和永續性的路徑。
44
lang: zh-tw
55
template: roadmap
6-
image: /roadmap/roadmap-main.png
6+
image: /heroes/roadmap-hub-hero.jpg
77
alt: "以太坊開發藍圖"
88
summaryPoints:
99
buttons:

public/upgrades/upgrade_doge.png

-499 KB
Binary file not shown.

src/components/PageMetadata.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Head from "next/head"
44
import { useRouter } from "next/router"
55
import { useTranslation } from "next-i18next"
66

7+
import { getOgImage } from "@/lib/utils/metadata"
8+
79
import { DEFAULT_LOCALE, SITE_URL } from "@/lib/constants"
810

911
type NameMeta = {
@@ -49,41 +51,26 @@ const PageMetadata = ({
4951
const canonical = canonicalUrl || url
5052

5153
/* Set fallback ogImage based on path */
52-
let ogImage = "/home/hero.png"
53-
54-
if (slug.includes("developers")) {
55-
ogImage = "/enterprise-eth.png"
56-
}
57-
58-
if (slug.includes("dapps")) {
59-
ogImage = "/doge-computer.png"
60-
}
61-
62-
if (slug.includes("roadmap")) {
63-
ogImage = "/upgrades/upgrade_doge.png"
64-
}
65-
66-
if (image) {
67-
ogImage = image
68-
}
54+
const ogImage = image || getOgImage(slug)
6955

7056
const ogImageUrl = new URL(ogImage, SITE_URL).href
7157
const metadata: Meta[] = [
72-
{ name: `description`, content: desc },
7358
{ name: `image`, content: ogImageUrl },
74-
{ property: `og:title`, content: fullTitle },
75-
{ property: `og:description`, content: desc },
76-
{ property: `og:type`, content: `website` },
59+
{ name: `description`, content: desc },
60+
{ name: `docsearch:description`, content: desc },
7761
{ name: `twitter:card`, content: `summary_large_image` },
7862
{ name: `twitter:creator`, content: author || siteTitle },
7963
{ name: `twitter:site`, content: author || siteTitle },
8064
{ name: `twitter:title`, content: fullTitle },
8165
{ name: `twitter:description`, content: desc },
8266
{ name: `twitter:image`, content: ogImageUrl },
67+
{ property: `og:title`, content: fullTitle },
68+
{ property: `og:locale`, content: locale! },
69+
{ property: `og:description`, content: desc },
70+
{ property: `og:type`, content: `website` },
8371
{ property: `og:url`, content: url },
8472
{ property: `og:image`, content: ogImageUrl },
8573
{ property: `og:site_name`, content: siteTitle },
86-
{ name: `docsearch:description`, content: desc },
8774
]
8875

8976
return (

src/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const DISCORD_PATH = "/discord/"
2424
export const EDIT_CONTENT_URL = `https://github.com/ethereum/ethereum-org-website/tree/dev/`
2525
export const MAIN_CONTENT_ID = "main-content"
2626
export const WEBSITE_EMAIL = "[email protected]"
27+
export const DEFAULT_OG_IMAGE = "/home/hero.png"
2728

2829
// Config
2930
export const CONTENT_IMAGES_MAX_WIDTH = 800

src/lib/utils/metadata.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { DEFAULT_OG_IMAGE } from "@/lib/constants"
2+
3+
/**
4+
* List of default og images for different sections
5+
*/
6+
const imageForSlug = [
7+
{ section: "developers", image: "/heroes/developers-hub-hero.jpg" },
8+
{ section: "roadmap", image: "/heroes/roadmap-hub-hero.jpg" },
9+
{ section: "guides", image: "/heroes/guides-hub-hero.jpg" },
10+
{ section: "community", image: "/heroes/community-hero.png" },
11+
{ section: "staking", image: "/upgrades/upgrade_rhino.png" },
12+
] as const
13+
14+
/**
15+
* Get the default OG image for a page based on the slug
16+
* @param slug - the slug of the page
17+
* @returns relative path of image
18+
*/
19+
export const getOgImage = (slug: string[]): string => {
20+
let result = DEFAULT_OG_IMAGE
21+
for (const item of imageForSlug) {
22+
if (slug.includes(item.section)) {
23+
result = item.image
24+
}
25+
}
26+
return result
27+
}

0 commit comments

Comments
 (0)