Repository navigation
feat(sync-content): mirror docs/cli image and PDF assets into the site - #16
Merged
Merged
Conversation
Guides in agentproto/ts can now embed screenshots and link a PDF, but sync-content.mjs only ever copied .md/meta.json — any relative image or PDF reference 404s once synced. Copy matched assets (png/jpg/gif/ svg/webp/pdf) to two places: content/docs/<rel>, where fumadocs-mdx's remarkImage plugin resolves a relative markdown image as a static import against the compiled .mdx file's own directory; and public/docs/<rel>, where Next serves it ahead of the docs catch-all route at the exact path a relative link resolves to from the page's own URL. Proved against agentproto/ts#1458's phone-pairing guide: all 5 screenshots and the PDF link render/200 through a real `next dev` render of the page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Guides in
agentproto/tscan now embed screenshots and link a downloadable PDF (seeagentproto/ts#1458, a phone-pairing guide), butscripts/sync-content.mjs'swalkMarkdown()only ever collected files ending.mdor namedmeta.json— there was no path that copied a binary asset fromdocs/cli/**intocontent/docs/**. Any relative image or PDF link in a guide 404s once synced onto this site.What
sync-content.mjsnow also walks and copies matched assets (png/jpg/jpeg/gif/svg/webp/pdf) from the source tree, to two destinations, for two different reasons (documented at length in the new header comment):content/docs/<rel>— fumadocs-mdx'sremarkImageplugin (fumadocs-core/dist/mdx-plugins/remark-image.js) rewrites a relative![]()image src into a staticimport, resolved against the compiled.mdxfile's own directory. Turbopack/webpack need the real file sitting there at build time for that import to resolve — this is never served frompublic/.public/docs/<rel>— a plain markdown link (e.g. "Download this guide as a PDF") is alinknode, not animagenode, soremarkImagenever touches it — it reaches the page as a literal relativehref. The browser resolves that against the page's own URL (/docs/<rel-page-path>, sincedocsSourcemountscontent/docsatbaseUrl: "/docs"). Next.js servespublic/files at that same path ahead of the[[...slug]]docs catch-all route, so mirroring the asset there is what actually turns the link into a 200 instead of a 404 through the docs route.Also:
public/docsadded to.gitignore(synced/generated, same ascontent/docs) and to thecleanscript.pnpm-lock.yamlis intentionally not committed here — this repo doesn't currently track one; I generated it locally only topnpm install/build in an isolated worktree.How I proved it
Built an isolated worktree (
git worktree add -b docs-assets-sync ... origin/main, so as not to touch the main checkout's own uncommitted work on another branch) and pointedsync-content.mjs's sibling-repo detection atagentproto/ts#1458's worktree via a../tssymlink (the same mechanism the script already supports for a local sibling checkout — no code change needed for that part).node scripts/sync-content.mjs— synced 63 docs + 6 assets (5 screenshots + 1 PDF) to bothcontent/docs/guides/assets/phone-pairing/andpublic/docs/guides/assets/phone-pairing/.pnpm build(next build, Turbopack): exit 1 — but for a reason unrelated to this change:docs/cli/verbs/pair.md(pre-existing content, last touched by an unrelated commit2bc6692fwell before #1458) has a rawfrom <daemon>; scan a new pairing QRin prose, which MDX parses as an unclosed JSX tag (Expected a closing tag for <daemon>) and which the staticgenerateStaticParams()build enumerates for every page, failing the whole build. I confirmed this is pre-existing and independent of my change by reverting my sync-content.mjs edit and rebuilding from a clean.next: same file, same MDX error, and (before that) the expectedModule not found: Can't resolve './assets/phone-pairing/*.png'errors from the unfixed script — i.e. the un-fixed script fails exactly the way this PR fixes, confirming the root cause. The<daemon>bug is a separate, pre-existing docs-authoring issue inagentproto/tsI'm not fixing here (out of scope for this repo).next startneeds a completed build), I rannext dev(Turbopack, which compiles routes on demand rather than enumerating every static page up front) and, only for this proof, locally patched the generated (gitignored, non-committed)content/docs/verbs/pair.mdxcopy to escape that one<daemon>— purely to unblock reaching/docs/guides/phone-pairingin dev; nothing undercontent/docs/orpublic/docs/is part of this PR's diff.GET /docs/guides/phone-pairing→200next/image's static import (/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fconfirm-fingerprint.<hash>.png&...etc.) — fetched one directly:200,image/png.href="./assets/phone-pairing/phone-pairing-guide.pdf"; fetching the browser-resolved absolute pathGET /docs/guides/assets/phone-pairing/phone-pairing-guide.pdf→200,application/pdf, 7 pages (matches the source PDF).Follow-up (not in this PR)
docs/cli/verbs/pair.md's<daemon>placeholder breaksnext buildfor the entire site today (it's enumerated bygenerateStaticParams), independent of anything here. Worth a one-line fix on theagentproto/tsside (backtick it:`<daemon>`) sopnpm buildactually succeeds end to end — flagging it here since I hit it while testing, not fixing it in this PR (different repo, out of scope for this change).Never merge
Not merging this myself — reporting the PR for review.
🤖 @agentproto-bot — PR · session
sess_39ac1d77(rdv-browser: phone pairing guide page) · claude-code / subscription · auth-profileClaude Subs Agentik· modelclaude-sonnet-5· supervisorsess_d3e835f4· $6.0454 (daemon) · hostmac.home· cwdagentproto/phone-pairing-guide