pagr

A 'static site generator', built using dati.
Log | Files | Refs | Atom

commit b6aaa0eef43e00498993e11470bc20edfa526d11
parent c95a59b9958924eaddddcf2d5e8034eba02b80e0
Author: gearsix <gearsix@tuta.io>
Date:   Thu,  5 Aug 2021 11:49:11 +0100

changed Title -> Slug

Diffstat:
Mpage.go | 14++------------
Mpage_test.go | 3++-
2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/page.go b/page.go @@ -77,16 +77,6 @@ func BuildSitemap(pages []Page) []Page { return pages } -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 -} - func lastFileMod(fpath string) time.Time { t := time.Now() // default/error ret if fd, e := os.Stat(fpath); e != nil { @@ -223,7 +213,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 Meta Meta @@ -248,7 +238,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{}, Meta: make(Meta), diff --git a/page_test.go b/page_test.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "path/filepath" "os" "time" "testing" @@ -32,7 +33,7 @@ func validateContents(t *testing.T, pages []Page, e error) { var last time.Time for i, p := range pages { - if len(p.Title) == 0 { + if len(p.Slug) == 0 && p.Slug != filepath.Base(p.Path) { t.Error("empty Title for page:", p) } if len(p.Path) == 0 {