Commit b541c717 authored by Tobias Weingartner's avatar Tobias Weingartner

Add ability to markdown a directory with a template.

parent e652d12c
......@@ -89,7 +89,6 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// Set path to found index file
fpath = idx
_ = dirents
}
// If supported extension, process it
......@@ -117,7 +116,7 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
Req: r,
URL: r.URL,
}
html, err := cfg.Markdown(fpath, body, ctx)
html, err := cfg.Markdown(fpath, body, dirents, ctx)
if err != nil {
return http.StatusInternalServerError, err
}
......
......@@ -3,6 +3,7 @@ package metadata
import (
"bufio"
"bytes"
"os"
"time"
)
......@@ -30,6 +31,9 @@ type Metadata struct {
// Flags to be used with Template
Flags map[string]bool
// Directory entries present, if a directory
Dirents []os.FileInfo
}
// NewMetadata() returns a new Metadata struct, loaded with the given map
......
package markdown
import (
"os"
"path/filepath"
"github.com/mholt/caddy/middleware"
......@@ -10,7 +11,7 @@ import (
// Markdown processes the contents of a page in b. It parses the metadata
// (if any) and uses the template (if found).
func (c *Config) Markdown(requestPath string, b []byte, ctx middleware.Context) ([]byte, error) {
func (c *Config) Markdown(requestPath string, b []byte, dirents []os.FileInfo, ctx middleware.Context) ([]byte, error) {
parser := metadata.GetParser(b)
markdown := parser.Markdown()
mdata := parser.Metadata()
......@@ -33,5 +34,12 @@ func (c *Config) Markdown(requestPath string, b []byte, ctx middleware.Context)
}
mdata.Variables["title"] = title
if len(dirents) > 0 {
mdata.Flags["dirents"] = true
mdata.Dirents = dirents
} else {
mdata.Flags["dirents"] = false
}
return execTemplate(c, mdata, ctx)
}
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