Skip to content

Commit

Permalink
Content
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 29, 2024
1 parent d2de640 commit 0bce7e5
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
6 changes: 6 additions & 0 deletions hugolib/content_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,15 @@ func (m *pageMap) AddFi(fi hugofs.FileMetaInfo, whatChanged *whatChanged) error
return fmt.Errorf("unsupported data file extension %q", pi.Ext())
}
// TODO1 disabled languages.

s := m.s.h.resolveSite(fi.Meta().Lang)
f := source.NewFileInfo(fi)
h := s.h

// Make sure the layouts are initialized.
if _, err := h.init.layouts.Do(context.Background()); err != nil {
return err
}
if err := func() error {
contentAdapter := s.pageMap.treePagesFromTemplateOptions.Get(pi.Base())
var rebuild bool
Expand Down
2 changes: 1 addition & 1 deletion hugolib/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func (p *pageState) getPageInfoForError() string {
func (p *pageState) getContentConverter() converter.Converter {
var err error
p.contentConverterInit.Do(func() {
markup := p.m.pageConfig.Markup
markup := p.m.pageConfig.Content.Markup
if markup == "html" {
// Only used for shortcode inner content.
markup = "markdown"
Expand Down
8 changes: 4 additions & 4 deletions hugolib/page__content.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,15 @@ func (c *cachedContent) contentRendered(ctx context.Context, cp *pageContentOutp
var result contentSummary // hasVariants bool

if c.pi.hasSummaryDivider {
isHTML := cp.po.p.m.pageConfig.Markup == "html"
isHTML := cp.po.p.m.pageConfig.Content.Markup == "html"
if isHTML {
// Use the summary sections as provided by the user.
i := bytes.Index(b, internalSummaryDividerPre)
result.summary = helpers.BytesToHTML(b[:i])
b = b[i+len(internalSummaryDividerPre):]

} else {
summary, content, err := splitUserDefinedSummaryAndContent(cp.po.p.m.pageConfig.Markup, b)
summary, content, err := splitUserDefinedSummaryAndContent(cp.po.p.m.pageConfig.Content.Markup, b)
if err != nil {
cp.po.p.s.Log.Errorf("Failed to set user defined summary for page %q: %s", cp.po.p.pathOrTitle(), err)
} else {
Expand Down Expand Up @@ -679,7 +679,7 @@ func (c *cachedContent) contentToC(ctx context.Context, cp *pageContentOutput) (
p.pageOutputTemplateVariationsState.Add(1)
}

isHTML := cp.po.p.m.pageConfig.Markup == "html"
isHTML := cp.po.p.m.pageConfig.Content.Markup == "html"

if !isHTML {
createAndSetToC := func(tocProvider converter.TableOfContentsProvider) {
Expand Down Expand Up @@ -797,7 +797,7 @@ func (c *cachedContent) contentPlain(ctx context.Context, cp *pageContentOutput)
if err != nil {
return nil, err
}
html := cp.po.p.s.ContentSpec.TrimShortHTML(b.Bytes(), cp.po.p.m.pageConfig.Markup)
html := cp.po.p.s.ContentSpec.TrimShortHTML(b.Bytes(), cp.po.p.m.pageConfig.Content.Markup)
result.summary = helpers.BytesToHTML(html)
} else {
var summary string
Expand Down
17 changes: 9 additions & 8 deletions hugolib/page__meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ params:
pcfg.Layout = cast.ToString(v)
params[loki] = pcfg.Layout
case "markup":
pcfg.Markup = cast.ToString(v)
params[loki] = pcfg.Markup
pcfg.Content.Markup = cast.ToString(v)
params[loki] = pcfg.Content.Markup
case "weight":
pcfg.Weight = cast.ToInt(v)
params[loki] = pcfg.Weight
Expand Down Expand Up @@ -647,7 +647,8 @@ params:
pcfg.Sitemap = p.s.conf.Sitemap
}

pcfg.Markup = p.s.ContentSpec.ResolveMarkup(pcfg.Markup)
// TODO1
pcfg.Content.Markup = p.s.ContentSpec.ResolveMarkup(pcfg.Content.Markup)

if draft != nil && published != nil {
pcfg.Draft = *draft
Expand Down Expand Up @@ -726,17 +727,17 @@ func (p *pageMeta) applyDefaultValues() error {
(&p.pageConfig.Build).Disable()
}

if p.pageConfig.Markup == "" {
if p.pageConfig.Content.Markup == "" {
if p.File() != nil {
// Fall back to file extension
p.pageConfig.Markup = p.s.ContentSpec.ResolveMarkup(p.File().Ext())
p.pageConfig.Content.Markup = p.s.ContentSpec.ResolveMarkup(p.File().Ext())
}
if p.pageConfig.Markup == "" {
p.pageConfig.Markup = "markdown"
if p.pageConfig.Content.Markup == "" {
p.pageConfig.Content.Markup = "markdown"
}
}

p.pageConfig.IsGoldmark = p.s.ContentSpec.Converters.IsGoldmark(p.pageConfig.Markup)
p.pageConfig.IsGoldmark = p.s.ContentSpec.Converters.IsGoldmark(p.pageConfig.Content.Markup)

if p.pageConfig.Title == "" && p.f == nil {
switch p.Kind() {
Expand Down
4 changes: 2 additions & 2 deletions hugolib/page__per_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (pco *pageContentOutput) RenderString(ctx context.Context, args ...any) (te
}

conv := pco.po.p.getContentConverter()
if opts.Markup != "" && opts.Markup != pco.po.p.m.pageConfig.Markup {
if opts.Markup != "" && opts.Markup != pco.po.p.m.pageConfig.Content.Markup {
var err error
conv, err = pco.po.p.m.newContentConverter(pco.po.p, opts.Markup)
if err != nil {
Expand Down Expand Up @@ -376,7 +376,7 @@ func (pco *pageContentOutput) RenderString(ctx context.Context, args ...any) (te
}

if opts.Display == "inline" {
markup := pco.po.p.m.pageConfig.Markup
markup := pco.po.p.m.pageConfig.Content.Markup
if opts.Markup != "" {
markup = pco.po.p.s.ContentSpec.ResolveMarkup(opts.Markup)
}
Expand Down
2 changes: 1 addition & 1 deletion hugolib/pagesfromdata/pagesfromgotmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (p *PagesFromTemplate) Execute(ctx context.Context) error {
}

p.BuildState.resolveDeletedPaths()
p.BuildState.printDebug()
// p.BuildState.printDebug()

return nil
}
Expand Down
10 changes: 6 additions & 4 deletions hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ p1: "p1"
{{ $val := "p1" }}
{{ return $val }}
-- layouts/_default/single.html --
Single: {{ .Title }}|{{ .Content }}|
Single: {{ .Title }}|{{ .Content }}|Params: {{ .Params.param1 }}|
-- layouts/_default/list.html --
List: {{ .Title }}|{{ .Content }}|
RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .Title }}:{{ .Path }}|{{ end }}$
Expand All @@ -41,15 +41,15 @@ RegularPagesRecursive: {{ range .RegularPagesRecursive }}{{ .Title }}:{{ .Path }
{{ $title := printf "%s:%s" $pd $pp }}
{{ $contentMarkdown := dict "type" "text" "value" "**Hello World**" }}
{{ $contentHTML := dict "type" "text" "value" "<b>Hello World!</b>" "markup" "html" }}
{{ $.AddPage (dict "kind" "page" "path" "p1" "title" $title "content" $contentMarkdown ) }}
{{ $.AddPage (dict "kind" "page" "path" "p1" "title" $title "content" $contentMarkdown "params" (dict "param1" "param1v" ) ) }}
{{ $.AddPage (dict "kind" "page" "path" "p2" "title" "p2" "content" $contentHTML ) }}
`

func TestPagesFromGoTmplBasic(t *testing.T) {
t.Parallel()
b := hugolib.Test(t, filesPagesFromDataTempleBasic)
b.AssertFileContent("public/docs/p1/index.html", "Single: p1:p1|", "<strong>Hello World</strong>")
b.AssertFileContent("public/docs/p2/index.html", "Single: p2:<b>Hello World!</b>|")
b.AssertFileContent("public/docs/p1/index.html", "Single: p1:p1|", "<strong>Hello World</strong>", "Params: param1v|")
b.AssertFileContent("public/docs/p2/index.html", "Single: p2|", "<b>Hello World!</b>")
}

func TestPagesFromGoTmplEditDataResource(t *testing.T) {
Expand Down Expand Up @@ -132,3 +132,5 @@ func TestPagesFromGoTmplRemoveGoTmpl(t *testing.T) {

// TODO1 markup.
// TODO1 resource path must end with a file name.
// TODO1 prevent site.Home.RenderString
// TODO1 also make markdownify work without Home.
2 changes: 1 addition & 1 deletion hugolib/shortcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func doRenderShortcode(
// unchanged.
// 2 If inner does not have a newline, strip the wrapping <p> block and
// the newline.
switch p.m.pageConfig.Markup {
switch p.m.pageConfig.Content.Markup {
case "", "markdown":
if match, _ := regexp.MatchString(innerNewlineRegexp, inner); !match {
cleaner, err := regexp.Compile(innerCleanupRegexp)
Expand Down
7 changes: 4 additions & 3 deletions resources/page/pagemeta/page_frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type PageConfig struct {
LinkTitle string // The link title of the page.
Type string // The content type of the page.
Layout string // The layout to use for to render this page.
Markup string // The markup used in the content file.
Weight int // The weight of the page, used in sorting if set to a non-zero value.
Kind string // The kind of page, e.g. "page", "section", "home" etc. This is usually derived from the content path.
Path string // The canonical path to the page, e.g. /sect/mypage. Note: Leading slash, no trailing slash, no extensions or language identifiers.
Expand Down Expand Up @@ -106,7 +105,6 @@ type PageConfig struct {
// Compiled values.
IsGoldmark bool `json:"-"`

// Only from data files.
Content Source
}

Expand Down Expand Up @@ -139,7 +137,10 @@ const (

type Source struct {
// Type may be either "text" or "url".
Type SourceType
Type SourceType
// The markup used in Value.
Markup string
// The content.
Value string
}

Expand Down

0 comments on commit 0bce7e5

Please sign in to comment.