Commit 24bdb433 authored by Maxime's avatar Maxime

Changed .Var to .Doc in Markdown templates

Put the title into the .Doc variables as well.
Changed the test template file to use new names.
parent 97dcc79a
...@@ -20,9 +20,8 @@ const ( ...@@ -20,9 +20,8 @@ const (
type MarkdownData struct { type MarkdownData struct {
middleware.Context middleware.Context
Var map[string]interface{} Doc map[string]interface{}
Title string markdown string
Markdown string
} }
// Process processes the contents of a page in b. It parses the metadata // Process processes the contents of a page in b. It parses the metadata
...@@ -69,7 +68,8 @@ func (md Markdown) Process(c Config, requestPath string, b []byte, ctx middlewar ...@@ -69,7 +68,8 @@ func (md Markdown) Process(c Config, requestPath string, b []byte, ctx middlewar
markdown = blackfriday.Markdown(markdown, c.Renderer, 0) markdown = blackfriday.Markdown(markdown, c.Renderer, 0)
// set it as body for template // set it as body for template
metadata.Variables["markdown"] = string(markdown) metadata.Variables["body"] = string(markdown)
metadata.Variables["title"] = metadata.Title
return md.processTemplate(c, requestPath, tmpl, metadata, ctx) return md.processTemplate(c, requestPath, tmpl, metadata, ctx)
} }
...@@ -91,9 +91,7 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me ...@@ -91,9 +91,7 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me
} }
mdData := MarkdownData{ mdData := MarkdownData{
Context: ctx, Context: ctx,
Var: metadata.Variables, Doc: metadata.Variables,
Title: metadata.Title,
Markdown: metadata.Variables["markdown"].(string),
} }
if err = t.Execute(b, mdData); err != nil { if err = t.Execute(b, mdData); err != nil {
...@@ -166,7 +164,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte { ...@@ -166,7 +164,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte {
title := metadata.Title title := metadata.Title
if title == "" { if title == "" {
title = filepath.Base(requestPath) title = filepath.Base(requestPath)
if body, _ := metadata.Variables["markdown"].([]byte); len(body) > 128 { if body, _ := metadata.Variables["body"].([]byte); len(body) > 128 {
title = string(body[:128]) title = string(body[:128])
} else if len(body) > 0 { } else if len(body) > 0 {
title = string(body) title = string(body)
...@@ -191,7 +189,7 @@ const ( ...@@ -191,7 +189,7 @@ const (
{{js}} {{js}}
</head> </head>
<body> <body>
{{.Markdown}} {{.Doc.body}}
</body> </body>
</html>` </html>`
cssTemplate = `<link rel="stylesheet" href="{{url}}">` cssTemplate = `<link rel="stylesheet" href="{{url}}">`
......
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>{{.Title}}</title> <title>{{.Doc.title}}</title>
</head> </head>
<body> <body>
{{.Include "header.html"}} {{.Include "header.html"}}
Welcome to {{.Var.sitename}}! Welcome to {{.Doc.sitename}}!
{{.Markdown}} {{.Doc.body}}
</body> </body>
</html> </html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment