diff options
Diffstat (limited to 'page')
| -rw-r--r-- | page/http.go | 10 | ||||
| -rw-r--r-- | page/page.go | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/page/http.go b/page/http.go index 7e1d780..b3622be 100644 --- a/page/http.go +++ b/page/http.go @@ -8,6 +8,7 @@ import ( ) func SetupHandlers() { + http.HandleFunc("/rebuildIndex/", RebuildIndexHandler) http.Handle("/static/", StaticHandler()) http.HandleFunc("/", PageHandler) } @@ -43,6 +44,15 @@ func PageHandler(w http.ResponseWriter, r *http.Request) { } +func RebuildIndexHandler(w http.ResponseWriter, r *http.Request) { + if r.Method != "POST" { + pageIndex = nil + p := &Page{Path: "index"} + _, _ = p.Index() + } + return +} + func StaticHandler() (h http.Handler) { return http.StripPrefix("/static/", http.FileServer(http.Dir("static"))) } diff --git a/page/page.go b/page/page.go index 6e1d7d5..c5230c6 100644 --- a/page/page.go +++ b/page/page.go @@ -135,10 +135,17 @@ func (p Page) String() string { return fmt.Sprintf("Page: %s", p.Path) } +var pageIndex map[string]PageList + // Index returns a map of all pages below the current Page's Path seperated // into their respective tags If a Page has multiple tags it will be listed // under each func (p *Page) Index() (map[string]PageList, error) { + if pageIndex != nil { + return pageIndex, nil + } + fmt.Fprintln(os.Stderr, "Rebuilding index...") + out := make(map[string]PageList) var pageErr error @@ -173,5 +180,7 @@ func (p *Page) Index() (map[string]PageList, error) { return nil }) + pageIndex = out + return out, nil } |
