Wordcount restored. fixed #92

This commit is contained in:
spf13
2013-10-15 09:15:52 -04:00
parent e58d8fe791
commit be5ace1588
2 changed files with 38 additions and 4 deletions

View File

@@ -38,7 +38,7 @@ type Page struct {
Images []string
Content template.HTML
Summary template.HTML
RawMarkdown string // TODO should be []byte
plain string // TODO should be []byte
Params map[string]interface{}
contentType string
Draft bool
@@ -77,6 +77,13 @@ func (p Pages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p Pages) Sort() { sort.Sort(p) }
func (p Pages) Limit(n int) Pages { return p[0:n] }
func (p Page) Plain() string {
if len(p.plain) == 0 {
p.plain = StripHTML(StripShortcodes(string(p.Content)))
}
return p.plain
}
func getSummaryString(content []byte, fmt string) []byte {
if bytes.Contains(content, summaryDivider) {
// If user defines split:
@@ -85,8 +92,8 @@ func getSummaryString(content []byte, fmt string) []byte {
} else {
// If hugo defines split:
// render, strip html, then split
plainContent := StripHTML(StripShortcodes(string(renderBytes(content, fmt))))
return []byte(TruncateWordsToWholeSentence(plainContent, summaryLength))
plain := StripHTML(StripShortcodes(string(renderBytes(content, fmt))))
return []byte(TruncateWordsToWholeSentence(plain, summaryLength))
}
}
@@ -217,7 +224,7 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
}
func (p *Page) analyzePage() {
p.WordCount = TotalWords(p.RawMarkdown)
p.WordCount = TotalWords(p.Plain())
p.FuzzyWordCount = int((p.WordCount+100)/100) * 100
}