@@ -4,12 +4,7 @@ import Head from "next/head"
4
4
import { useRouter } from "next/router"
5
5
import { useTranslation } from "next-i18next"
6
6
7
- import { DEFAULT_LOCALE , SITE_URL } from "@/lib/constants"
8
-
9
- import ogImageDapps from "@/public/doge-computer.png"
10
- import ogImageDevelopers from "@/public/enterprise-eth.png"
11
- import ogImageDefault from "@/public/home/hero.png"
12
- import ogImageUpgrades from "@/public/upgrades/upgrade_doge.png"
7
+ import { SITE_URL } from "@/lib/constants"
13
8
14
9
type NameMeta = {
15
10
name : string
@@ -44,33 +39,38 @@ const PageMetadata: React.FC<IProps> = ({
44
39
const desc = description || t ( "site-description" )
45
40
const siteTitle = t ( "site-title" )
46
41
const fullTitle = `${ title } | ${ siteTitle } `
42
+ const origin = process . env . NEXT_PUBLIC_SITE_URL || SITE_URL // TODO: Remove .env var usage after launch
43
+
44
+ // Remove any query params (?) or hash links (#)
45
+ const path = asPath . replace ( / [ \? \# ] .* / , "" )
46
+ const slug = path . split ( "/" )
47
47
48
48
/* Set canonical URL w/ language path to avoid duplicate content */
49
49
/* e.g. set ethereum.org/about/ to ethereum.org/en/about/ */
50
- const canonical = canonicalUrl || join ( SITE_URL , DEFAULT_LOCALE , asPath )
51
- const url = locale ? join ( SITE_URL , locale , asPath ) : canonical
50
+ const url = new URL ( join ( locale ! , path ) , origin ) . href
51
+ const canonical = canonicalUrl || url
52
52
53
53
/* Set fallback ogImage based on path */
54
- let ogImage = ogImageDefault . src
54
+ let ogImage = "/home/hero.png"
55
55
56
- if ( asPath . includes ( "/ developers/ " ) ) {
57
- ogImage = ogImageDevelopers . src
56
+ if ( slug . includes ( "developers" ) ) {
57
+ ogImage = "/enterprise-eth.png"
58
58
}
59
59
60
- if ( asPath . includes ( "/ dapps/ " ) ) {
61
- ogImage = ogImageDapps . src
60
+ if ( slug . includes ( "dapps" ) ) {
61
+ ogImage = "/doge-computer.png"
62
62
}
63
63
64
- if ( asPath . includes ( "/ roadmap/ " ) ) {
65
- ogImage = ogImageUpgrades . src
64
+ if ( slug . includes ( "roadmap" ) ) {
65
+ ogImage = "/upgrades/upgrade_doge.png"
66
66
}
67
67
68
68
if ( image ) {
69
69
ogImage = image
70
70
}
71
71
72
- const ogImageUrl = join ( SITE_URL , ogImage )
73
- const metadata : Array < Meta > = [
72
+ const ogImageUrl = new URL ( ogImage , origin ) . href
73
+ const metadata : Meta [ ] = [
74
74
{ name : `description` , content : desc } ,
75
75
{ name : `image` , content : ogImageUrl } ,
76
76
{ property : `og:title` , content : fullTitle } ,
0 commit comments