Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Render images and 3D models in the browser views

3b2bcc30534f24b4628b6365e69dcb9065115065 · Keenan Nemetz · 13d ago · parent 87bab8e1

Render images and 3D models in the browser views

A blob whose name is an image is served as that image, so the <img> a README
already emitted works and the source view can show it. An SVG keeps its source
view and previews on request. The instance introduction resolves assets/, so a
landing-page picture is no longer a broken link.

A changed image or model shows both sides in the commit, compare, and change
request diffs, where git only says "binary". The 3D viewer is a vendored
three.js bundle, loaded only when a page has a model, with a download fallback
for a reader without JavaScript or WebGL.

closes: 01M7XQ9AKKKFNEX0F679JRRYQD

server/web/templates/code.html +17−2

@@ -99,7 +99,10 @@
99 99 </nav>
100 100 <span class="code-tab-actions">
101 101 {{if eq .Mode "blob"}}
102 {{if and .IsMarkdown (not .Truncated)}}
102 {{/* Source and preview are two readings of the same text. A raster image or
103 a binary model has no source to read, so it is shown once and only
104 offers the download below. */}}
105 {{if and (or .IsMarkdown .IsImage .IsModel) (not .Binary) (not .Truncated)}}
103 106 <a class="{{if not .Preview}}active{{end}}" href="/{{.Name}}/blob/{{esc .Ref}}/{{pathurl .Path}}" hx-get="/{{.Name}}/blob/{{esc .Ref}}/{{pathurl .Path}}" hx-target="#code-main" hx-swap="outerHTML" hx-push-url="true">source</a>
104 107 <a class="{{if .Preview}}active{{end}}" href="/{{.Name}}/blob/{{esc .Ref}}/{{pathurl .Path}}?preview=1" hx-get="/{{.Name}}/blob/{{esc .Ref}}/{{pathurl .Path}}?preview=1" hx-target="#code-main" hx-swap="outerHTML" hx-push-url="true">preview</a>
105 108 {{end}}
@@ -163,7 +166,19 @@ git push -u origin {{.Ref}}</pre>
163 166
164 167 {{define "code_blob"}}
165 168 {{template "code_tabbar" .}}
166 {{if .Binary}}
169 {{if .ModelPreview}}
170 {{/* app.js imports the viewer only when it finds this element; the fallback is
171 what a reader without JavaScript or WebGL sees. */}}
172 <div class="model-viewer" data-model="/{{.Name}}/raw/{{esc .Ref}}/{{pathurl .Path}}" data-format="{{.ModelFormat}}" data-title="{{.Path}}">
173 <p class="model-fallback"><a href="/{{.Name}}/raw/{{esc .Ref}}/{{pathurl .Path}}">Download {{.Path}}</a> to open it in a 3D application.</p>
174 </div>
175 {{else if .ImagePreview}}
176 {{/* The raw route is the image: the blob page does not re-encode it, and the
177 same URL is what a README's <img> already points at. */}}
178 <figure class="media-preview">
179 <img src="/{{.Name}}/raw/{{esc .Ref}}/{{pathurl .Path}}" alt="{{.Path}}" decoding="async">
180 </figure>
181 {{else if .Binary}}
167 182 <div class="card">
168 183 <p class="muted">Binary file · {{bytes .Size}}. It is not shown inline.</p>
169 184 <p><a class="button secondary" href="/{{.Name}}/raw/{{esc .Ref}}/{{pathurl .Path}}">Download</a></p>