@mailoo/blog 1.34.2 → 1.34.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +49 -10
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -33,15 +33,24 @@ const client = createMailooBlogClient(config, {
33
33
  })
34
34
  ```
35
35
 
36
- A **site-relative** prefix is copied onto rewritten `ogImageUrl`, image URLs
37
- in `htmlContent` / `content`, and JSON-LD `image` / `logo`. That path is the
38
- right `src` for `<img>`. `og:image`, `twitter:image`, and JSON-LD `image` /
39
- `logo` must be **absolute** and resolved against the **current request
40
- origin** (`X-Forwarded-Host` or `Host`, plus `X-Forwarded-Proto`). Do not
41
- bake a fixed `SITE_URL` into this option: the same post can be served on
42
- more than one host. Without `metadataBase`, Next.js prefixes a relative
43
- `openGraph.images` with `http://localhost:3000`. Leave `htmlContent` image
44
- URLs relative.
36
+ A site-relative prefix is copied onto rewritten `ogImageUrl` and image URLs
37
+ in `htmlContent` / JSON-LD. Leave those paths as `<img src>`. Do not pass
38
+ `post.ogImageUrl` into `openGraph.images` as-is. Absolutize against the
39
+ **current request origin** (`X-Forwarded-Host` or `Host`, plus
40
+ `X-Forwarded-Proto`). Do not bake a fixed `SITE_URL` into this option.
41
+ Without `metadataBase`, Next.js emits `http://localhost:3000/…`.
42
+
43
+ Facebook needs absolute `https://`; MIME `image/jpeg` | `image/gif` |
44
+ `image/png`; and `og:image:type` / `width` / `height` (min 200×200, max
45
+ 8 MB). The package does not supply width/height — probe the proxy (Range
46
+ `bytes=0-524288`).
47
+
48
+ `Allow` the proxy path in the `*` robots group for Twitter/LinkedIn and
49
+ RFC 9309. That is **not** enough for Facebook: `Disallow: /api/` wins over
50
+ `Allow: /api/v1/mailoo-image` and the debugger reports a synthetic 403
51
+ even when the origin returned 200. Add `User-agent: facebookexternalhit`
52
+ / `Allow: /`. Do not expect that group to override `Disallow: /api/` —
53
+ omit `Disallow: /api/` or serve the proxy outside `/api/`.
45
54
 
46
55
  ```ts
47
56
  import { headers } from 'next/headers'
@@ -61,10 +70,40 @@ function absoluteSocialImageUrl(imageUrl: string, origin: string): string {
61
70
  return new URL(imageUrl, `${origin}/`).toString()
62
71
  }
63
72
 
73
+ async function probeOgImage(imageUrl: string): Promise<{
74
+ url: string
75
+ secureUrl: string
76
+ type: 'image/jpeg' | 'image/gif' | 'image/png'
77
+ width: number
78
+ height: number
79
+ }> {
80
+ const res = await fetch(imageUrl, {
81
+ headers: { Range: 'bytes=0-524288' },
82
+ })
83
+ if (!res.ok && res.status !== 206) {
84
+ throw new Error(`og:image probe failed: HTTP ${res.status}`)
85
+ }
86
+ const type = (res.headers.get('content-type') ?? '')
87
+ .split(';')[0]
88
+ ?.trim()
89
+ .toLowerCase()
90
+ if (type !== 'image/jpeg' && type !== 'image/gif' && type !== 'image/png') {
91
+ throw new Error(
92
+ `og:image type must be jpeg, gif or png, got ${type || 'missing'}`
93
+ )
94
+ }
95
+ // Host: parse PNG IHDR / JPEG SOF / GIF header of the body.
96
+ const { width, height } = parseImageDimensions(
97
+ new Uint8Array(await res.arrayBuffer())
98
+ )
99
+ return { url: imageUrl, secureUrl: imageUrl, type, width, height }
100
+ }
101
+
64
102
  const origin = await requestOrigin()
65
- const ogImage = post.ogImageUrl
103
+ const absolute = post.ogImageUrl
66
104
  ? absoluteSocialImageUrl(post.ogImageUrl, origin)
67
105
  : undefined
106
+ const image = absolute ? await probeOgImage(absolute) : undefined
68
107
  ```
69
108
 
70
109
  Mount `createPublicImageContentHandler` from `@mailoo/images/routes` on that
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mailoo/blog",
3
- "version": "1.34.2",
3
+ "version": "1.34.3",
4
4
  "description": "Headless Mailoo Blog module for Next.js (BFF routes, server client, components)",
5
5
  "license": "LicenseRef-Mailoo-NoModification",
6
6
  "homepage": "https://mailoo.app/en/support/docs/integrations/nextjs-packages",
@@ -69,7 +69,7 @@
69
69
  "LICENSE"
70
70
  ],
71
71
  "dependencies": {
72
- "@mailoo/images": "1.34.2"
72
+ "@mailoo/images": "1.34.3"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "@mailoo/next-core": "^1.18.4",
@@ -88,7 +88,7 @@
88
88
  }
89
89
  },
90
90
  "devDependencies": {
91
- "@mailoo/next-core": "1.34.2",
91
+ "@mailoo/next-core": "1.34.3",
92
92
  "@types/node": "^25.9.5",
93
93
  "@types/react": "^19.2.18",
94
94
  "@types/react-dom": "^19.2.7",