aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--entry.go9
-rw-r--r--main.go24
-rw-r--r--nav.go16
-rw-r--r--page.go26
-rw-r--r--template.go12
-rw-r--r--utils.go8
6 files changed, 65 insertions, 30 deletions
diff --git a/entry.go b/entry.go
index 01abf50..ad4cca3 100644
--- a/entry.go
+++ b/entry.go
@@ -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())
diff --git a/main.go b/main.go
index cab9fcc..ad5e819 100644
--- a/main.go
+++ b/main.go
@@ -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)
+
}
diff --git a/nav.go b/nav.go
new file mode 100644
index 0000000..e7c9579
--- /dev/null
+++ b/nav.go
@@ -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
+}
diff --git a/page.go b/page.go
index f9bb5b1..0d0b1dd 100644
--- a/page.go
+++ b/page.go
@@ -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) () {
+
+}
diff --git a/utils.go b/utils.go
index c78cbcc..42780c4 100644
--- a/utils.go
+++ b/utils.go
@@ -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
}