Separate out the HTML template

This commit is contained in:
2026-04-10 09:15:39 +02:00
parent 6a09fe4d98
commit fe99756cbd
3 changed files with 50 additions and 44 deletions

46
main.go
View File

@@ -30,49 +30,7 @@ var md = goldmark.New(
goldmark.WithRendererOptions(html.WithUnsafe()),
)
var tmpl = template.Must(template.New("").Parse(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{.Title}} — datascape</title>
<link rel="stylesheet" href="/_/style.css">
</head>
<body>
<header>
<nav class="breadcrumb">
<a href="/">~</a>
{{range .Crumbs}}<span class="sep">/</span><a href="{{.URL}}">{{.Name}}</a>{{end}}
</nav>
{{if .CanEdit}}<a class="edit-btn" href="?edit">EDIT</a>{{end}}
</header>
<main>
{{if .EditMode}}
<form class="edit-form" method="POST" action="{{.PostURL}}">
<textarea name="content" autofocus>{{.RawContent}}</textarea>
<div class="form-actions">
<button class="btn-save" type="submit">Save</button>
<a class="btn-cancel" href="{{.PostURL}}">Cancel</a>
</div>
</form>
{{else}}
{{if .Content}}<div class="content">{{.Content}}</div>{{end}}
{{if .Entries}}
<div class="listing">
<div class="listing-header">Contents</div>
{{range .Entries}}
<div class="listing-item">
<span class="icon">{{.Icon}}</span>
<a href="{{.URL}}">{{.Name}}</a>
<span class="meta">{{.Meta}}</span>
</div>
{{end}}
</div>
{{else if not .Content}}<p class="empty">Empty folder — <a href="?edit">create index.md</a></p>{{end}}
{{end}}
</main>
</body>
</html>`))
var tmpl = template.Must(template.New("page.html").ParseFS(assets, "assets/page.html"))
type crumb struct{ Name, URL string }
type entry struct{ Icon, Name, URL, Meta string }
@@ -301,7 +259,7 @@ func buildCrumbs(urlPath string) []crumb {
func pageTitle(urlPath string) string {
if urlPath == "/" {
return "home"
return "Datascape"
}
parts := strings.Split(strings.Trim(urlPath, "/"), "/")
return parts[len(parts)-1]