diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2020-01-05 00:30:59 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2020-01-05 00:30:59 -0500 |
| commit | 9b849e00766b1dd0dfc9d603c18c90be3493b97b (patch) | |
| tree | d1c7e3070fcb1706e0af2ad89fa7858b8bfce3ca | |
| parent | 839b8f3ef95c1aae4cf55df2d9e77a411107d46b (diff) | |
| download | go-website-9b849e00766b1dd0dfc9d603c18c90be3493b97b.tar.gz go-website-9b849e00766b1dd0dfc9d603c18c90be3493b97b.tar.xz | |
The markdown files are also templates now.v0.0.5
| -rw-r--r-- | go.mod | 1 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | page/page.go | 31 |
3 files changed, 30 insertions, 4 deletions
@@ -4,6 +4,7 @@ go 1.13 require ( github.com/kr/pretty v0.1.0 // indirect + github.com/russross/blackfriday v2.0.0+incompatible github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/russross/blackfriday.v2 v2.0.0 @@ -3,6 +3,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/russross/blackfriday v2.0.0+incompatible h1:cBXrhZNUf9C+La9/YpS+UHpUT8YD6Td9ZMSU9APFcsk= +github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 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) +} |
