aboutsummaryrefslogtreecommitdiff
path: root/page/page.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2023-01-07 13:31:23 -0500
committerMitchell Riedstra <mitch@riedstra.dev>2023-01-07 13:31:23 -0500
commitca33a035c779ae14fb6330c8801c75f49dd1bb79 (patch)
treedeaabaf15d6d91079a68f247e46070399e4343ee /page/page.go
parent97dd660925434be537cd9a49a1d0c893b223e357 (diff)
downloadgo-website-ca33a035c779ae14fb6330c8801c75f49dd1bb79.tar.gz
go-website-ca33a035c779ae14fb6330c8801c75f49dd1bb79.tar.xz
Add an internal caching option. It performs quite well.v0.0.22
Also refactor and clean up most linter warnings.
Diffstat (limited to 'page/page.go')
-rw-r--r--page/page.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/page/page.go b/page/page.go
index 214021e..03d1f1e 100644
--- a/page/page.go
+++ b/page/page.go
@@ -59,7 +59,7 @@ type Page struct {
Vars map[string]interface{}
// Keys of vars to be included when RenderJson is called, all vars are
// omitted if empty.
- JsonVars []string
+ JSONVars []string
markdown []byte
}
@@ -69,7 +69,7 @@ type Page struct {
var Global interface{}
// Funcs accessible to the templates.
-var Funcs template.FuncMap = template.FuncMap{
+var Funcs = template.FuncMap{
"join": strings.Join,
"split": strings.Split,
"toLower": strings.ToLower,
@@ -191,7 +191,12 @@ func (p *Page) Render(wr io.Writer) error {
t = t.Funcs(Funcs)
- return t.Execute(wr, p)
+ err = t.Execute(wr, p)
+ if err != nil {
+ return fmt.Errorf("while executing template: %w", err)
+ }
+
+ return nil
}
// Read in the special markdown file format for the website off of the disk.
@@ -253,6 +258,7 @@ func (p *Page) Read() error {
// this is called in the base template.
func (p *Page) RenderBody() (string, error) {
s, err := p.GetMarkdown()
+
return string(blackfriday.Run([]byte(s))), err
}
@@ -278,3 +284,15 @@ func (p *Page) GetMarkdown() (string, error) {
func (p Page) String() string {
return fmt.Sprintf("Page: %s", p.path)
}
+
+// setRenderingMarkdownOnly simply sets the special vars field,
+// "RenderingMarkdownOnly" to be true.
+func (p *Page) setRenderingMarkdownOnly() {
+ if p.Vars != nil {
+ p.Vars["RenderingMarkdownOnly"] = true
+ } else {
+ p.Vars = map[string]interface{}{
+ "RenderingMarkdownOnly": true,
+ }
+ }
+}