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:
@@ -0,0 +1,40 @@
|
||||
package sites
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestRehomeText(t *testing.T) {
|
||||
const p = "/preview/0/main/"
|
||||
for in, want := range map[string]string{
|
||||
`<a href="/pricing/">`: `<a href="/preview/0/main/pricing/">`,
|
||||
`<a href="/">`: `<a href="/preview/0/main/">`,
|
||||
`<a href=/about/>`: `<a href=/preview/0/main/about/>`,
|
||||
`<a href="//cdn.example/x.js">`: `<a href="//cdn.example/x.js">`,
|
||||
`<a href="https://other.example/">`: `<a href="https://other.example/">`,
|
||||
`<a href="#top">`: `<a href="#top">`,
|
||||
`<img src='/i.png' srcset="/a.png 1x, /b.png 2x, https://c/d.png 3x">`: `<img src='/preview/0/main/i.png' srcset="/preview/0/main/a.png 1x, /preview/0/main/b.png 2x, https://c/d.png 3x">`,
|
||||
`<meta http-equiv="refresh" content="0; url=/new/">`: `<meta http-equiv="refresh" content="0; url=/preview/0/main/new/">`,
|
||||
`<div style="background:url('/bg.jpg')">`: `<div style="background:url('/preview/0/main/bg.jpg')">`,
|
||||
`<form action="/send">`: `<form action="/preview/0/main/send">`,
|
||||
} {
|
||||
if got := RehomeText(in, p, false); got != want {
|
||||
t.Errorf("%s\n got %s\nwant %s", in, got, want)
|
||||
}
|
||||
}
|
||||
if got := RehomeText(`a{background:url(/x.png)} <a href="/">`, p, true); got != `a{background:url(/preview/0/main/x.png)} <a href="/">` {
|
||||
t.Errorf("css: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSlug(t *testing.T) {
|
||||
taken := []Preview{{Branch: "supermarket/page-1", Slug: "supermarket-page-1"}}
|
||||
for branch, want := range map[string]string{
|
||||
"main": "main",
|
||||
"supermarket/page-1": "supermarket-page-1",
|
||||
"Supermarket/Page_1": "supermarket-page-1-2",
|
||||
"///": "branch",
|
||||
} {
|
||||
if got := Slug(branch, taken); got != want {
|
||||
t.Errorf("%q: %q, want %q", branch, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user