Skip to content

Commit e176f2f

Browse files
committed
improve ogimage
1 parent 18139c2 commit e176f2f

3 files changed

Lines changed: 65 additions & 62 deletions

File tree

functions/ogimage/[[path]]/index.png.res

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ type context = {request: FetchAPI.request, params: {path: array<string>}}
1717

1818
let onRequest = async ({params}: context) => {
1919
let title = params.path[0]->Option.getOr("ReScript")->decodeURIComponent
20-
let descripton = params.path[1]->Option.getOr("ReScript")->decodeURIComponent
20+
let description = params.path[1]->Option.getOr("ReScript")->decodeURIComponent
2121

22-
// if the description contains a `.` we want to split it up and use the first sentence as the subTitle
23-
let (descripton, subTitle) = {
24-
let segments = descripton->String.split(".")
25-
switch segments->Array.length > 1 {
26-
| true => (segments[1]->Option.getOr(""), segments[0])
27-
| false => (descripton, None)
22+
// we want to split the title if it contains a |
23+
let (title, subTitle, description) = {
24+
let titleSegments = title->String.split("|")
25+
// if the description contains a `.` we want to split it up and use the first sentence as the subTitle
26+
let descriptionSegments = description->String.split(".")
27+
28+
let (subTitle, description) = switch titleSegments[1] {
29+
| Some(subTitle) => (Some(subTitle), description)
30+
| None =>
31+
switch descriptionSegments[1] {
32+
| Some(description) => (descriptionSegments[0], description)
33+
| None => (None, description)
34+
}
2835
}
29-
}
3036

31-
// we want to split the title if it contains a |
32-
let (title, subTitle) = {
33-
let segments = title->String.split("|")
34-
(segments[0]->Option.getOr(""), segments[1]->Option.orElse(subTitle))
37+
(titleSegments[0]->Option.getOr(""), subTitle, description)
3538
}
3639

3740
Cloudflare.imageResponse(
@@ -103,7 +106,7 @@ let onRequest = async ({params}: context) => {
103106
// extra space since X wants to overlay the text
104107
}}
105108
>
106-
{React.string(descripton)}
109+
{React.string(description)}
107110
</p>
108111
</div>,
109112
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@
114114
"vite-plugin-page-reload": "^0.2.3",
115115
"vitest": "^4.1.2",
116116
"vitest-browser-react": "^2.2.0",
117-
"wrangler": "^4.80.0"
117+
"wrangler": "^4.85.0"
118118
}
119119
}

yarn.lock

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -384,50 +384,50 @@ __metadata:
384384
languageName: node
385385
linkType: hard
386386

387-
"@cloudflare/unenv-preset@npm:2.16.0":
388-
version: 2.16.0
389-
resolution: "@cloudflare/unenv-preset@npm:2.16.0"
387+
"@cloudflare/unenv-preset@npm:2.16.1":
388+
version: 2.16.1
389+
resolution: "@cloudflare/unenv-preset@npm:2.16.1"
390390
peerDependencies:
391391
unenv: 2.0.0-rc.24
392-
workerd: 1.20260301.1 || ~1.20260302.1 || ~1.20260303.1 || ~1.20260304.1 || >1.20260305.0 <2.0.0-0
392+
workerd: ">1.20260305.0 <2.0.0-0"
393393
peerDependenciesMeta:
394394
workerd:
395395
optional: true
396-
checksum: 10c0/ddb2939cd05b5a0cb17d44b98a11b5c8e24dc6fa31171e98d8f1d7ffbb9cd35fde2ad2873715dc90db63183d6768ea43256ce3e4eb8c359542a2051f2d8bd919
396+
checksum: 10c0/08c9bd9ef488a14fd5330eb2c0829fc221f97f12295f8263dc8e3a6816ebd1a629e7255a3619b8bb688f1f58deafe28042c4e90ea84c926438c768f235f82ad9
397397
languageName: node
398398
linkType: hard
399399

400-
"@cloudflare/workerd-darwin-64@npm:1.20260401.1":
401-
version: 1.20260401.1
402-
resolution: "@cloudflare/workerd-darwin-64@npm:1.20260401.1"
400+
"@cloudflare/workerd-darwin-64@npm:1.20260424.1":
401+
version: 1.20260424.1
402+
resolution: "@cloudflare/workerd-darwin-64@npm:1.20260424.1"
403403
conditions: os=darwin & cpu=x64
404404
languageName: node
405405
linkType: hard
406406

407-
"@cloudflare/workerd-darwin-arm64@npm:1.20260401.1":
408-
version: 1.20260401.1
409-
resolution: "@cloudflare/workerd-darwin-arm64@npm:1.20260401.1"
407+
"@cloudflare/workerd-darwin-arm64@npm:1.20260424.1":
408+
version: 1.20260424.1
409+
resolution: "@cloudflare/workerd-darwin-arm64@npm:1.20260424.1"
410410
conditions: os=darwin & cpu=arm64
411411
languageName: node
412412
linkType: hard
413413

414-
"@cloudflare/workerd-linux-64@npm:1.20260401.1":
415-
version: 1.20260401.1
416-
resolution: "@cloudflare/workerd-linux-64@npm:1.20260401.1"
414+
"@cloudflare/workerd-linux-64@npm:1.20260424.1":
415+
version: 1.20260424.1
416+
resolution: "@cloudflare/workerd-linux-64@npm:1.20260424.1"
417417
conditions: os=linux & cpu=x64
418418
languageName: node
419419
linkType: hard
420420

421-
"@cloudflare/workerd-linux-arm64@npm:1.20260401.1":
422-
version: 1.20260401.1
423-
resolution: "@cloudflare/workerd-linux-arm64@npm:1.20260401.1"
421+
"@cloudflare/workerd-linux-arm64@npm:1.20260424.1":
422+
version: 1.20260424.1
423+
resolution: "@cloudflare/workerd-linux-arm64@npm:1.20260424.1"
424424
conditions: os=linux & cpu=arm64
425425
languageName: node
426426
linkType: hard
427427

428-
"@cloudflare/workerd-windows-64@npm:1.20260401.1":
429-
version: 1.20260401.1
430-
resolution: "@cloudflare/workerd-windows-64@npm:1.20260401.1"
428+
"@cloudflare/workerd-windows-64@npm:1.20260424.1":
429+
version: 1.20260424.1
430+
resolution: "@cloudflare/workerd-windows-64@npm:1.20260424.1"
431431
conditions: os=win32 & cpu=x64
432432
languageName: node
433433
linkType: hard
@@ -8103,19 +8103,19 @@ __metadata:
81038103
languageName: node
81048104
linkType: hard
81058105

8106-
"miniflare@npm:4.20260401.0":
8107-
version: 4.20260401.0
8108-
resolution: "miniflare@npm:4.20260401.0"
8106+
"miniflare@npm:4.20260424.0":
8107+
version: 4.20260424.0
8108+
resolution: "miniflare@npm:4.20260424.0"
81098109
dependencies:
81108110
"@cspotcode/source-map-support": "npm:0.8.1"
81118111
sharp: "npm:^0.34.5"
8112-
undici: "npm:7.24.4"
8113-
workerd: "npm:1.20260401.1"
8112+
undici: "npm:7.24.8"
8113+
workerd: "npm:1.20260424.1"
81148114
ws: "npm:8.18.0"
81158115
youch: "npm:4.1.0-beta.10"
81168116
bin:
81178117
miniflare: bootstrap.js
8118-
checksum: 10c0/886073d7dc9375b03e8f21c8335ad6856a8797c3e1ed6c321e4d8b433fa5273f272fc178d61a3ed5f96a6d92e9d104fbf36342214af96c7a738e23cfc663955e
8118+
checksum: 10c0/c01802224ed46a29ef2705808409896446bb09acd588bf85f38adc7bee8c8d45ca3232860da757a33a3761ed7f0cff7df28b5bb04604e72a8dc30a1d2868cd4c
81198119
languageName: node
81208120
linkType: hard
81218121

@@ -9554,7 +9554,7 @@ __metadata:
95549554
vite-plugin-page-reload: "npm:^0.2.3"
95559555
vitest: "npm:^4.1.2"
95569556
vitest-browser-react: "npm:^2.2.0"
9557-
wrangler: "npm:^4.80.0"
9557+
wrangler: "npm:^4.85.0"
95589558
languageName: unknown
95599559
linkType: soft
95609560

@@ -11062,10 +11062,10 @@ __metadata:
1106211062
languageName: node
1106311063
linkType: hard
1106411064

11065-
"undici@npm:7.24.4":
11066-
version: 7.24.4
11067-
resolution: "undici@npm:7.24.4"
11068-
checksum: 10c0/cb302e81fadb7f0b7946ab77595715c0961b46a025ccecae79ba599432d0bc8d1e3da4dfe7ff66bc74f115c1b8ff0f099bc4e9bf313db4562da23995872c6d17
11065+
"undici@npm:7.24.8":
11066+
version: 7.24.8
11067+
resolution: "undici@npm:7.24.8"
11068+
checksum: 10c0/5b3cb18b1c6ccff564c37390547b2f137c666ada5083af6d5b5671dc12f73530ae2872e16fab1e3948b46013fed7c81ed10bce23f7dbf21b73794244b70b7eea
1106911069
languageName: node
1107011070
linkType: hard
1107111071

@@ -11819,15 +11819,15 @@ __metadata:
1181911819
languageName: node
1182011820
linkType: hard
1182111821

11822-
"workerd@npm:1.20260401.1":
11823-
version: 1.20260401.1
11824-
resolution: "workerd@npm:1.20260401.1"
11822+
"workerd@npm:1.20260424.1":
11823+
version: 1.20260424.1
11824+
resolution: "workerd@npm:1.20260424.1"
1182511825
dependencies:
11826-
"@cloudflare/workerd-darwin-64": "npm:1.20260401.1"
11827-
"@cloudflare/workerd-darwin-arm64": "npm:1.20260401.1"
11828-
"@cloudflare/workerd-linux-64": "npm:1.20260401.1"
11829-
"@cloudflare/workerd-linux-arm64": "npm:1.20260401.1"
11830-
"@cloudflare/workerd-windows-64": "npm:1.20260401.1"
11826+
"@cloudflare/workerd-darwin-64": "npm:1.20260424.1"
11827+
"@cloudflare/workerd-darwin-arm64": "npm:1.20260424.1"
11828+
"@cloudflare/workerd-linux-64": "npm:1.20260424.1"
11829+
"@cloudflare/workerd-linux-arm64": "npm:1.20260424.1"
11830+
"@cloudflare/workerd-windows-64": "npm:1.20260424.1"
1183111831
dependenciesMeta:
1183211832
"@cloudflare/workerd-darwin-64":
1183311833
optional: true
@@ -11841,25 +11841,25 @@ __metadata:
1184111841
optional: true
1184211842
bin:
1184311843
workerd: bin/workerd
11844-
checksum: 10c0/826b74a6c28d833ff8d12b8f6bdd930c76c3042a4aeb87fd455659d62bba4e3ed741c1d86774db316258bc03d157e31f7fc0e27e6ef4bbb98a75ad69d7b11c5c
11844+
checksum: 10c0/566cfe48a2202fb977174275e678f52c2fa126e42fcc2edc2fbe1250eb94d9987200662cc1b487924c2a5ade83c2bf3e6879e7f684e2139815fb9337ce0d8c45
1184511845
languageName: node
1184611846
linkType: hard
1184711847

11848-
"wrangler@npm:^4.80.0":
11849-
version: 4.80.0
11850-
resolution: "wrangler@npm:4.80.0"
11848+
"wrangler@npm:^4.85.0":
11849+
version: 4.85.0
11850+
resolution: "wrangler@npm:4.85.0"
1185111851
dependencies:
1185211852
"@cloudflare/kv-asset-handler": "npm:0.4.2"
11853-
"@cloudflare/unenv-preset": "npm:2.16.0"
11853+
"@cloudflare/unenv-preset": "npm:2.16.1"
1185411854
blake3-wasm: "npm:2.1.5"
1185511855
esbuild: "npm:0.27.3"
1185611856
fsevents: "npm:~2.3.2"
11857-
miniflare: "npm:4.20260401.0"
11857+
miniflare: "npm:4.20260424.0"
1185811858
path-to-regexp: "npm:6.3.0"
1185911859
unenv: "npm:2.0.0-rc.24"
11860-
workerd: "npm:1.20260401.1"
11860+
workerd: "npm:1.20260424.1"
1186111861
peerDependencies:
11862-
"@cloudflare/workers-types": ^4.20260401.1
11862+
"@cloudflare/workers-types": ^4.20260424.1
1186311863
dependenciesMeta:
1186411864
fsevents:
1186511865
optional: true
@@ -11869,7 +11869,7 @@ __metadata:
1186911869
bin:
1187011870
wrangler: bin/wrangler.js
1187111871
wrangler2: bin/wrangler.js
11872-
checksum: 10c0/3e0ad86c48db6079609a540409a7800a0120c5dff5563c5ecb1b137165c4a7047fcaefaaffd5a06188540cd105e3aeb7a2cb68ec11cd02f21259a036d95a759c
11872+
checksum: 10c0/b301e1b4c70bebb3adbf4b4fa9a90351b1847d940208b1878e491e751706ba3efe477bb43dce4f2a90b00b548f93858a60f4a87c012da1186f56eaa260d61115
1187311873
languageName: node
1187411874
linkType: hard
1187511875

0 commit comments

Comments
 (0)