Skip to content

Commit aa6a5df

Browse files
authored
chore: fix og images (#766)
1 parent f3839ec commit aa6a5df

File tree

6 files changed

+111
-15
lines changed

6 files changed

+111
-15
lines changed

docs/astro.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import sitemap from "@astrojs/sitemap";
66
import { imageService } from "@unpic/astro/service";
77
import icon from "astro-icon";
88

9+
import netlify from "@astrojs/netlify";
10+
911
// https://astro.build/config
1012
export default defineConfig({
1113
image: {
1214
service: imageService({
1315
placeholder: "blurhash",
1416
}),
17+
domains: ["images.unsplash.com"],
1518
},
19+
1620
integrations: [
1721
// Enable Preact to support Preact JSX components.
1822
preact({
@@ -33,10 +37,13 @@ export default defineConfig({
3337
sitemap(),
3438
icon(),
3539
],
40+
3641
markdown: {
3742
shikiConfig: {
3843
theme: "one-dark-pro",
3944
},
4045
},
46+
4147
site: `https://unpic.pics`,
48+
adapter: netlify(),
4249
});

docs/netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[images]
2-
remote_images = "https://images.unsplash.com/.*"
2+
remote_images = "https://images.unsplash.com/*"
33
[dev]
44
command = "pnpm --filter docs dev"

docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@algolia/client-search": "^5.19.0",
1616
"@astrojs/markdown-remark": "^6.0.2",
1717
"@astrojs/mdx": "^4.0.6",
18+
"@astrojs/netlify": "^6.1.0",
1819
"@astrojs/preact": "^4.0.2",
1920
"@astrojs/react": "^4.1.5",
2021
"@astrojs/rss": "^4.0.11",
@@ -31,7 +32,7 @@
3132
"@types/node": "^22.10.7",
3233
"@types/react": "^19.0.7",
3334
"@types/react-dom": "^19.0.3",
34-
"@unpic/astro": "workspace:^",
35+
"@unpic/astro": "^",
3536
"@unpic/placeholder": "^0.1.2",
3637
"@unpic/react": "workspace:^",
3738
"astro": "^5.1.7",

docs/src/components/BlogSEO.astro

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@ import type { CollectionEntry } from "astro:content";
33
import { SITE, OPEN_GRAPH } from "../consts";
44
55
import { getImage } from "astro:assets";
6+
import { transformUrl } from "unpic";
67
78
type Props = { canonicalUrl: URL } & CollectionEntry<"blog">["data"];
89
910
const { image, title, description, canonicalUrl } = Astro.props;
1011
const formattedContentTitle = `${title ?? ""} – ${SITE.title}`;
1112
12-
const img = await getImage({
13-
src: image ?? "",
14-
width: 1200,
15-
height: 630,
16-
});
13+
const img = image
14+
? transformUrl({
15+
url: image,
16+
width: 1200,
17+
height: 630,
18+
fallback: "astro",
19+
})
20+
: null;
1721
1822
const og = new URL("/og-blog.png", Astro.site);
1923
og.searchParams.set("title", title ?? "");
20-
og.searchParams.set("img", img.src ?? "");
24+
og.searchParams.set("img", img ?? "");
2125
2226
const imageSrc = og.toString();
23-
const canonicalImageSrc = new URL(imageSrc, Astro.site).toString();
2427
const imageAlt = description ?? OPEN_GRAPH.image.alt;
2528
---
2629

@@ -32,7 +35,10 @@ const imageAlt = description ?? OPEN_GRAPH.image.alt;
3235
<meta property="og:type" content="article" />
3336
<meta property="og:url" content={canonicalUrl} />
3437
<meta property="og:locale" content={SITE.defaultLanguage} />
35-
<meta property="og:image" content={img.src} />
38+
<meta
39+
property="og:image"
40+
content={img ? new URL(img, Astro.site).href : imageSrc}
41+
/>
3642
<meta property="og:image:alt" content={imageAlt} />
3743
<meta
3844
name="description"
@@ -46,7 +52,7 @@ const imageAlt = description ?? OPEN_GRAPH.image.alt;
4652
<meta name="twitter:site" content={OPEN_GRAPH.twitter} />
4753
<meta name="twitter:title" content={formattedContentTitle} />
4854
<meta name="twitter:description" content={description ?? SITE.description} />
49-
<meta name="twitter:image" content={canonicalImageSrc} />
55+
<meta name="twitter:image" content={imageSrc} />
5056
<meta name="twitter:image:alt" content={imageAlt} />
5157

5258
<!--

packages/solid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@
140140
"./dist/index/server.js": "./dist/index/index.js",
141141
"./dist/base/server.js": "./dist/base/index.js"
142142
}
143-
}
143+
}

pnpm-lock.yaml

Lines changed: 85 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)