Skip to content

Commit c23a5c4

Browse files
committed
Serve docs content images from shared R2 bucket instead of git
Content images under content/docs/images/ were committed as binary files and referenced from MDX with relative paths (../images/foo.png). fumadocs-mdx's static-export bundler resolved those at build time into content-hashed files, which meant the image bytes had to be physically present in the repo just to run `next build`. That's a growing repo and doesn't fit the shared image-hosting setup other Abstract Machines properties are moving to (a single R2 bucket, proxied same-origin so URLs don't change, with immediate cache purge on update). Since this site is a pure Next.js static export with no server runtime in production (deployed as Cloudflare static assets, no next-on-pages or opennextjs/cloudflare), there's no Next.js request handler to reach an R2 binding from. Instead, wrangler.jsonc now has a `main` Worker script that falls back from the ASSETS binding (only when no static file matches, since run_worker_first defaults to false) to reading `/docs/hardware/img/*` straight out of the shared `websites-images` bucket, under the `hardware-docs` key prefix. The first pass of this migration also changed MDX authoring syntax (relative paths -> absolute `/img/<file>`) and added a width/height JSON manifest (src/lib/image-dimensions.json) rendered through next/image, so every new image required a manual manifest entry or the build would throw. That's more ceremony than this change should require: authors should keep writing plain markdown image syntax with whatever relative path they always used, and nothing about next/image's optimizer is actually usable here anyway (this is a static export with no image-optimization server, `unoptimized` was already set). This commit reverts the MDX content and syntax to their original form and replaces DocImage/next/image with a plain, zoomable `<img>`: - content/docs/**/*.mdx: reverted to the original relative-path markdown image syntax (`../images/foo.png`) - src/lib/remark-doc-images.ts: new remark plugin that resolves each image's relative path against content/docs/images/ at compile time (pure path math, no image bytes needed) into the literal `/docs/hardware/img/...` URL the Worker serves — replaces fumadocs-mdx's remarkImage, which needs the file on disk - source.config.ts: disable remarkImageOptions, wire in remarkDocImages - src/mdx-components.tsx: render the `img` MDX node as a plain `<img>` (no next/image, no width/height) wrapped in ImageZoom for click-to-zoom, passing `src`/`alt` to ImageZoom itself as well as the inner `<img>` — ImageZoom's zoomed-in view reads its image from that prop directly, not from `children` - src/components/doc-image.tsx, src/lib/image-dimensions.json: removed, no longer needed - worker/index.ts, wrangler.jsonc: unchanged from the first pass - scripts/publish-image.mjs, scripts/README.md, scripts/.env.publish-image.example: maintainer-only upload+purge CLI and its docs, unchanged from the first pass
1 parent daf1569 commit c23a5c4

68 files changed

Lines changed: 526 additions & 4221 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ web_modules/
6969
.env
7070
.env.*
7171
!.env.example
72+
!scripts/.env.publish-image.example
7273

7374
# parcel-bundler cache (https://parceljs.org/)
7475
.cache

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ This site uses:
1919

2020
- **Next.js static export**`next build` outputs static files to `out/`
2121
- **Next.js `basePath`** — generates links and assets under `/docs/hardware`
22-
- **Post-build nesting**`scripts/nest-static-export.mjs` moves the export under `out/docs/hardware/` so Cloudflare static assets can serve it from the route prefix without custom Worker code
22+
- **Post-build nesting**`scripts/nest-static-export.mjs` moves the export under `out/docs/hardware/` so Cloudflare static assets can serve it from the route prefix
23+
- **Worker script (`worker/index.ts`)** — thin `main` script in front of the static
24+
assets. Almost every request is served by the `ASSETS` binding untouched
25+
(`run_worker_first` defaults to `false`, so Cloudflare only invokes the Worker when no
26+
static file matches). The one exception is `/docs/hardware/img/*`, which the Worker
27+
answers directly from the shared R2 bucket (`IMAGES_BUCKET`) — see
28+
[`scripts/README.md`](./scripts/README.md) for why docs content images are no longer
29+
committed to this repo.
2330

2431
### Cloudflare build settings (Dashboard)
2532

