commit c06ff7c0d3f1636f36003495af45b8c453a90ec1
parent af2bc729ac896a6131541a77f19e7f338e5ee669
Author: gearsix <gearsix@tuta.io>
Date: Sat, 2 Oct 2021 11:37:14 +0100
moved Page.Title to Page.Meta['Title']
This way the user can override the 'Title' value in their meta files if
they have a preferred name to the default.
Bugfix in Page.Build that was causing the Execute errors to get
shadowed.
Diffstat:
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/page.go b/page.go
@@ -223,7 +223,6 @@ func pagePath(root, path string) string {
// gets passed to templates for execution after Content has been loaded.
// This is the data structure to reference when writing a template!
type Page struct {
- Title string
Slug string
Path string
Nav Nav
@@ -244,16 +243,15 @@ type Nav struct {
Crumbs []*Page
}
-// NewPage returns a Page with init values. `.Title` will be set to the
-// value returned by titleFromPath(path), `.Path` will be set to `path`.
+// NewPage returns a Page with init values. `.Path` will be set to `path`.
// Updated is set to time.Now(). Any other values will simply be initialised.
func NewPage(path string, updated time.Time) Page {
+ defaultMeta := Meta{"Title": titleFromPath(path), "Description": "TODO"}
return Page{
- Title: titleFromPath(path),
Slug: filepath.Base(path),
Path: path,
Nav: Nav{},
- Meta: make(Meta),
+ Meta: defaultMeta,
Contents: make([]string, 0),
Assets: make([]string, 0),
Updated: updated.Format(timefmt),
@@ -364,10 +362,11 @@ func CopyFile(src, dst string) (err error) {
}
func (p *Page) Build(outDir string, t suti.Template) (out string, err error) {
- if outb, err := t.Execute(p); err == nil {
+ var buf bytes.Buffer
+ if buf, err = t.Execute(p); err == nil {
out = filepath.Join(outDir, p.Path, "index.html")
if err = os.MkdirAll(filepath.Dir(out), 0755); err == nil {
- err = os.WriteFile(out, outb.Bytes(), 0644)
+ err = os.WriteFile(out, buf.Bytes(), 0644)
}
}
return out, err