mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
markdown: Refactor fixes
This commit is contained in:
parent
978aef2ae7
commit
6ce83aad2b
2 changed files with 13 additions and 9 deletions
|
@ -162,7 +162,12 @@ func extractMetadata(b []byte) (metadata Metadata, markdown []byte, err error) {
|
||||||
var parser MetadataParser
|
var parser MetadataParser
|
||||||
|
|
||||||
// Read first line
|
// Read first line
|
||||||
if scanner.Scan() {
|
if !scanner.Scan() {
|
||||||
|
// if no line is read,
|
||||||
|
// assume metadata not present
|
||||||
|
return metadata, b, nil
|
||||||
|
}
|
||||||
|
|
||||||
line := scanner.Bytes()
|
line := scanner.Bytes()
|
||||||
parser = findParser(line)
|
parser = findParser(line)
|
||||||
// if no parser found,
|
// if no parser found,
|
||||||
|
@ -170,7 +175,6 @@ func extractMetadata(b []byte) (metadata Metadata, markdown []byte, err error) {
|
||||||
if parser == nil {
|
if parser == nil {
|
||||||
return metadata, b, nil
|
return metadata, b, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// buffer for metadata contents
|
// buffer for metadata contents
|
||||||
buf := bytes.Buffer{}
|
buf := bytes.Buffer{}
|
||||||
|
|
|
@ -137,7 +137,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["body"].([]byte); len(body) > 128 {
|
if body, _ := metadata.Variables["markdown"].([]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)
|
||||||
|
@ -162,7 +162,7 @@ const (
|
||||||
{{js}}
|
{{js}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{.body}}
|
{{.markdown}}
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
cssTemplate = `<link rel="stylesheet" href="{{url}}">`
|
cssTemplate = `<link rel="stylesheet" href="{{url}}">`
|
||||||
|
|
Loading…
Reference in a new issue