diff options
Diffstat (limited to 'local/index.go')
| -rw-r--r-- | local/index.go | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/local/index.go b/local/index.go deleted file mode 100644 index 7b821f6..0000000 --- a/local/index.go +++ /dev/null @@ -1,71 +0,0 @@ -package local - -import ( - "fmt" - "os" - "path/filepath" - "strings" - "time" -) - -var pageIndex map[string]PageList - -// RebuildIndex can be called in order to rebuild the entire website -// index -func (p *Page) RebuildIndex() error { - pageIndex = nil - _, err := p.Index() - return err -} - -// 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 - - filepath.Walk(filepath.Dir(p.path), - func(path string, info os.FileInfo, err error) error { - if err != nil { - return err - } - - if !info.IsDir() && strings.HasSuffix(info.Name(), Suffix) { - - p2 := NewPage(strings.ReplaceAll(path, Suffix, "")) - err = p2.Read() - - if err != nil { - pageErr = err - fmt.Fprintln(os.Stderr, "Error encountered: ", err) - return err - } - - for tag, _ := range p2.Tags { - if _, ok := out[tag]; !ok { - out[tag] = []*Page{p2} - } else { - out[tag] = append(out[tag], p2) - } - } - - } - - return nil - }) - - pageIndex = out - - return out, nil -} - -func (p *Page) Time() time.Time { - return p.Date.Time -} |
