diff --git a/middleware/markdown/metadata.go b/middleware/markdown/metadata.go index 3e3e48be..8734663a 100644 --- a/middleware/markdown/metadata.go +++ b/middleware/markdown/metadata.go @@ -162,14 +162,18 @@ func extractMetadata(b []byte) (metadata Metadata, markdown []byte, err error) { var parser MetadataParser // Read first line - if scanner.Scan() { - line := scanner.Bytes() - parser = findParser(line) - // if no parser found, + if !scanner.Scan() { + // if no line is read, // assume metadata not present - if parser == nil { - return metadata, b, nil - } + return metadata, b, nil + } + + line := scanner.Bytes() + parser = findParser(line) + // if no parser found, + // assume metadata not present + if parser == nil { + return metadata, b, nil } // buffer for metadata contents diff --git a/middleware/markdown/process.go b/middleware/markdown/process.go index 5bf9badf..9741bd17 100644 --- a/middleware/markdown/process.go +++ b/middleware/markdown/process.go @@ -137,7 +137,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte { title := metadata.Title if title == "" { title = filepath.Base(requestPath) - if body, _ := metadata.Variables["body"].([]byte); len(body) > 128 { + if body, _ := metadata.Variables["markdown"].([]byte); len(body) > 128 { title = string(body[:128]) } else if len(body) > 0 { title = string(body) @@ -162,7 +162,7 @@ const ( {{js}} - {{.body}} + {{.markdown}} ` cssTemplate = ``