aboutsummaryrefslogtreecommitdiff
path: root/page/page.go
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2020-01-05 00:30:59 -0500
committerMitch Riedstra <mitch@riedstra.us>2020-01-05 00:30:59 -0500
commit9b849e00766b1dd0dfc9d603c18c90be3493b97b (patch)
treed1c7e3070fcb1706e0af2ad89fa7858b8bfce3ca /page/page.go
parent839b8f3ef95c1aae4cf55df2d9e77a411107d46b (diff)
downloadgo-website-9b849e00766b1dd0dfc9d603c18c90be3493b97b.tar.gz
go-website-9b849e00766b1dd0dfc9d603c18c90be3493b97b.tar.xz
The markdown files are also templates now.v0.0.5
Diffstat (limited to 'page/page.go')
-rw-r--r--page/page.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/page/page.go b/page/page.go
index 47e64e3..3c6a130 100644
--- a/page/page.go
+++ b/page/page.go
@@ -3,22 +3,23 @@ package page
import (
"bufio"
"bytes"
+ "fmt"
"io"
"os"
"text/template"
"time"
- "gopkg.in/russross/blackfriday.v2"
+ "github.com/russross/blackfriday"
"gopkg.in/yaml.v2"
)
type Page struct {
Name string
Head string
- Body string
Date *time.Time
Published bool
- Templates map[string]string
+ Vars map[string]interface{}
+ Markdown []byte
}
// Can be adjusted to change the base template used in rendering
@@ -94,6 +95,28 @@ func (p *Page) Read() error {
return err
}
- p.Body = string(blackfriday.Run(markdownBuf.Bytes()))
+ // p.Body = string(blackfriday.Run(markdownBuf.Bytes()))
+ p.Markdown = markdownBuf.Bytes()
return nil
}
+
+func (p *Page) RenderBody() (string, error) {
+ buf := &bytes.Buffer{}
+ t, err := template.New("Body").Parse(string(p.Markdown))
+ if err != nil {
+ return "", err
+ }
+
+ err = t.Execute(buf, p)
+ if err != nil {
+ return "", err
+ }
+
+ return string(blackfriday.Run(buf.Bytes())), nil
+
+ // return buf.String(), nil
+}
+
+func (p Page) String() string {
+ return fmt.Sprintf("Page: %s", p.Name)
+}