mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-07 11:28:48 +03:00
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.
This commit is contained in:
parent
97dcc79a7f
commit
24bdb433c9
2 changed files with 11 additions and 13 deletions
|
@ -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
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
@ -90,10 +90,8 @@ func (md Markdown) processTemplate(c Config, requestPath string, tmpl []byte, me
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
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 {
|
||||||
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 (
|
||||||
{{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}}">`
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<!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>
|
||||||
|
|
Loading…
Reference in a new issue