func (m *pageMeta) parseFrontMatter(h *HugoSites, pid uint64) (*contentParseInfo, error) {
var (
- sourceKey string
- openSource hugio.OpenReadSeekCloser
- hasContent = m.pageConfig.IsFromContentAdapter
+ sourceKey string
+ openSource hugio.OpenReadSeekCloser
+ isFromContentAdapter = m.pageConfig.IsFromContentAdapter
)
- if m.f != nil && !hasContent {
+ if m.f != nil && !isFromContentAdapter {
sourceKey = filepath.ToSlash(m.f.Filename())
- if !hasContent {
+ if !isFromContentAdapter {
meta := m.f.FileInfo().Meta()
openSource = func() (hugio.ReadSeekCloser, error) {
r, err := meta.Open()
return r, nil
}
}
- } else if hasContent {
+ } else if isFromContentAdapter {
openSource = m.pageConfig.Content.ValueAsOpenReadSeekCloser()
}
items, err := pageparser.ParseBytes(
source,
- pageparser.Config{},
+ pageparser.Config{
+ NoFrontMatter: isFromContentAdapter,
+ },
)
if err != nil {
return nil, err
pi.itemsStep1 = items
- if hasContent {
+ if isFromContentAdapter {
// No front matter.
return pi, nil
}
b.AssertLogNotContains("WARN")
}
+
+func TestPagesFromGoTmplShortcodeNoPreceddingCharacterIssue12544(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['home','rss','section','sitemap','taxonomy','term']
+-- content/_content.gotmpl --
+{{ $content := dict "mediaType" "text/html" "value" "x{{< sc >}}" }}
+{{ .AddPage (dict "content" $content "path" "a") }}
+
+{{ $content := dict "mediaType" "text/html" "value" "{{< sc >}}" }}
+{{ .AddPage (dict "content" $content "path" "b") }}
+-- layouts/_default/single.html --
+|{{ .Content }}|
+-- layouts/shortcodes/sc.html --
+foo
+{{- /**/ -}}
+`
+
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/a/index.html", "|xfoo|")
+ b.AssertFileContent("public/b/index.html", "|foo|") // fails
+}
return l.input
}
-type Config struct{}
+type Config struct {
+ NoFrontMatter bool
+}
// note: the input position here is normally 0 (start), but
// can be set if position of first shortcode is known
// ParseBytes parses the page in b according to the given Config.
func ParseBytes(b []byte, cfg Config) (Items, error) {
- l, err := parseBytes(b, cfg, lexIntroSection)
+ startLexer := lexIntroSection
+ if cfg.NoFrontMatter {
+ startLexer = lexMainSection
+ }
+ l, err := parseBytes(b, cfg, startLexer)
if err != nil {
return nil, err
}