0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00

markdown: Make base path optional, always generate links

The base path being optional in the Caddyfile is convenient when you just want the whole site to be markdown-enabled. The other change is to always generate links... this is because an index page for markdown files may not be statically generated, but it should still show links. Commit 09341fc was a regression, and this fixes it.
This commit is contained in:
Matthew Holt 2015-11-07 20:24:17 -07:00
parent be9f644425
commit 171fd34b3c
2 changed files with 20 additions and 13 deletions

View file

@ -61,10 +61,15 @@ func markdownParse(c *Controller) ([]*markdown.Config, error) {
} }
// Get the path scope // Get the path scope
if !c.NextArg() || c.Val() == "{" { args := c.RemainingArgs()
switch len(args) {
case 0:
md.PathScope = "/"
case 1:
md.PathScope = args[0]
default:
return mdconfigs, c.ArgErr() return mdconfigs, c.ArgErr()
} }
md.PathScope = c.Val()
// Load any other configuration parameters // Load any other configuration parameters
for c.NextBlock() { for c.NextBlock() {

View file

@ -17,8 +17,7 @@ import (
// It only generates static files if it is enabled (cfg.StaticDir // It only generates static files if it is enabled (cfg.StaticDir
// must be set). // must be set).
func GenerateStatic(md Markdown, cfg *Config) error { func GenerateStatic(md Markdown, cfg *Config) error {
// If static site generation is enabled. // Generate links since they may be needed, even without sitegen.
if cfg.StaticDir != "" {
generated, err := generateLinks(md, cfg) generated, err := generateLinks(md, cfg)
if err != nil { if err != nil {
return err return err
@ -29,10 +28,13 @@ func GenerateStatic(md Markdown, cfg *Config) error {
return nil return nil
} }
// If static site generation is enabled, generate the site.
if cfg.StaticDir != "" {
if err := generateStaticHTML(md, cfg); err != nil { if err := generateStaticHTML(md, cfg); err != nil {
return err return err
} }
} }
return nil return nil
} }