Skip to content

Commit 1a1bb0a

Browse files
authored
Merge pull request #547 from shibomb/fix/ogp-url-default-img
Fix: ogp url, ogp image url and default ogp image file.
2 parents d1cae09 + e23bf7b commit 1a1bb0a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (shouldSkipCompress) {
1717

1818
// https://astro.build/config
1919
export default defineConfig({
20+
site: 'https://p5js.org',
2021
integrations: [
2122
preact({
2223
compat: true,

public/assets/img/p5js.png

27.1 KB
Loading

src/components/Head/index.astro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface Props {
1010
1111
const {
1212
title,
13-
featuredImageSrc = "/favicon.svg",
13+
featuredImageSrc = "/assets/img/p5js.png",
1414
locale,
1515
description,
1616
} = Astro.props;
@@ -28,6 +28,9 @@ const t = await getUiTranslator(locale);
2828
const localizedTitle = t(title) as string;
2929
const localizedDescription =
3030
description || (t("briefPageDescriptions", title) as string);
31+
32+
const rootUrl = new URL('/', process.env.NODE_ENV === "production" ? Astro.site : Astro.url.href);
33+
const ogpImageSrc = new URL(featuredImageSrc, rootUrl);
3134
---
3235

3336
<head>
@@ -38,14 +41,14 @@ const localizedDescription =
3841
<meta name="description" content={localizedDescription} />
3942
<meta property="og:title" content={title} />
4043
<meta property="og:description" content={localizedDescription} />
41-
<meta property="og:image" content={featuredImageSrc} />
44+
<meta property="og:image" content={ogpImageSrc} />
4245
<meta property="og:url" content={Astro.url.href} />
4346
<meta property="og:type" content="website" />
4447
<meta property="og:locale" content={localeContentMap[locale]} />
4548
<meta name="twitter:card" content="summary_large_image" />
4649
<meta name="twitter:site" content="@p5xjs" />
4750
<meta name="twitter:title" content={title} />
4851
<meta name="twitter:description" content={localizedDescription} />
49-
<meta name="twitter:image" content={featuredImageSrc} />
52+
<meta name="twitter:image" content={ogpImageSrc} />
5053
<meta name="twitter:url" content={Astro.url.href} />
5154
</head>

0 commit comments

Comments
 (0)