mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-13 20:24:00 +02:00
@@ -356,7 +356,7 @@ func (m *pageMap) addPagesFromGoTmplFi(fi hugofs.FileMetaInfo, buildConfig *Buil
|
|||||||
Watching: s.Conf.Watching(),
|
Watching: s.Conf.Watching(),
|
||||||
HandlePage: func(pt *pagesfromdata.PagesFromTemplate, pc *pagemeta.PageConfig) error {
|
HandlePage: func(pt *pagesfromdata.PagesFromTemplate, pc *pagemeta.PageConfig) error {
|
||||||
s := pt.Site.(*Site)
|
s := pt.Site.(*Site)
|
||||||
if err := pc.Compile(pt.GoTmplFi.Meta().PathInfo.Base(), true, "", s.Log, s.conf.MediaTypes.Config); err != nil {
|
if err := pc.Compile(pt.GoTmplFi.Meta().PathInfo.Base(), true, "", s.Log, s.conf.OutputFormats.Config, s.conf.MediaTypes.Config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,7 +54,6 @@ type pageMeta struct {
|
|||||||
|
|
||||||
resource.Staler
|
resource.Staler
|
||||||
*pageMetaParams
|
*pageMetaParams
|
||||||
pageMetaFrontMatter
|
|
||||||
|
|
||||||
// Set for standalone pages, e.g. robotsTXT.
|
// Set for standalone pages, e.g. robotsTXT.
|
||||||
standaloneOutputFormat output.Format
|
standaloneOutputFormat output.Format
|
||||||
@@ -79,7 +78,6 @@ func (m *pageMeta) setMetaPostPrepareRebuild() {
|
|||||||
Path: m.pageConfig.Path,
|
Path: m.pageConfig.Path,
|
||||||
Params: params,
|
Params: params,
|
||||||
}
|
}
|
||||||
m.pageMetaFrontMatter = pageMetaFrontMatter{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type pageMetaParams struct {
|
type pageMetaParams struct {
|
||||||
@@ -94,11 +92,6 @@ type pageMetaParams struct {
|
|||||||
cascadeOriginal *maps.Ordered[page.PageMatcher, maps.Params] // contains the original cascade as defined in the front matter.
|
cascadeOriginal *maps.Ordered[page.PageMatcher, maps.Params] // contains the original cascade as defined in the front matter.
|
||||||
}
|
}
|
||||||
|
|
||||||
// From page front matter.
|
|
||||||
type pageMetaFrontMatter struct {
|
|
||||||
configuredOutputFormats output.Formats // outputs defined in front matter.
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *pageMetaParams) init(preserveOriginal bool) {
|
func (m *pageMetaParams) init(preserveOriginal bool) {
|
||||||
if preserveOriginal {
|
if preserveOriginal {
|
||||||
m.paramsOriginal = xmaps.Clone[maps.Params](m.pageConfig.Params)
|
m.paramsOriginal = xmaps.Clone[maps.Params](m.pageConfig.Params)
|
||||||
@@ -531,16 +524,7 @@ params:
|
|||||||
for i, s := range o {
|
for i, s := range o {
|
||||||
o[i] = strings.ToLower(s)
|
o[i] = strings.ToLower(s)
|
||||||
}
|
}
|
||||||
if len(o) > 0 {
|
pm.pageConfig.Outputs = o
|
||||||
// Output formats are explicitly set in front matter, use those.
|
|
||||||
outFormats, err := p.s.conf.OutputFormats.Config.GetByNames(o...)
|
|
||||||
if err != nil {
|
|
||||||
p.s.Log.Errorf("Failed to resolve output formats: %s", err)
|
|
||||||
} else {
|
|
||||||
pm.configuredOutputFormats = outFormats
|
|
||||||
params[loki] = outFormats
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "draft":
|
case "draft":
|
||||||
draft = new(bool)
|
draft = new(bool)
|
||||||
*draft = cast.ToBool(v)
|
*draft = cast.ToBool(v)
|
||||||
@@ -672,7 +656,7 @@ params:
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := pcfg.Compile("", false, ext, p.s.Log, p.s.conf.MediaTypes.Config); err != nil {
|
if err := pcfg.Compile("", false, ext, p.s.Log, p.s.conf.OutputFormats.Config, p.s.conf.MediaTypes.Config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,8 +813,8 @@ func (p *pageMeta) newContentConverter(ps *pageState, markup string) (converter.
|
|||||||
|
|
||||||
// The output formats this page will be rendered to.
|
// The output formats this page will be rendered to.
|
||||||
func (m *pageMeta) outputFormats() output.Formats {
|
func (m *pageMeta) outputFormats() output.Formats {
|
||||||
if len(m.configuredOutputFormats) > 0 {
|
if len(m.pageConfig.ConfiguredOutputFormats) > 0 {
|
||||||
return m.configuredOutputFormats
|
return m.pageConfig.ConfiguredOutputFormats
|
||||||
}
|
}
|
||||||
return m.s.conf.C.KindOutputFormats[m.Kind()]
|
return m.s.conf.C.KindOutputFormats[m.Kind()]
|
||||||
}
|
}
|
||||||
|
@@ -779,3 +779,45 @@ Single.
|
|||||||
|
|
||||||
b.AssertFileContent("public/tags/index.html", "Terms: mytag: 1|§s")
|
b.AssertFileContent("public/tags/index.html", "Terms: mytag: 1|§s")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContentAdapterOutputsIssue13689(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
|
||||||
|
[outputs]
|
||||||
|
page = ['html','json']
|
||||||
|
-- layouts/page.html --
|
||||||
|
html: {{ .Title }}
|
||||||
|
-- layouts/page.json --
|
||||||
|
json: {{ .Title }}
|
||||||
|
-- content/p1.md --
|
||||||
|
---
|
||||||
|
title: p1
|
||||||
|
---
|
||||||
|
-- content/p2.md --
|
||||||
|
---
|
||||||
|
title: p2
|
||||||
|
outputs:
|
||||||
|
- html
|
||||||
|
---
|
||||||
|
-- content/_content.gotmpl --
|
||||||
|
{{ $page := dict "path" "p3" "title" "p3" }}
|
||||||
|
{{ $.AddPage $page }}
|
||||||
|
|
||||||
|
{{ $page := dict "path" "p4" "title" "p4" "outputs" (slice "html") }}
|
||||||
|
{{ $.AddPage $page }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := hugolib.Test(t, files)
|
||||||
|
|
||||||
|
b.AssertFileExists("public/p1/index.html", true)
|
||||||
|
b.AssertFileExists("public/p1/index.json", true)
|
||||||
|
b.AssertFileExists("public/p2/index.html", true)
|
||||||
|
b.AssertFileExists("public/p2/index.json", false)
|
||||||
|
b.AssertFileExists("public/p3/index.html", true)
|
||||||
|
b.AssertFileExists("public/p3/index.json", true)
|
||||||
|
b.AssertFileExists("public/p4/index.html", true)
|
||||||
|
b.AssertFileExists("public/p4/index.json", false) // currently returns true
|
||||||
|
}
|
||||||
|
@@ -804,7 +804,7 @@ func (s *Site) initRenderFormats() {
|
|||||||
Tree: s.pageMap.treePages,
|
Tree: s.pageMap.treePages,
|
||||||
Handle: func(key string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
|
Handle: func(key string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
|
||||||
if p, ok := n.(*pageState); ok {
|
if p, ok := n.(*pageState); ok {
|
||||||
for _, f := range p.m.configuredOutputFormats {
|
for _, f := range p.m.pageConfig.ConfiguredOutputFormats {
|
||||||
if !formatSet[f.Name] {
|
if !formatSet[f.Name] {
|
||||||
formats = append(formats, f)
|
formats = append(formats, f)
|
||||||
formatSet[f.Name] = true
|
formatSet[f.Name] = true
|
||||||
|
@@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/gohugoio/hugo/hugofs/files"
|
"github.com/gohugoio/hugo/hugofs/files"
|
||||||
"github.com/gohugoio/hugo/markup"
|
"github.com/gohugoio/hugo/markup"
|
||||||
"github.com/gohugoio/hugo/media"
|
"github.com/gohugoio/hugo/media"
|
||||||
|
"github.com/gohugoio/hugo/output"
|
||||||
"github.com/gohugoio/hugo/resources/kinds"
|
"github.com/gohugoio/hugo/resources/kinds"
|
||||||
"github.com/gohugoio/hugo/resources/page"
|
"github.com/gohugoio/hugo/resources/page"
|
||||||
"github.com/gohugoio/hugo/resources/resource"
|
"github.com/gohugoio/hugo/resources/resource"
|
||||||
@@ -116,6 +117,7 @@ type PageConfig struct {
|
|||||||
// Compiled values.
|
// Compiled values.
|
||||||
CascadeCompiled *maps.Ordered[page.PageMatcher, maps.Params] `mapstructure:"-" json:"-"`
|
CascadeCompiled *maps.Ordered[page.PageMatcher, maps.Params] `mapstructure:"-" json:"-"`
|
||||||
ContentMediaType media.Type `mapstructure:"-" json:"-"`
|
ContentMediaType media.Type `mapstructure:"-" json:"-"`
|
||||||
|
ConfiguredOutputFormats output.Formats `mapstructure:"-" json:"-"`
|
||||||
IsFromContentAdapter bool `mapstructure:"-" json:"-"`
|
IsFromContentAdapter bool `mapstructure:"-" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +152,7 @@ func (p *PageConfig) Validate(pagesFromData bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compile sets up the page configuration after all fields have been set.
|
// Compile sets up the page configuration after all fields have been set.
|
||||||
func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, logger loggers.Logger, mediaTypes media.Types) error {
|
func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, logger loggers.Logger, outputFormats output.Formats, mediaTypes media.Types) error {
|
||||||
// In content adapters, we always get relative paths.
|
// In content adapters, we always get relative paths.
|
||||||
if basePath != "" {
|
if basePath != "" {
|
||||||
p.Path = path.Join(basePath, p.Path)
|
p.Path = path.Join(basePath, p.Path)
|
||||||
@@ -195,6 +197,15 @@ func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, lo
|
|||||||
p.Content.Markup = p.ContentMediaType.SubType
|
p.Content.Markup = p.ContentMediaType.SubType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(p.Outputs) > 0 {
|
||||||
|
outFormats, err := outputFormats.GetByNames(p.Outputs...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to resolve output formats %v: %w", p.Outputs, err)
|
||||||
|
} else {
|
||||||
|
p.ConfiguredOutputFormats = outFormats
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if pagesFromData {
|
if pagesFromData {
|
||||||
if p.Kind == "" {
|
if p.Kind == "" {
|
||||||
p.Kind = kinds.KindPage
|
p.Kind = kinds.KindPage
|
||||||
@@ -205,6 +216,7 @@ func (p *PageConfig) Compile(basePath string, pagesFromData bool, ext string, lo
|
|||||||
// but also because people tend to use use the filename to name their resources (with spaces and all),
|
// but also because people tend to use use the filename to name their resources (with spaces and all),
|
||||||
// and this isn't relevant when creating resources from an API where it's easy to add textual meta data.
|
// and this isn't relevant when creating resources from an API where it's easy to add textual meta data.
|
||||||
p.Path = paths.NormalizePathStringBasic(p.Path)
|
p.Path = paths.NormalizePathStringBasic(p.Path)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Cascade != nil {
|
if p.Cascade != nil {
|
||||||
|
@@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
"github.com/gohugoio/hugo/config/testconfig"
|
"github.com/gohugoio/hugo/config/testconfig"
|
||||||
"github.com/gohugoio/hugo/media"
|
"github.com/gohugoio/hugo/media"
|
||||||
|
"github.com/gohugoio/hugo/output"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/resources/page/pagemeta"
|
"github.com/gohugoio/hugo/resources/page/pagemeta"
|
||||||
|
|
||||||
@@ -175,7 +176,7 @@ func TestContentMediaTypeFromMarkup(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
var pc pagemeta.PageConfig
|
var pc pagemeta.PageConfig
|
||||||
pc.Content.Markup = test.in
|
pc.Content.Markup = test.in
|
||||||
c.Assert(pc.Compile("", true, "", logger, media.DefaultTypes), qt.IsNil)
|
c.Assert(pc.Compile("", true, "", logger, output.DefaultFormats, media.DefaultTypes), qt.IsNil)
|
||||||
c.Assert(pc.ContentMediaType.Type, qt.Equals, test.expected)
|
c.Assert(pc.ContentMediaType.Type, qt.Equals, test.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user