Skip to content

Commit 2a47164

Browse files
Merge pull request #75 from WebDevSimplified/fix-og-img
Add Secure URL
2 parents 30b7925 + 5d4aed2 commit 2a47164

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

src/components/BaseHead.astro

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ export interface Props {
33
title: string
44
description: string
55
permalink: string
6-
image?: string
76
}
8-
const { title, description, permalink, image } = Astro.props
7+
const { title, description, permalink } = Astro.props
8+
const url = new URL(permalink)
9+
const imageHttpUrl = new URL("og.webp", url)
10+
imageHttpUrl.protocol = "http:"
11+
12+
const imageHttpsUrl = new URL(imageHttpUrl)
13+
imageHttpsUrl.protocol = "https:"
914
---
1015

1116
<!-- Global Metadata -->
@@ -23,21 +28,17 @@ const { title, description, permalink, image } = Astro.props
2328
<meta property="og:url" content={permalink} />
2429
<meta property="og:title" content={title} />
2530
<meta property="og:description" content={description} />
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-
}
31+
<meta property="og:image" content={imageHttpUrl.toString()} />
32+
<meta property="og:image:secure_url" content={imageHttpsUrl.toString()} />
33+
<meta property="og:image:width" content="1200" />
34+
<meta property="og:image:height" content="630" />
35+
3536
<!-- Twitter -->
3637
<meta property="twitter:card" content="summary_large_image" />
3738
<meta property="twitter:url" content={permalink} />
3839
<meta property="twitter:title" content={title} />
3940
<meta property="twitter:description" content={description} />
40-
{image && <meta property="twitter:image" content={image} />}
41+
<meta property="twitter:image" content={imageHttpUrl.toString()} />
4142

4243
<!-- Fonts -->
4344
<link rel="preconnect" href="https://fonts.gstatic.com" />

src/layouts/BlogPost.astro

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import "../styles/shiki-highlight.css"
55
import BaseHead from "../components/BaseHead.astro"
66
import BlogPost from "../components/BlogPost.astro"
77
import BaseTopOfBody from "src/components/BaseTopOfBody.astro"
8-
import path from "path"
98
109
const { content } = Astro.props
1110
const {
@@ -19,17 +18,9 @@ const {
1918
const url = Astro.request.url
2019
---
2120

22-
<html lang={content.lang || "en"}>
21+
<html lang={content.lang || "en"} prefix="og: https://ogp.me/ns#">
2322
<head>
24-
<BaseHead
25-
{title}
26-
{description}
27-
permalink={url}
28-
image={new URL(
29-
path.join(Astro.url.pathname, "og.webp"),
30-
Astro.url,
31-
).toString()}
32-
/>
23+
<BaseHead {title} {description} permalink={url} />
3324
</head>
3425

3526
<body>

src/pages/404.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let description = "Web Dev Simplified Blog"
99
let permalink = "https://blog.webdevsimplified.com"
1010
---
1111

12-
<html lang="en">
12+
<html lang="en" prefix="og: https://ogp.me/ns#">
1313
<head>
1414
<BaseHead {title} {description} {permalink} />
1515
</head>

src/pages/index.astro

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ const allPosts = allMarkdownPosts
4646
// https://docs.astro.build/core-concepts/astro-components/
4747
---
4848

49-
<html lang="en">
49+
<html lang="en" prefix="og: https://ogp.me/ns#">
5050
<head>
51-
<BaseHead
52-
{title}
53-
{description}
54-
permalink={Astro.url.toString()}
55-
image={new URL("/og.webp", Astro.url).toString()}
56-
/>
51+
<BaseHead {title} {description} permalink={Astro.url.toString()} />
5752

5853
<style>
5954
.content {

0 commit comments

Comments
 (0)