Commit ff28bc8b authored by Matthew Holt's avatar Matthew Holt

markdown: Change .Url -> .URL, increase summary length

Also, summary truncated at nearest space instead of middle of word, and code spans become part of summary.
parent 0b01489f
package markdown
import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
......@@ -16,8 +17,8 @@ const (
// Date format YYYY-MM-DD HH:MM:SS
timeLayout = `2006-01-02 15:04:05`
// Length of page summary.
summaryLen = 150
// Maximum length of page summary.
summaryLen = 500
)
// PageLink represents a statically generated markdown page.
......@@ -25,7 +26,7 @@ type PageLink struct {
Title string
Summary string
Date time.Time
Url string
URL string
}
// byDate sorts PageLink by newest date to oldest.
......@@ -99,15 +100,22 @@ func (l *linkGen) generateLinks(md Markdown, cfg *Config) {
return err
}
// truncate summary to maximum length
if len(summary) > summaryLen {
summary = summary[:summaryLen]
// trim to nearest word
lastSpace := bytes.LastIndex(summary, []byte(" "))
if lastSpace != -1 {
summary = summary[:lastSpace]
}
}
metadata := parser.Metadata()
cfg.Links = append(cfg.Links, PageLink{
Title: metadata.Title,
Url: reqPath,
URL: reqPath,
Date: metadata.Date,
Summary: string(blackfriday.Markdown(summary, PlaintextRenderer{}, 0)),
})
......
......@@ -48,7 +48,11 @@ func (r PlaintextRenderer) TitleBlock(out *bytes.Buffer, text []byte) {}
func (r PlaintextRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int) {}
func (r PlaintextRenderer) CodeSpan(out *bytes.Buffer, text []byte) {}
func (r PlaintextRenderer) CodeSpan(out *bytes.Buffer, text []byte) {
out.Write([]byte("`"))
out.Write(text)
out.Write([]byte("`"))
}
func (r PlaintextRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte) {
out.Write(text)
......
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