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