Phase 5 part 2: preview any branch of a site

Sites → Previews builds a branch with Hugo (drafts included) and serves it
under /preview/<site>/<branch>/, links rewritten to stay inside, behind a
sandboxing CSP so a branch's scripts can't act on the app or phone home.
The image now builds Hugo v0.170.1 from source; Alpine's 0.147.2 couldn't
build the site. Hugo's errors show their innermost cause.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 14:02:23 -07:00
co-authored by Claude Opus 5.5
parent 1152cd448b
commit 233c6ac630
13 changed files with 722 additions and 5 deletions
+1
View File
@@ -62,6 +62,7 @@
{{if eq .ID "sites"}}
<div class="subnav">
<a href="/sites" {{if eq $nav "sites/site"}}aria-current="page"{{end}}>Sections and pages</a>
<a href="/sites/previews" {{if eq $nav "sites/previews"}}aria-current="page"{{end}}>Previews</a>
</div>
{{end}}
{{if eq .ID "prospects"}}
@@ -0,0 +1,53 @@
{{define "content"}}{{with .Data}}{{$d := .}}
<div class="heading"><h1>Previews</h1></div>
<p class="lede">See a branch of your website before it's merged. Supermarket builds the branch with Hugo, drafts included, and serves it here. Your live site isn't touched. Pull requests from Supermarket are branches too, so this is where you check a new page.</p>
{{if not .Sites}}
<section class="card empty"><p>Add your website and its Hugo repository under <a href="/settings/profile">Settings → Profile</a> first.</p></section>
{{else}}
{{if gt (len .Sites) 1}}<nav class="tabs">{{range .Sites}}<a href="/sites/previews?site={{.Index}}" {{if and $d.Current (eq .Index $d.Current.Index)}}aria-current="page"{{end}}>{{.URL}}</a>{{end}}</nav>{{end}}
{{if not .Hugo}}<p class="warn-text">There's no Hugo in Supermarket's image, so previews can't be built.</p>{{end}}
{{with .Current}}{{$cur := .}}
{{if .Err}}
<section class="card"><p class="warn-text">{{.URL}}: {{.Err}}. Set it under <a href="/settings/profile">Settings → Profile</a>.</p></section>
{{else if not $d.HasSynced}}
<section class="card empty"><p>Read {{.Repo}} under <a href="/sites?site={{.Index}}">Sections and pages</a> first.</p></section>
{{else}}
<p class="help">Branches of {{.Repo}}, as of the last read {{ago $d.Synced.At}}. Building reads the repository again first, so it builds the branch's latest commit. A preview can't send anything anywhere or change anything in Supermarket, and analytics don't count it.</p>
<div class="table-wrap"><table>
<thead><tr><th>Branch</th><th>Latest commit</th><th>Preview</th><th></th></tr></thead>
<tbody>
{{range $d.Rows}}
<tr>
<td><strong>{{.Name}}</strong>{{if .Published}} <span class="badge published">published</span>{{end}}</td>
<td class="small">{{.Subject}}<br><span class="muted">{{ago .At}}</span></td>
<td class="small">
{{with .Preview}}
{{if .Commit}}Built {{ago .At}}{{end}}
{{with .Err}}<br><span class="error-text">The last build failed: {{.}}</span>{{end}}
{{else}}<span class="muted">None yet</span>{{end}}
{{if .Stale}}<br><span class="warn-text">The branch has moved on since.</span>{{end}}
</td>
<td>
<div class="row-actions">
{{with .Link}}<a class="button" href="{{.}}" target="_blank" rel="noopener">Open preview ↗</a>{{end}}
<form method="post" action="/sites/previews/build">
<input type="hidden" name="site" value="{{$cur.Index}}"><input type="hidden" name="branch" value="{{.Name}}">
<button type="submit" class="secondary" data-busy="Building…" {{if or (not $d.Hugo) (not $d.Gitea)}}disabled{{end}}>{{if .Preview}}Build again{{else}}Build preview{{end}}</button>
</form>
{{if .Preview}}
<form method="post" action="/sites/previews/delete">
<input type="hidden" name="site" value="{{$cur.Index}}"><input type="hidden" name="branch" value="{{.Name}}">
<button type="submit" class="secondary">Delete</button>
</form>
{{end}}
</div>
</td>
</tr>
{{end}}
</tbody>
</table></div>
{{end}}
{{end}}
{{end}}
{{end}}{{end}}