Skip to content

Commit 471f726

Browse files
Fix OG Images
1 parent dac5c97 commit 471f726

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

src/components/BaseHead.astro

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ const { title, description, permalink, image } = Astro.props
2323
<meta property="og:url" content={permalink} />
2424
<meta property="og:title" content={title} />
2525
<meta property="og:description" content={description} />
26-
{image && <meta property="og:image" content={image} />}
27-
26+
{
27+
image && (
28+
<>
29+
<meta property="og:image" content={image} />
30+
<meta property="og:image:width" content="1200" />
31+
<meta property="og:image:height" content="630" />
32+
</>
33+
)
34+
}
2835
<!-- Twitter -->
2936
<meta property="twitter:card" content="summary_large_image" />
3037
<meta property="twitter:url" content={permalink} />
@@ -49,9 +56,9 @@ const { title, description, permalink, image } = Astro.props
4956
}.js`}
5057
></script>
5158
<script is:inline>
52-
window.plausible =
53-
window.plausible ||
54-
function () {
55-
; (window.plausible.q = window.plausible.q || []).push(arguments)
56-
}
59+
window.plausible =
60+
window.plausible ||
61+
function () {
62+
;(window.plausible.q = window.plausible.q || []).push(arguments)
63+
}
5764
</script>

src/layouts/BlogPost.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const url = Astro.request.url
2121

2222
<html lang={content.lang || "en"}>
2323
<head>
24-
<BaseHead {title} {description} permalink={url} image={new URL(`${Astro.url.pathname}/og.jpg`, Astro.url).toString()} />
24+
<BaseHead {title} {description} permalink={url} image={new URL(path.join(`${Astro.url.pathname}/og.jpg`), Astro.url).toString()} />
2525
</head>
2626

2727
<body>

src/pages/index.astro

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ interface MarkdownFrontmatter {
1919
// It will run during the build, but never in the browser.
2020
// All variables are available to use in the HTML template below.
2121
let title = "Web Dev Simplified Blog"
22-
let description = "In depth articles with interactive examples about every web dev topic."
22+
let description =
23+
"In depth articles with interactive examples about every web dev topic."
2324
2425
// Data Fetching: List all Markdown posts in the repo.
2526
@@ -47,7 +48,12 @@ const allPosts = allMarkdownPosts
4748

4849
<html lang="en">
4950
<head>
50-
<BaseHead {title} {description} permalink={Astro.url.toString()} image={new URL("/og.jpg", Astro.url).toString()} />
51+
<BaseHead
52+
{title}
53+
{description}
54+
permalink={Astro.url.toString()}
55+
image={new URL("/og.", Astro.url).toString()}
56+
/>
5157

5258
<style>
5359
.content {

src/utils/generateOpenGraphImage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export async function generateOpenGraphImage({
164164
satoriOptions,
165165
)
166166

167-
const jpg = await sharp(Buffer.from(svg)).jpeg({ quality: 100 }).toBuffer()
167+
const jpg = await sharp(Buffer.from(svg)).jpeg({ quality: 90 }).toBuffer()
168168

169169
return new Response(jpg, { headers: { "Content-Type": "image/jpg" } })
170170
}

0 commit comments

Comments
 (0)