mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
The <!--more--> (summary divider) now works even if it is on the same line as content
This commit is contained in:
parent
0fdea0c2c2
commit
5b6021000d
4 changed files with 37 additions and 12 deletions
|
@ -270,6 +270,10 @@ func WordCount(s string) map[string]int {
|
|||
return m
|
||||
}
|
||||
|
||||
func RemoveSummaryDivider(content []byte) []byte {
|
||||
return bytes.Replace(content, summaryDivider, []byte(""), -1)
|
||||
}
|
||||
|
||||
func StripHTML(s string) string {
|
||||
output := ""
|
||||
|
||||
|
|
|
@ -481,7 +481,7 @@ func (page *Page) convertMarkdown(lines io.Reader) {
|
|||
b := new(bytes.Buffer)
|
||||
b.ReadFrom(lines)
|
||||
content := b.Bytes()
|
||||
page.Content = template.HTML(string(blackfriday.MarkdownCommon(content)))
|
||||
page.Content = template.HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content))))
|
||||
summary, plain := getSummaryString(content)
|
||||
if plain {
|
||||
page.Summary = template.HTML(string(summary))
|
||||
|
|
|
@ -100,6 +100,14 @@ Simple Page
|
|||
Some more text
|
||||
`
|
||||
|
||||
var SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE = `---
|
||||
title: Simple
|
||||
---
|
||||
Simple Page<!--more-->
|
||||
|
||||
Some more text
|
||||
`
|
||||
|
||||
func checkError(t *testing.T, err error, expected string) {
|
||||
if err == nil {
|
||||
t.Fatalf("err is nil")
|
||||
|
@ -175,7 +183,20 @@ func TestPageWithDelimiter(t *testing.T) {
|
|||
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
|
||||
}
|
||||
checkPageTitle(t, p, "Simple")
|
||||
checkPageContent(t, p, "<p>Simple Page</p>\n\n<!--more-->\n\n<p>Some more text</p>\n")
|
||||
checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
|
||||
checkPageSummary(t, p, "<p>Simple Page</p>\n")
|
||||
checkPageType(t, p, "page")
|
||||
checkPageLayout(t, p, "page/single.html")
|
||||
|
||||
}
|
||||
|
||||
func TestPageWithMoreTag(t *testing.T) {
|
||||
p, err := ReadFrom(strings.NewReader(SIMPLE_PAGE_WITH_SUMMARY_DELIMITER_SAME_LINE), "simple")
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
|
||||
}
|
||||
checkPageTitle(t, p, "Simple")
|
||||
checkPageContent(t, p, "<p>Simple Page</p>\n\n<p>Some more text</p>\n")
|
||||
checkPageSummary(t, p, "<p>Simple Page</p>\n")
|
||||
checkPageType(t, p, "page")
|
||||
checkPageLayout(t, p, "page/single.html")
|
||||
|
|
Loading…
Reference in a new issue