mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 09:21:59 -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
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RemoveSummaryDivider(content []byte) []byte {
|
||||||
|
return bytes.Replace(content, summaryDivider, []byte(""), -1)
|
||||||
|
}
|
||||||
|
|
||||||
func StripHTML(s string) string {
|
func StripHTML(s string) string {
|
||||||
output := ""
|
output := ""
|
||||||
|
|
||||||
|
|
|
@ -481,7 +481,7 @@ func (page *Page) convertMarkdown(lines io.Reader) {
|
||||||
b := new(bytes.Buffer)
|
b := new(bytes.Buffer)
|
||||||
b.ReadFrom(lines)
|
b.ReadFrom(lines)
|
||||||
content := b.Bytes()
|
content := b.Bytes()
|
||||||
page.Content = template.HTML(string(blackfriday.MarkdownCommon(content)))
|
page.Content = template.HTML(string(blackfriday.MarkdownCommon(RemoveSummaryDivider(content))))
|
||||||
summary, plain := getSummaryString(content)
|
summary, plain := getSummaryString(content)
|
||||||
if plain {
|
if plain {
|
||||||
page.Summary = template.HTML(string(summary))
|
page.Summary = template.HTML(string(summary))
|
||||||
|
|
|
@ -100,6 +100,14 @@ Simple Page
|
||||||
Some more text
|
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) {
|
func checkError(t *testing.T, err error, expected string) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("err is 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)
|
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
|
||||||
}
|
}
|
||||||
checkPageTitle(t, p, "Simple")
|
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")
|
checkPageSummary(t, p, "<p>Simple Page</p>\n")
|
||||||
checkPageType(t, p, "page")
|
checkPageType(t, p, "page")
|
||||||
checkPageLayout(t, p, "page/single.html")
|
checkPageLayout(t, p, "page/single.html")
|
||||||
|
|
|
@ -31,16 +31,16 @@ import (
|
||||||
var DefaultTimer = nitro.Initalize()
|
var DefaultTimer = nitro.Initalize()
|
||||||
|
|
||||||
type Site struct {
|
type Site struct {
|
||||||
Config Config
|
Config Config
|
||||||
Pages Pages
|
Pages Pages
|
||||||
Tmpl *template.Template
|
Tmpl *template.Template
|
||||||
Indexes IndexList
|
Indexes IndexList
|
||||||
Files []string
|
Files []string
|
||||||
Sections Index
|
Sections Index
|
||||||
Info SiteInfo
|
Info SiteInfo
|
||||||
Shortcodes map[string]ShortcodeFunc
|
Shortcodes map[string]ShortcodeFunc
|
||||||
timer *nitro.B
|
timer *nitro.B
|
||||||
Target target.Publisher
|
Target target.Publisher
|
||||||
}
|
}
|
||||||
|
|
||||||
type SiteInfo struct {
|
type SiteInfo struct {
|
||||||
|
|
Loading…
Reference in a new issue