From bcf6d391f17a193c81ad6643f8d006de6c6abad8 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sun, 18 Jul 2021 16:27:24 -0400 Subject: Adjust the program a bit, remove clunky "head" templates. Add an example site among other improvements --- page/checkup.go | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 page/checkup.go (limited to 'page/checkup.go') diff --git a/page/checkup.go b/page/checkup.go new file mode 100644 index 0000000..c4501c2 --- /dev/null +++ b/page/checkup.go @@ -0,0 +1,85 @@ +package page + +import ( + "fmt" + "os" + "path/filepath" + "reflect" + "strings" +) + +// Checkup will return a map[string]PageList of all the pages broken down by +// the status of their fields. For instance, whehter or not they have a date +func (p *Page) Checkup() (map[string]PageList, error) { + Logger.Println("Checking up on all files...") + + out := make(map[string]PageList) + + filepath.Walk(filepath.Dir("."), + 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 { + Logger.Println("Error encountered: ", err) + return err + } + + r := reflect.ValueOf(*p2) + + for i := 0; i < r.NumField(); i++ { + key := "" + f := r.Field(i) + fi := r.Type().Field(i) + + if fi.PkgPath != "" { + continue + } + + name := fi.Name + + switch f.Interface().(type) { + case string: + if f.String() == "" { + key = fmt.Sprintf("Empty \"%s\"", name) + } else { + key = fmt.Sprintf("Not Empty \"%s\"", name) + } + case bool: + if !f.Bool() { + key = fmt.Sprintf("\"%s\" is false", name) + } else { + key = fmt.Sprintf("\"%s\" is true", name) + } + case map[string]interface{}: + case *PageTime: + if f.IsNil() { + key = fmt.Sprintf("\"%s\" is empty", name) + } + } + + if key == "" { + continue + } + + if _, ok := out[key]; !ok { + out[key] = []*Page{p2} + } else { + out[key] = append(out[key], p2) + } + + } + + } + + return nil + }) + + return out, nil +} -- cgit v1.2.3