progdoc/stdlayout.go
2026-02-01 15:00:26 +11:00

45 lines
870 B
Go

package progdoc
import (
"bytes"
"html/template"
"io"
)
type stdLayoutSource struct {
MainSource pageSource
}
func (s stdLayoutSource) HTML(w io.Writer, srcCtx *SourceCtx) error {
var data struct {
Meta *siteMeta
Content template.HTML
}
var content bytes.Buffer
if err := s.MainSource.HTML(&content, srcCtx); err != nil {
return err
}
data.Meta = srcCtx.Meta
data.Content = template.HTML(content.String())
return stdLayoutTemplate.Execute(w, data)
}
var stdLayoutTemplate = template.Must(template.New("stdlayout").Parse(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.Meta.Title}}</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body>
<main>
{{.Content}}
</main>
</body>
</html>
`))