commit ef730963ae12f3f09cf66f33d94b7b91db6e318a
parent a552991c53ca03347904d63925e2e334f1c7550b
Author: gearsix <gearsix@tuta.io>
Date: Wed, 18 Aug 2021 21:03:36 +0100
added Title, minor bugfix
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/page.go b/page.go
@@ -98,6 +98,16 @@ func lastFileMod(fpath string) time.Time {
return t
}
+func titleFromPath(path string) (title string) {
+ if title = filepath.Base(path); title == "/" {
+ title = "Home"
+ }
+ title = strings.TrimSuffix(title, filepath.Ext(title))
+ title = strings.ReplaceAll(title, "-", " ")
+ title = strings.Title(title)
+ return
+}
+
var contentExts = [5]string{
".txt", // plain-text
".html", // HTML
@@ -213,6 +223,7 @@ 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
@@ -238,6 +249,7 @@ type Nav struct {
// Updated is set to time.Now(). Any other values will simply be initialised.
func NewPage(path string, updated time.Time) Page {
return Page{
+ Title: titleFromPath(path),
Slug: filepath.Base(path),
Path: path,
Nav: Nav{},
diff --git a/pagr.go b/pagr.go
@@ -65,8 +65,8 @@ func main() {
log.Printf("loaded %d template files", len(t))
htmlc := 0
- assetc := copyAssets(wg, config)
var wg sync.WaitGroup
+ assetc := copyAssets(wg, config)
for _, pg := range p {
var tmpl suti.Template
tmpl, err = findTemplate(pg, t)