aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-07-18 16:04:06 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-07-18 16:04:06 -0400
commitf2082a0d72f9359be02182883a1e1190d8b1b215 (patch)
tree7856590caa92fe0e71861c85546cdabe0bea16ca
parent8b1d8bf26452f3ce8b38228a39755a6b8e18775a (diff)
downloadgo-website-f2082a0d72f9359be02182883a1e1190d8b1b215.tar.gz
go-website-f2082a0d72f9359be02182883a1e1190d8b1b215.tar.xz
More changes to how the website functions
-rw-r--r--cmd/server/feed.go4
-rw-r--r--example-site/blog/first-post.md5
-rw-r--r--example-site/blog/second-post.md1
-rw-r--r--example-site/blog/unpublished-post.md22
-rw-r--r--example-site/checkup.md62
-rw-r--r--example-site/inc/base.html16
-rw-r--r--example-site/index.md5
-rw-r--r--example-site/multi-tag-page.md1
-rw-r--r--example-site/untagged-page.md1
-rw-r--r--page/checkup.go85
-rw-r--r--page/misc.go31
11 files changed, 220 insertions, 13 deletions
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 @@
<link id="maincss" rel="stylesheet" href="/static/style.css" defer>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="author" content="{{.Global.App.Author.Name}}">
- <meta name="description" content="{{.Global.App.Description}}">
-
- <!--
- <link rel="apple-touch-icon" sizes="180x180" href="/static/apple-touch-icon.png">
- <link rel="icon" type="image/png" sizes="32x32" href="/static/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png">
- <link rel="manifest" href="/static/site.webmanifest">
- -->
+
+ {{if .AuthorName }}
+ <meta name="author" content="{{.AuthorName}}">
+ {{else if .Global.App.Author.Name }}
+ <meta name="author" content="{{.Global.App.Author.Name}}">
+ {{else}}
+ {{end}}
{{if .Title}}
<title>{{.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)
+}