Skip to content

Move blob rendering behind a viewer registry - #16

Merged
tamnd merged 1 commit into
mainfrom
viewer-framework
Jun 11, 2026
Merged

tamnd merged 1 commit into
mainfrom
viewer-framework

Conversation

@tamnd

@tamnd tamnd commented Jun 11, 2026

Copy link
Copy Markdown
Owner

The blob page hardwired its file types in three places: the classifyBlob enum, the handleBlob switch, and an if/else chain in blob.tmpl. Every new preview meant touching all three.

This introduces server/viewer, an ordered registry of small Match/Render renderers. The server walks it, first match wins, and a render error degrades to the next match instead of failing the page. The code viewer matches every non-binary file and sits last, so text always renders. Structural blob states (symlink, LFS pointer, too big, empty) stay in the handler: they are states of the record, not content.

What moved, what changed:

  • highlight, markdown and octicon code move to server/viewer with exported names; behavior unchanged, golden tests moved along
  • the raw endpoint serves through http.ServeContent over the shared MIME table, so media files get Range/HEAD for free when the audio and video viewers land
  • the Preview/Code toggle is computed server side by probing the registry without the plain flag, fixing the toggle for any future rich text viewer, not just markdown
  • blob.tmpl shrinks to structural notices plus the viewer fragment

No new file types in this PR. Spec 2011 doc 18, PR 1 of 4: media, tabular (csv/tsv/parquet) and docx viewers follow.

The blob page used to hardwire its file types: a closed enum in
classifyBlob, a switch in handleBlob, and an if/else chain in the
template. Adding a preview meant touching all three.

Now server/viewer owns content rendering. Each file type is one
Renderer behind a small Match/Render interface and the server walks
an ordered registry: first match wins, a render error falls through
to the next match, and the code viewer sits last so any text file
still renders. Structural states (symlink, LFS, too big, empty)
stay in the handler since they describe the record, not the content.

The highlight, markdown and octicon code moves into the new package
unchanged apart from exported names. The raw endpoint now serves
through http.ServeContent with the shared MIME table, which buys
Range and HEAD support for the media viewers coming next.

The Preview/Code toggle is computed server side: on a plain view the
registry is probed without the plain flag, so the toggle stays
visible on files whose rich viewer stepped aside.

Spec 2011 doc 18, PR 1 of 4.
@tamnd
tamnd merged commit 8685a0b into main Jun 11, 2026
3 checks passed
@tamnd
tamnd deleted the viewer-framework branch June 11, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant