From f2082a0d72f9359be02182883a1e1190d8b1b215 Mon Sep 17 00:00:00 2001 From: Mitchell Riedstra Date: Sun, 18 Jul 2021 16:04:06 -0400 Subject: More changes to how the website functions --- cmd/server/feed.go | 4 ++ example-site/blog/first-post.md | 5 +-- example-site/blog/second-post.md | 1 + example-site/blog/unpublished-post.md | 22 +++++++++ example-site/checkup.md | 62 +++++++++++++++++++++++++ example-site/inc/base.html | 16 +++---- example-site/index.md | 5 +++ example-site/multi-tag-page.md | 1 + example-site/untagged-page.md | 1 + page/checkup.go | 85 +++++++++++++++++++++++++++++++++++ page/misc.go | 31 +++++++++++++ 11 files changed, 220 insertions(+), 13 deletions(-) create mode 100644 example-site/blog/unpublished-post.md create mode 100644 example-site/checkup.md create mode 100644 page/checkup.go create mode 100644 page/misc.go diff --git a/cmd/server/feed.go b/cmd/server/feed.go index 073097b..c478365 100644 --- a/cmd/server/feed.go +++ b/cmd/server/feed.go @@ -175,6 +175,10 @@ func (a *App) FeedHandler(w http.ResponseWriter, r *http.Request) { break } + if !p.Published { + continue + } + content := &bytes.Buffer{} err := p.Render(content) if err != nil { diff --git a/example-site/blog/first-post.md b/example-site/blog/first-post.md index 42ef931..f9c5ea2 100644 --- a/example-site/blog/first-post.md +++ b/example-site/blog/first-post.md @@ -1,13 +1,10 @@ --- title: 'Blog Post #1' -# head: "This is optional" description: My example description - date: 07.02.2021 15:00:00 EDT - +published: true tags: Blog: - |--- `{{.Date.Time.Format "Monday January 2 2006"}}` diff --git a/example-site/blog/second-post.md b/example-site/blog/second-post.md index f8abef2..34fe318 100644 --- a/example-site/blog/second-post.md +++ b/example-site/blog/second-post.md @@ -2,6 +2,7 @@ title: 'Blog Post #2' description: My example description for blog post #2 date: 07.14.2021 15:00:00 EDT +published: true tags: Blog: |--- diff --git a/example-site/blog/unpublished-post.md b/example-site/blog/unpublished-post.md new file mode 100644 index 0000000..3088250 --- /dev/null +++ b/example-site/blog/unpublished-post.md @@ -0,0 +1,22 @@ +--- +title: 'Unpublished Blog Post' +description: My example description for an unpublished blog post +date: 07.15.2021 15:00:00 EDT + +# Defaults to false +# published: false + +tags: + Blog: +|--- + +`{{.Date.Time.Format "Monday January 2 2006"}}` + +# {{.Title}} + +This is an example unpublished blog post. + +Description: + +> {{.Description}} + diff --git a/example-site/checkup.md b/example-site/checkup.md new file mode 100644 index 0000000..f7d7a88 --- /dev/null +++ b/example-site/checkup.md @@ -0,0 +1,62 @@ +--- +title: Example checkup page +description: Showing the output of one of the internal checkup mechanisms + +|--- + +# {{.Title}} + +# Status + +{{range $key, $val := .Checkup}} +## {{$key}}: +{{range $page := $val}} +``` +{{$page}} +{{$page.EncodeYaml nil}} +``` +{{end}} +{{end}} +## Raw + +``` +{{.EncodeYaml .Checkup}} +``` + +## Recent Blog Entries: + +[Atom Feed](/{{.Global.App.FeedPrefix}}/Blog?limit=5&content) + +{{range $val := .Index.Blog.SortDate}} + * [{{$val.Date.Time.Format "2006-01-02"}} {{$val.Title}}]({{$val.Path}}){{end}} + +## Published Blog Entries: + +{{range $val := .Index.Blog.SortDate}}{{if $val.Published}} + * [{{$val.Date.Time.Format "2006-01-02"}} * {{$val.Title}}]({{$val.Path}}){{end}}{{end}} + +## Some internals + + +#### Global vars: + +``` +{{.Global}} + +"App" under Global vars: +{{.Global.App}} +``` + +#### Page Index + +{{range $key, $val := .Index}} +``` +### {{$key}}: + +{{range $v2 := $val}} +{{$v2.StringDetail}}{{end}} +``` + + +{{end}} + diff --git a/example-site/inc/base.html b/example-site/inc/base.html index 959c7d6..2f93ec7 100644 --- a/example-site/inc/base.html +++ b/example-site/inc/base.html @@ -6,15 +6,13 @@ - - - - + + {{if .AuthorName }} + + {{else if .Global.App.Author.Name }} + + {{else}} + {{end}} {{if .Title}} {{.Title}} diff --git a/example-site/index.md b/example-site/index.md index 6d292b5..42b0181 100644 --- a/example-site/index.md +++ b/example-site/index.md @@ -21,6 +21,11 @@ it. {{range $val := .Index.Blog.SortDate}} * [{{$val.Date.Time.Format "2006-01-02"}} {{$val.Title}}]({{$val.Path}}){{end}} +## Published Blog Entries: + +{{range $val := .Index.Blog.SortDate}}{{if $val.Published}} + * [{{$val.Date.Time.Format "2006-01-02"}} * {{$val.Title}}]({{$val.Path}}){{end}}{{end}} + ## Some internals diff --git a/example-site/multi-tag-page.md b/example-site/multi-tag-page.md index a1a61d2..6e3b4f6 100644 --- a/example-site/multi-tag-page.md +++ b/example-site/multi-tag-page.md @@ -4,6 +4,7 @@ description: A page with several tags added to it date: 07.02.2021 15:00:00 EDT authorname: Someone Else # authoremail: someoneelse@example.com +published: true tags: Blog: Automotive: diff --git a/example-site/untagged-page.md b/example-site/untagged-page.md index aa8400f..c55274e 100644 --- a/example-site/untagged-page.md +++ b/example-site/untagged-page.md @@ -2,6 +2,7 @@ title: Untagged page description: A page with no tags added to it date: 07.02.2021 15:00:00 EDT +published: true tags: |--- 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 +} diff --git a/page/misc.go b/page/misc.go new file mode 100644 index 0000000..0dbd059 --- /dev/null +++ b/page/misc.go @@ -0,0 +1,31 @@ +package page + +import ( + "encoding/json" + + "gopkg.in/yaml.v3" +) + +func (p Page) EncodeYaml(data interface{}) string { + if data == nil { + data = p + } + + b, err := yaml.Marshal(data) + if err != nil { + Logger.Println("Encountered error in EncodeYaml: ", err) + } + return string(b) +} + +func (p Page) EncodeJson(data interface{}) string { + if data == nil { + data = p + } + + b, err := json.MarshalIndent(data, "", " ") + if err != nil { + Logger.Println("Encountered error in EncodeJson: ", err) + } + return string(b) +} -- cgit v1.2.3