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 (
type MarkdownData struct {
middleware.Context
Var map[string]interface{}
Title string
Markdown string
Doc map[string]interface{}
markdown string
}
// 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
markdown = blackfriday.Markdown(markdown, c.Renderer, 0)
// 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)
}
......@@ -90,10 +90,8 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me
return nil, err
}
mdData := MarkdownData{
Context: ctx,
Var: metadata.Variables,
Title: metadata.Title,
Markdown: metadata.Variables["markdown"].(string),
Context: ctx,
Doc: metadata.Variables,
}
if err = t.Execute(b, mdData); err != nil {
......@@ -166,7 +164,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte {
title := metadata.Title
if title == "" {
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])
} else if len(body) > 0 {
title = string(body)
......@@ -191,7 +189,7 @@ const (
{{js}}
</head>
<body>
{{.Markdown}}
{{.Doc.body}}
</body>
</html>`
cssTemplate = `<link rel="stylesheet" href="{{url}}">`
......
<!DOCTYPE html>
<html>
<head>
<title>{{.Title}}</title>
<title>{{.Doc.title}}</title>
</head>
<body>
{{.Include "header.html"}}
Welcome to {{.Var.sitename}}!
{{.Markdown}}
Welcome to {{.Doc.sitename}}!
{{.Doc.body}}
</body>
</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