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/markdown.go +44−1
| @@ -19,6 +19,7 @@ import ( | |||
| 19 | 19 | "github.com/yuin/goldmark/extension" | |
| 20 | 20 | "github.com/yuin/goldmark/text" | |
| 21 | 21 | ||
| 22 | "rodent.software/vole/forge/instancerepo" | ||
| 22 | 23 | "rodent.software/vole/metadata" | |
| 23 | 24 | ) | |
| 24 | 25 | ||
| @@ -41,6 +42,10 @@ type treeDoc struct { | |||
| 41 | 42 | Repo string | |
| 42 | 43 | Ref string | |
| 43 | 44 | Path string | |
| 45 | // Instance marks the introduction written in the instance repository. It | ||
| 46 | // has no Ref to resolve against, and the only files it can name are the | ||
| 47 | // customization assets under assets/, which are served from a fixed URL. | ||
| 48 | Instance bool | ||
| 44 | 49 | // Mentions links @name to the account it addresses. It is set for the | |
| 45 | 50 | // documents that address people — an issue, a comment, a change request, a | |
| 46 | 51 | // release note — and left off for a README or a documentation file, where a | |
| @@ -67,8 +72,12 @@ func (w *Web) renderMarkdown(repoName, src string) template.HTML { | |||
| 67 | 72 | // from a form that ends up in a page, so it goes through the same parser and | |
| 68 | 73 | // sanitizer as an issue body. It has no repository and addresses nobody: `#123` stays literal | |
| 69 | 74 | // and `@name` stays a name. | |
| 75 | // | ||
| 76 | // A relative link in it is a path in the instance repository, and the only | ||
| 77 | // files that repository serves are the assets, so `` | ||
| 78 | // finds the picture instead of resolving against the landing page's URL. | ||
| 70 | 79 | func (w *Web) renderInstanceMarkdown(src string) template.HTML { | |
| 71 | return w.renderTreeMarkdown(treeDoc{}, src) | ||
| 80 | return w.renderTreeMarkdown(treeDoc{Instance: true}, src) | ||
| 72 | 81 | } | |
| 73 | 82 | ||
| 74 | 83 | // renderTreeMarkdown is renderMarkdown for a document that has a place in the | |
| @@ -129,6 +138,9 @@ func rewriteTreeLinks(doc ast.Node, tree treeDoc) { | |||
| 129 | 138 | // previews the file and then jumps. `..` is clamped at the repository root rather | |
| 130 | 139 | // than allowed to walk out of it. | |
| 131 | 140 | func docHref(doc treeDoc, dest string, image bool) (string, bool) { | |
| 141 | if doc.Instance { | ||
| 142 | return instanceAssetHref(dest) | ||
| 143 | } | ||
| 132 | 144 | if doc.Ref == "" || dest == "" || strings.HasPrefix(dest, "/") { | |
| 133 | 145 | return "", false | |
| 134 | 146 | } | |
| @@ -180,6 +192,37 @@ func docHref(doc treeDoc, dest string, image bool) (string, bool) { | |||
| 180 | 192 | } | |
| 181 | 193 | } | |
| 182 | 194 | ||
| 195 | // instanceAssetHref points a relative destination in the instance introduction | ||
| 196 | // at the customization asset it names. CSS, images and fonts under assets/ are | ||
| 197 | // the only files the instance repository serves, so anything else is left as | ||
| 198 | // written rather than linked to a route that does not exist. A fragment and | ||
| 199 | // query are kept, and `..` is clamped at the repository root. | ||
| 200 | func instanceAssetHref(dest string) (string, bool) { | ||
| 201 | if dest == "" || strings.HasPrefix(dest, "/") { | ||
| 202 | return "", false | ||
| 203 | } | ||
| 204 | u, err := url.Parse(dest) | ||
| 205 | if err != nil || u.Scheme != "" || u.Host != "" { | ||
| 206 | return "", false | ||
| 207 | } | ||
| 208 | name, suffix := dest, "" | ||
| 209 | if i := strings.IndexAny(dest, "?#"); i >= 0 { | ||
| 210 | name, suffix = dest[:i], dest[i:] | ||
| 211 | } | ||
| 212 | if name == "" { | ||
| 213 | return "", false | ||
| 214 | } | ||
| 215 | target := strings.TrimPrefix(path.Clean("/"+name), "/") | ||
| 216 | if !strings.HasPrefix(target, instancerepo.AssetsPrefix) { | ||
| 217 | return "", false | ||
| 218 | } | ||
| 219 | rel := strings.TrimPrefix(target, instancerepo.AssetsPrefix) | ||
| 220 | if rel == "" { | ||
| 221 | return "", false | ||
| 222 | } | ||
| 223 | return instanceAssetPrefix + instancerepo.AssetsPrefix + pathURL(rel) + suffix, true | ||
| 224 | } | ||
| 225 | |||
| 183 | 226 | func linkCrossReferences(repoName, src string) string { | |
| 184 | 227 | var out strings.Builder | |
| 185 | 228 | inFence := false | |