diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2020-02-01 11:06:24 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2020-02-01 11:08:12 +0100 |
commit | 4bedcc88d171a0886a114c604a79155d088bdbeb (patch) | |
tree | 1d6b24ebd61e55371dbc8a1e0f862eae0efc3099 | |
parent | 5ec92205b871ede6ae4b8afc755efb7d06d1ffd9 (diff) |
Fixed URL generation, added nav list generation, added page generation
stub
-rw-r--r-- | entry.go | 9 | ||||
-rw-r--r-- | main.go | 24 | ||||
-rw-r--r-- | nav.go | 16 | ||||
-rw-r--r-- | page.go | 26 | ||||
-rw-r--r-- | template.go | 12 | ||||
-rw-r--r-- | utils.go | 8 |
6 files changed, 65 insertions, 30 deletions
@@ -1,7 +1,6 @@ package main import ( - "fmt" "os" "path/filepath" "regexp" @@ -13,6 +12,7 @@ import ( */ type entry struct { name string + rawName string fullPath string } @@ -29,9 +29,10 @@ func findEntries(cfg config) (entries []Renderer, err error) { err = filepath.Walk(cfg.DocsRoot, func(p string, f os.FileInfo, e error) error { if !f.IsDir() && baseEntryRegex.MatchString(f.Name()) { - baseCaptures := baseEntryRegex.FindStringSubmatch(f.Name()) - newBaseEntry := entry{name: nameify(baseCaptures[1]), fullPath: p} - fmt.Println(newBaseEntry.name) + baseCaptures := baseEntryRegex.FindStringSubmatch(f.Name()) + newBaseEntry := entry{name: nameify(baseCaptures[1]), + rawName: baseCaptures[1], + fullPath: p} if logEntryRegex.MatchString(f.Name()) { logCaptures := logEntryRegex.FindStringSubmatch(f.Name()) @@ -5,11 +5,6 @@ import ( "os" ) -type templateData struct { - SiteTitle string - Pages map[string]page - Index int -} func main() { // show usage if config file is missing @@ -31,14 +26,15 @@ func main() { } // render all entries - var pages = make(map[string]page) - for _, e := range entries { - fmt.Println("Processing page") - e.render(pages) - fmt.Println(pages) - fmt.Println("**************") - - } - fmt.Println("----------------------------------------------------------------------------------------------") + pages := createPageMap(entries) + fmt.Println("Pages:") fmt.Println(pages) + + // create navigation item slice + navItems := createNavSlice(pages, cfg) + fmt.Println("Navigation:") + fmt.Println(navItems) + + generatePages(pages, navItems, cfg) + } @@ -0,0 +1,16 @@ +package main + +import () + +type navItem struct { + AbsoluteUrl string + Text string +} + +func createNavSlice(pages map[string]page, cfg config) (nav []navItem) { + for k, v := range pages { + newNavItem := navItem{AbsoluteUrl: cfg.BaseUrl + "/" + k, Text: v.pageName} + nav = append(nav, newNavItem) + } + return +} @@ -1,7 +1,5 @@ package main -//import "fmt" - /* * This file contains all the code related to turning entries into HTML pages */ @@ -12,8 +10,6 @@ type page struct { func (p *page) appendContent(c string) { p.content = append(p.content, c) - //fmt.Println("---------------------------------------------------------------------------------------------------------") - //fmt.Println(p) } type Renderer interface { @@ -28,7 +24,7 @@ func (e entry) render(pages map[string]page) (err error) { p := page{pageName: e.name, content: []string{md}} - pages[e.name] = p + pages[e.rawName] = p return } @@ -38,12 +34,26 @@ func (le logEntry) render(pages map[string]page) (err error) { return } - if val, ok := pages["log"]; ok { + logUrl := "log" + + if val, ok := pages[logUrl]; ok { val.appendContent(md) - pages["log"] = val + pages[logUrl] = val } else { p := page{pageName: "Log", content: []string{md}} - pages["log"] = p + pages[logUrl] = p + } + return +} + +func createPageMap(entries []Renderer) (pages map[string]page) { + pages = make(map[string]page) + for _, e := range entries { + err := e.render(pages) + if err != nil { + panic(err) + } + } return } diff --git a/template.go b/template.go new file mode 100644 index 0000000..ff69756 --- /dev/null +++ b/template.go @@ -0,0 +1,12 @@ +package main + +type templateData struct { + SiteTitle string + StylesheetUrl string + Nav []navItem + Content []string +} + +func generatePages(pages map[string]page, nav []navItem, cfg config) () { + +} @@ -20,8 +20,8 @@ func readConfig(file string) (cfg config, err error) { } func nameify(raw string) (clean string) { - clean = strings.ReplaceAll(raw, "-", " ") - clean = strings.TrimSpace(clean) - clean = strings.Title(clean) - return + clean = strings.ReplaceAll(raw, "-", " ") + clean = strings.TrimSpace(clean) + clean = strings.Title(clean) + return } |