mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-30 15:58:10 +08:00
markdown: working version of template integration. Awaiting static site generation and tests.
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"github.com/mholt/caddy/middleware"
|
||||
"github.com/mholt/caddy/middleware/markdown"
|
||||
"github.com/russross/blackfriday"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Markdown configures a new Markdown middleware instance.
|
||||
@ -33,7 +34,9 @@ func markdownParse(c *Controller) ([]markdown.Config, error) {
|
||||
|
||||
for c.Next() {
|
||||
md := markdown.Config{
|
||||
Renderer: blackfriday.HtmlRenderer(0, "", ""),
|
||||
Renderer: blackfriday.HtmlRenderer(0, "", ""),
|
||||
Templates: make(map[string]string),
|
||||
StaticFiles: make(map[string]string),
|
||||
}
|
||||
|
||||
// Get the path scope
|
||||
@ -61,6 +64,23 @@ func markdownParse(c *Controller) ([]markdown.Config, error) {
|
||||
return mdconfigs, c.ArgErr()
|
||||
}
|
||||
md.Scripts = append(md.Scripts, c.Val())
|
||||
case "template":
|
||||
tArgs := c.RemainingArgs()
|
||||
switch len(tArgs) {
|
||||
case 0:
|
||||
return mdconfigs, c.ArgErr()
|
||||
case 1:
|
||||
if _, ok := md.Templates[markdown.DefaultTemplate]; ok {
|
||||
return mdconfigs, c.Err("only one default template is allowed, use alias.")
|
||||
}
|
||||
fpath := filepath.Clean(c.Root + string(filepath.Separator) + tArgs[0])
|
||||
md.Templates[markdown.DefaultTemplate] = fpath
|
||||
case 2:
|
||||
fpath := filepath.Clean(c.Root + string(filepath.Separator) + tArgs[1])
|
||||
md.Templates[tArgs[0]] = fpath
|
||||
default:
|
||||
return mdconfigs, c.ArgErr()
|
||||
}
|
||||
default:
|
||||
return mdconfigs, c.Err("Expected valid markdown configuration property")
|
||||
}
|
||||
|
Reference in New Issue
Block a user