Commit 604c8abb authored by Maxime's avatar Maxime

Remove debug line, add file name as default title

parent ef4a4b0a
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
package markdown package markdown
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
...@@ -126,7 +125,6 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error ...@@ -126,7 +125,6 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
URL: r.URL, URL: r.URL,
} }
html, err := md.Process(m, fpath, body, ctx) html, err := md.Process(m, fpath, body, ctx)
fmt.Printf("%v", html)
if err != nil { if err != nil {
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
......
...@@ -68,7 +68,13 @@ func (md Markdown) Process(c Config, requestPath string, b []byte, ctx middlewar ...@@ -68,7 +68,13 @@ func (md Markdown) Process(c Config, requestPath string, b []byte, ctx middlewar
// set it as body for template // set it as body for template
metadata.Variables["body"] = string(markdown) metadata.Variables["body"] = string(markdown)
metadata.Variables["title"] = metadata.Title title := metadata.Title
if title == "" {
title = filepath.Base(requestPath)
var extension = filepath.Ext(requestPath)
title = title[0 : len(title)-len(extension)]
}
metadata.Variables["title"] = title
return md.processTemplate(c, requestPath, tmpl, metadata, ctx) return md.processTemplate(c, requestPath, tmpl, metadata, ctx)
} }
...@@ -160,15 +166,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte { ...@@ -160,15 +166,7 @@ func defaultTemplate(c Config, metadata Metadata, requestPath string) []byte {
} }
// Title is first line (length-limited), otherwise filename // Title is first line (length-limited), otherwise filename
title := metadata.Title title, _ := metadata.Variables["title"].(string)
if title == "" {
title = filepath.Base(requestPath)
if body, _ := metadata.Variables["body"].([]byte); len(body) > 128 {
title = string(body[:128])
} else if len(body) > 0 {
title = string(body)
}
}
html := []byte(htmlTemplate) html := []byte(htmlTemplate)
html = bytes.Replace(html, []byte("{{title}}"), []byte(title), 1) html = bytes.Replace(html, []byte("{{title}}"), []byte(title), 1)
......
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