summaryrefslogtreecommitdiffstats
path: root/hugolib/page_content.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-19 11:30:57 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-10-22 20:46:13 +0200
commit44da60d869578423dea529db62ed613588a2a560 (patch)
tree0e9839e0d4a23048ae57f145fb3dedc1ad8005f5 /hugolib/page_content.go
parent1e3e34002dae3d4a980141efcc86886e7de5bef8 (diff)
hugolib: Redo the summary delimiter logic
Now that we have a proper page parse tree, this can be greatly simplified. See #5324
Diffstat (limited to 'hugolib/page_content.go')
-rw-r--r--hugolib/page_content.go32
1 files changed, 24 insertions, 8 deletions
diff --git a/hugolib/page_content.go b/hugolib/page_content.go
index 7d5e3e8d6..0d715f38b 100644
--- a/hugolib/page_content.go
+++ b/hugolib/page_content.go
@@ -23,6 +23,10 @@ import (
"github.com/gohugoio/hugo/parser/pageparser"
)
+var (
+ internalSummaryDivider = []byte("HUGOMORE42")
+)
+
// The content related items on a Page.
type pageContent struct {
renderable bool
@@ -41,11 +45,12 @@ type pageContent struct {
}
type rawPageContent struct {
+ hasSummaryDivider bool
+
// The AST of the parsed page. Contains information about:
// shortcBackup3odes, front matter, summary indicators.
// TODO(bep) 2errors add this to a new rawPagecContent struct
// with frontMatterItem (pos) etc.
- // * also Result.Iterator, Result.Source
// * RawContent, RawContentWithoutFrontMatter
parsed pageparser.Result
}
@@ -71,16 +76,15 @@ Loop:
it := iter.Next()
switch {
- case it.Typ == pageparser.TypeIgnore:
- case it.Typ == pageparser.TypeHTMLComment:
+ case it.Type == pageparser.TypeIgnore:
+ case it.Type == pageparser.TypeHTMLComment:
// Ignore. This is only a leading Front matter comment.
- case it.Typ == pageparser.TypeHTMLDocument:
+ case it.Type == pageparser.TypeHTMLDocument:
// This is HTML only. No shortcode, front matter etc.
p.renderable = false
result.Write(it.Val)
- // TODO(bep) 2errors commented out frontmatter
case it.IsFrontMatter():
- f := metadecoders.FormatFromFrontMatterType(it.Typ)
+ f := metadecoders.FormatFromFrontMatterType(it.Type)
m, err := metadecoders.UnmarshalToMap(it.Val, f)
if err != nil {
return err
@@ -92,11 +96,23 @@ Loop:
if !p.shouldBuild() {
// Nothing more to do.
return nil
+ }
+ case it.Type == pageparser.TypeLeadSummaryDivider, it.Type == pageparser.TypeSummaryDividerOrg:
+ result.Write(internalSummaryDivider)
+ p.source.hasSummaryDivider = true
+ // Need to determine if the page is truncated.
+ f := func(item pageparser.Item) bool {
+ if item.IsNonWhitespace() {
+ p.truncated = true
+
+ // Done
+ return false
+ }
+ return true
}
+ iter.PeekWalk(f)
- //case it.Typ == pageparser.TypeLeadSummaryDivider, it.Typ == pageparser.TypeSummaryDividerOrg:
- // TODO(bep) 2errors store if divider is there and use that to determine if replace or not
// Handle shortcode
case it.IsLeftShortcodeDelim():
// let extractShortcode handle left delim (will do so recursively)