Skip to content

Commit

Permalink
content adapter: Handle <!--more--> separator in content.value
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jun 1, 2024
1 parent 74b9b8a commit 31a07ae
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
26 changes: 26 additions & 0 deletions hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,3 +643,29 @@ Footer: {{ range index site.Menus.footer }}{{ .Name }}|{{ end }}|
"Footer: Footer|p2||",
)
}

func TestPagesFromGoTmplMore(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
[markup.goldmark.renderer]
unsafe = true
-- content/s1/_content.gotmpl --
{{ $page := dict
"content" (dict "mediaType" "text/markdown" "value" "aaa <!--more--> bbb")
"title" "p1"
"path" "p1"
}}
{{ .AddPage $page }}
-- layouts/_default/single.html --
summary: {{ .Summary }}|content: {{ .Content}}
`

b := hugolib.Test(t, files)

b.AssertFileContent("public/s1/p1/index.html",
"<p>aaa</p>|content: <p>aaa</p>\n<p>bbb</p>",
)
}
7 changes: 4 additions & 3 deletions parser/pageparser/pagelexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ type Config struct {
// can be set if position of first shortcode is known
func newPageLexer(input []byte, stateStart stateFunc, cfg Config) *pageLexer {
lexer := &pageLexer{
input: input,
stateStart: stateStart,
cfg: cfg,
input: input,
stateStart: stateStart,
summaryDivider: summaryDivider,
cfg: cfg,
lexerShortcodeState: lexerShortcodeState{
currLeftDelimItem: tLeftDelimScNoMarkup,
currRightDelimItem: tRightDelimScNoMarkup,
Expand Down
2 changes: 0 additions & 2 deletions parser/pageparser/pagelexer_intro.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package pageparser

func lexIntroSection(l *pageLexer) stateFunc {
l.summaryDivider = summaryDivider

LOOP:
for {
r := l.next()
Expand Down
11 changes: 11 additions & 0 deletions parser/pageparser/pageparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ func BenchmarkHasShortcode(b *testing.B) {
}
})
}

func TestSummaryDividerStartingFromMain(t *testing.T) {
c := qt.New(t)

input := `aaa <!--more--> bbb`
items, err := collectStringMain(input)
c.Assert(err, qt.IsNil)

c.Assert(items, qt.HasLen, 4)
c.Assert(items[1].Type, qt.Equals, TypeLeadSummaryDivider)
}

0 comments on commit 31a07ae

Please sign in to comment.