mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Fix a more summary corner case
Also refactor the rendering pages test to accept more than one page source per test run, which wasn't really needed for this issue, but may be in the future. Closes #2586 Fixes #2538
This commit is contained in:
committed by
GitHub
parent
58f31d2769
commit
67df33d83f
@@ -260,7 +260,11 @@ var (
|
||||
// Returns the page as summary and main if a user defined split is provided.
|
||||
func (p *Page) setUserDefinedSummaryIfProvided() (*summaryContent, error) {
|
||||
|
||||
sc := splitUserDefinedSummaryAndContent(p.Markup, p.rawContentCopy)
|
||||
sc, err := splitUserDefinedSummaryAndContent(p.Markup, p.rawContentCopy)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if sc == nil {
|
||||
// No divider found
|
||||
@@ -285,12 +289,18 @@ type summaryContent struct {
|
||||
contentWithoutSummary []byte
|
||||
}
|
||||
|
||||
func splitUserDefinedSummaryAndContent(markup string, c []byte) *summaryContent {
|
||||
func splitUserDefinedSummaryAndContent(markup string, c []byte) (sc *summaryContent, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("summary split failed: %s", r)
|
||||
}
|
||||
}()
|
||||
|
||||
c = bytes.TrimSpace(c)
|
||||
startDivider := bytes.Index(c, internalSummaryDivider)
|
||||
|
||||
if startDivider == -1 {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
endDivider := startDivider + len(internalSummaryDivider)
|
||||
@@ -317,8 +327,11 @@ func splitUserDefinedSummaryAndContent(markup string, c []byte) *summaryContent
|
||||
}
|
||||
|
||||
// Find the closest end/start markup string to the divider
|
||||
fromStart := -1
|
||||
fromIdx := bytes.LastIndex(c[:startDivider], startMarkup)
|
||||
fromStart := startDivider - fromIdx - len(startMarkup)
|
||||
if fromIdx != -1 {
|
||||
fromStart = startDivider - fromIdx - len(startMarkup)
|
||||
}
|
||||
fromEnd := bytes.Index(c[endDivider:], endMarkup)
|
||||
|
||||
if fromEnd != -1 && fromEnd <= fromStart {
|
||||
@@ -328,7 +341,6 @@ func splitUserDefinedSummaryAndContent(markup string, c []byte) *summaryContent
|
||||
}
|
||||
|
||||
withoutDivider := bytes.TrimSpace(append(c[:startDivider], c[endDivider:]...))
|
||||
|
||||
var (
|
||||
contentWithoutSummary []byte
|
||||
summary []byte
|
||||
@@ -346,11 +358,17 @@ func splitUserDefinedSummaryAndContent(markup string, c []byte) *summaryContent
|
||||
contentWithoutSummary = append(divStart, contentWithoutSummary...)
|
||||
}
|
||||
|
||||
return &summaryContent{
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sc = &summaryContent{
|
||||
summary: summary,
|
||||
content: withoutDivider,
|
||||
contentWithoutSummary: contentWithoutSummary,
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (p *Page) setAutoSummary() error {
|
||||
|
Reference in New Issue
Block a user