Skip to content

Commit 405c580

Browse files
fix og image resolution
1 parent 97993b4 commit 405c580

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

blog/addressing-tanstack-feedback/index.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ This feedback was valuable. Here's what we changed.
1919

2020
## No More project_id
2121

22-
The `project_id` was used for anonymous telemetry and a sync protocol. Both are not needed anymore. Thus, `project_id` is gone.
22+
The `project_id` was used for anonymous telemetry and a sync protocol. Both are not needed anymore. Thus, `project_id` is now gone for [unpackaged projects](https://inlang.com/docs/unpacked-project).
23+
24+
```diff
25+
project.inlang/
26+
├── settings.json
27+
├── cache/
28+
├── README.md
29+
-└── project_id
30+
└── .gitignore
31+
```
2332

2433
## Middleware Documentation
2534

@@ -58,4 +67,3 @@ _Links:_
5867
- [Monorepo Setup](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/monorepo)
5968
- [Pedro Martins](https://nikuscs.com/)
6069
- [Pedro's original post](https://nikuscs.com/blog/13-tanstackstart-i18n/)
61-
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, it, expect } from "vitest";
2+
import { resolveOgImageUrl } from "./og-image";
3+
4+
describe("resolveOgImageUrl", () => {
5+
it("returns absolute URLs unchanged", () => {
6+
expect(
7+
resolveOgImageUrl("https://example.com/og.png", "my-post"),
8+
).toBe("https://example.com/og.png");
9+
});
10+
11+
it("resolves relative URLs against the blog slug", () => {
12+
expect(resolveOgImageUrl("./assets/banner.svg", "my-post")).toBe(
13+
"https://inlang.com/blog/my-post/assets/banner.svg",
14+
);
15+
});
16+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function resolveOgImageUrl(value: string, slug: string): string {
2+
if (isAbsoluteUrl(value)) return value;
3+
return new URL(value, `https://inlang.com/blog/${slug}/`).toString();
4+
}
5+
6+
function isAbsoluteUrl(value: string): boolean {
7+
return /^[a-z][a-z0-9+.-]*:/.test(value);
8+
}

packages/website-v2/src/routes/blog/$slug.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useEffect, useState } from "react";
55
import { initMarkdownInteractive } from "../../components/markdown-interactive";
66
import markdownCss from "../../markdown.css?url";
77
import { getBlogDescription, getBlogTitle } from "../../blog/blogMetadata";
8+
import { resolveOgImageUrl } from "../../blog/og-image";
89

910
const ogImage =
1011
"https://cdn.jsdelivr.net/gh/opral/inlang@latest/packages/website/public/opengraph/inlang-social-image.jpg";
@@ -120,10 +121,13 @@ const loadBlogPost = createServerFn({ method: "GET" }).handler(async (ctx) => {
120121
rawMarkdown,
121122
frontmatter: parsed.frontmatter,
122123
});
123-
const ogImageOverride =
124+
const ogImageOverrideRaw =
124125
typeof parsed.frontmatter?.["og:image"] === "string"
125126
? parsed.frontmatter["og:image"]
126127
: undefined;
128+
const ogImageOverride = ogImageOverrideRaw
129+
? resolveOgImageUrl(ogImageOverrideRaw, slug)
130+
: undefined;
127131
const ogImageAlt =
128132
typeof parsed.frontmatter?.["og:image:alt"] === "string"
129133
? parsed.frontmatter["og:image:alt"]

0 commit comments

Comments
 (0)