aboutsummaryrefslogtreecommitdiff
path: root/page/page.go
diff options
context:
space:
mode:
Diffstat (limited to 'page/page.go')
-rw-r--r--page/page.go58
1 files changed, 52 insertions, 6 deletions
diff --git a/page/page.go b/page/page.go
index b2cc3e1..adb2362 100644
--- a/page/page.go
+++ b/page/page.go
@@ -46,11 +46,11 @@ import (
// The exported fields can be filled in the yaml at the top of a page and
// utilized within.
type Page struct {
- path string
- Title string
- Description string
- AuthorName string
- AuthorEmail string
+ path string
+ DefaultTitle string `yaml:"title"`
+ DefaultDescription string `yaml:"description"`
+ AuthorName string
+ AuthorEmail string
// Tags to apply to the page in question. Useful for Index()
Tags map[string]interface{}
Date *PageTime
@@ -76,8 +76,14 @@ var CacheIndex = true
// backend.
var FileSystem = os.DirFS(".")
+// TemplateDirectory is the parent directory which templates are stored,
+// usually the BaseTemplate is stored here as well, though it does not
+// have to be. Currently this is used for the 4xx and 5xx pages. ( 4xx.md
+// and 5xx.md respectively.
+var TemplateDirectory = "tpl"
+
// BaseTemplate can be adjusted to change the base template used in rendering.
-var BaseTemplate = "inc/base.html"
+var BaseTemplate = "tpl/base.md"
// Suffix is applied to all pages for reading off of the disk.
var Suffix = ".md"
@@ -107,6 +113,46 @@ func (p Page) Path() string {
return filepath.ToSlash(p.path)
}
+// Title returns `DefaultTitle` unless `.Vars.Title` is
+// set, then it returns that instead.
+func (p Page) Title() string {
+ if p.Vars == nil {
+ return p.DefaultTitle
+ }
+
+ t, ok := p.Vars["Title"]
+ if !ok {
+ return p.DefaultTitle
+ }
+
+ nt, ok := t.(string)
+ if !ok {
+ return p.DefaultTitle
+ }
+
+ return nt
+}
+
+// Description returns `DefaultDescription` unless `.Vars.Description` is
+// set, then it returns that instead.
+func (p Page) Description() string {
+ if p.Vars == nil {
+ return p.DefaultDescription
+ }
+
+ t, ok := p.Vars["Description"]
+ if !ok {
+ return p.DefaultDescription
+ }
+
+ nt, ok := t.(string)
+ if !ok {
+ return p.DefaultDescription
+ }
+
+ return nt
+}
+
// Global is specifically for use inside of a page markdown file or
// in a base template. This simply returns the package Global variable.
func (p *Page) Global() interface{} {