@@ -46,8 +53,11 @@ flowchart LR
4653
4754
subgraph Runtime_Request_Flow
4855
U[Browser request] --> H[Cloudflare static asset route]
49-
H --> J[Static asset lookup]
56+
H -->|asset found| J[Static asset lookup]
57+
H -->|no asset matches| K[worker/index.ts]
58+
K -->|"/docs/hardware/img/*"| R[(R2: websites-images)]
5059
J --> U
60+
R --> U
5161
end
5262
```
5363

@@ -73,6 +83,8 @@ Set this as a Cloudflare build variable so it is embedded into the static output
7383
| `src/lib/source.ts` | Fumadocs source adapter |
7484
| `src/lib/layout.shared.tsx` | Shared layout options (nav, logo) |
7585
| `scripts/nest-static-export.mjs` | Moves static export under `/docs/hardware` |
86+
| `worker/index.ts` | Worker script: falls back to `ASSETS`, proxies `/docs/hardware/img/*` from R2 |
87+
| `scripts/publish-image.mjs` | Maintainer-only: uploads a docs image to R2 and purges its cache (see `scripts/README.md`) |
7688

7789
## Learn More
7890

content/docs/base-board/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Modular expansion board for S0 IoT Gateway
55

66
# S0 Base Board
77

8-
![S0 Baseboard](../images/baseboard-front.png)
8+
![S0 Baseboard](/img/baseboard-front.png)
99

1010
The **S0 Base Board** is a modular expansion board designed to power and extend the functionality of the S0 compute module. It integrates critical components for industrial IoT and smart metering applications, making it ideal for professional deployments.
1111

@@ -39,7 +39,7 @@ The Base Board transforms the S0 module into a complete gateway solution. The S0
3939

4040
## Getting Started
4141

42-
![Baseboard Labeled](../images/bb-label.png)
42+
![Baseboard Labeled](/img/bb-label.png)
4343

4444
### Powering the Board
4545

content/docs/base-board/pinouts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: S0 Base Board pin assignments and header descriptions
55

66
# Base Board Pinouts
77

8-
![Baseboard Pin Sockets](../images/baseboard-pinout.svg)
8+
![Baseboard Pin Sockets](/img/baseboard-pinout.svg)
99

1010
## DC Header Pinout (`J6`)
1111

content/docs/base-board/schematics.mdx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ description: S0 Base Board circuit schematics and diagrams
77

88
## Ethernet Circuit
99

10-
![W5500](../images/ethernet.png)
10+
![W5500](/img/ethernet.png)
1111

12-
![Jack and Magnetics](../images/magneticsandjack.png)
12+
![Jack and Magnetics](/img/magneticsandjack.png)
1313

14-
![Decoupling Caps](../images/decapseth.png)
14+
![Decoupling Caps](/img/decapseth.png)
1515

1616
## M-Bus Circuit
1717

18-
![Wired M-Bus](../images/wiredmbus.png)
18+
![Wired M-Bus](/img/wiredmbus.png)
1919

2020
## SD Card Circuit
2121

22-
![SD Card](../images/sdcard.png)
22+
![SD Card](/img/sdcard.png)
2323

2424
## Board Frame and Connectors
2525

26-
![Board Frame](../images/baseframe.png)
26+
![Board Frame](/img/baseframe.png)
2727

28-
![Board Headers](../images/baseconnectors.png)
28+
![Board Headers](/img/baseconnectors.png)
2929

3030
## Power Circuitry
3131

32-
![Terminal Block and Battery Connector](../images/powerbase.png)
32+
![Terminal Block and Battery Connector](/img/powerbase.png)
3333

34-
![Voltage Converters](../images/voltconvert.png)
34+
![Voltage Converters](/img/voltconvert.png)
3535

36-
![Battery Charger](../images/battcharger.png)
36+
![Battery Charger](/img/battcharger.png)

content/docs/images/arch.png

-102 KB
Binary file not shown.
-618 KB
Binary file not shown.
-116 KB
Binary file not shown.
-158 KB
Binary file not shown.

0 commit comments

Comments
 (0)