mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
hugolob: A first incorporation of output types in rendering
This commit is contained in:
parent
10de077164
commit
254cd89c8e
5 changed files with 25 additions and 16 deletions
|
@ -550,9 +550,9 @@ func (s *Site) preparePagesForRender(cfg *BuildCfg) {
|
||||||
|
|
||||||
// TODO(bep) output this is temporary
|
// TODO(bep) output this is temporary
|
||||||
if p.IsNode() && p.Kind != KindTaxonomyTerm {
|
if p.IsNode() && p.Kind != KindTaxonomyTerm {
|
||||||
p.mediaTypes = mediaTypesWithRSS
|
p.outputTypes = outputTypesWithRSS
|
||||||
} else {
|
} else {
|
||||||
p.mediaTypes = mediaTypesHTML
|
p.outputTypes = outputTypesHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
//analyze for raw stats
|
//analyze for raw stats
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/spf13/hugo/helpers"
|
"github.com/spf13/hugo/helpers"
|
||||||
|
"github.com/spf13/hugo/output"
|
||||||
"github.com/spf13/hugo/parser"
|
"github.com/spf13/hugo/parser"
|
||||||
|
|
||||||
"html/template"
|
"html/template"
|
||||||
|
@ -36,11 +37,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/spf13/hugo/output"
|
|
||||||
|
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
bp "github.com/spf13/hugo/bufferpool"
|
bp "github.com/spf13/hugo/bufferpool"
|
||||||
"github.com/spf13/hugo/media"
|
|
||||||
"github.com/spf13/hugo/source"
|
"github.com/spf13/hugo/source"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -203,9 +201,8 @@ type Page struct {
|
||||||
|
|
||||||
lang string
|
lang string
|
||||||
|
|
||||||
// The media types this page will be rendered to.
|
// The output types this page will be rendered to.
|
||||||
// TODO(bep) probably wrap this to add additional information like template evaluation?
|
outputTypes output.Types
|
||||||
mediaTypes media.Types
|
|
||||||
|
|
||||||
// Used to pick the correct template(s)
|
// Used to pick the correct template(s)
|
||||||
layoutIdentifier pageLayoutIdentifier
|
layoutIdentifier pageLayoutIdentifier
|
||||||
|
@ -676,6 +673,7 @@ func (p *Page) Section() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Page) layouts(layouts ...string) []string {
|
func (p *Page) layouts(layouts ...string) []string {
|
||||||
|
// TODO(bep) output
|
||||||
if len(p.layoutsCalculated) > 0 {
|
if len(p.layoutsCalculated) > 0 {
|
||||||
return p.layoutsCalculated
|
return p.layoutsCalculated
|
||||||
}
|
}
|
||||||
|
@ -1879,8 +1877,8 @@ func kindFromFilename(filename string) string {
|
||||||
|
|
||||||
// TODO(bep) output
|
// TODO(bep) output
|
||||||
var (
|
var (
|
||||||
mediaTypesWithRSS = media.Types{media.HTMLType, media.RSSType}
|
outputTypesWithRSS = output.Types{output.HTMLType, output.RSSType}
|
||||||
mediaTypesHTML = media.Types{media.HTMLType}
|
outputTypesHTML = output.Types{output.HTMLType}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Page) setValuesForKind(s *Site) {
|
func (p *Page) setValuesForKind(s *Site) {
|
||||||
|
|
|
@ -1676,6 +1676,7 @@ func errorCollator(results <-chan error, errs chan<- error) {
|
||||||
close(errs)
|
close(errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(bep) output move
|
||||||
func (s *Site) appendThemeTemplates(in []string) []string {
|
func (s *Site) appendThemeTemplates(in []string) []string {
|
||||||
if !s.PathSpec.ThemeSet() {
|
if !s.PathSpec.ThemeSet() {
|
||||||
return in
|
return in
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
bp "github.com/spf13/hugo/bufferpool"
|
bp "github.com/spf13/hugo/bufferpool"
|
||||||
"github.com/spf13/hugo/media"
|
"github.com/spf13/hugo/output"
|
||||||
)
|
)
|
||||||
|
|
||||||
// renderPages renders pages each corresponding to a markdown file.
|
// renderPages renders pages each corresponding to a markdown file.
|
||||||
|
@ -64,13 +64,21 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for p := range pages {
|
for p := range pages {
|
||||||
// TODO(bep) output
|
// TODO(bep) output
|
||||||
for _, mediaType := range p.mediaTypes {
|
for _, outputType := range p.outputTypes {
|
||||||
switch mediaType {
|
var layouts []string
|
||||||
|
|
||||||
case media.HTMLType:
|
if len(p.layoutsCalculated) > 0 {
|
||||||
|
// TODO(bep) output
|
||||||
|
layouts = p.layoutsCalculated
|
||||||
|
} else {
|
||||||
|
layouts = s.layoutHandler.For(p.layoutIdentifier, "", outputType)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch outputType {
|
||||||
|
|
||||||
|
case output.HTMLType:
|
||||||
targetPath := p.TargetPath()
|
targetPath := p.TargetPath()
|
||||||
|
|
||||||
layouts := p.layouts()
|
|
||||||
s.Log.DEBUG.Printf("Render %s to %q with layouts %q", p.Kind, targetPath, layouts)
|
s.Log.DEBUG.Printf("Render %s to %q with layouts %q", p.Kind, targetPath, layouts)
|
||||||
|
|
||||||
if err := s.renderAndWritePage("page "+p.FullFilePath(), targetPath, p, s.appendThemeTemplates(layouts)...); err != nil {
|
if err := s.renderAndWritePage("page "+p.FullFilePath(), targetPath, p, s.appendThemeTemplates(layouts)...); err != nil {
|
||||||
|
@ -84,7 +92,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case media.RSSType:
|
case output.RSSType:
|
||||||
if err := s.renderRSS(p); err != nil {
|
if err := s.renderRSS(p); err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Types []Type
|
||||||
|
|
||||||
// Type represents an output represenation, usually to a file on disk.
|
// Type represents an output represenation, usually to a file on disk.
|
||||||
type Type struct {
|
type Type struct {
|
||||||
// The Name is used as an identifier. Internal output types (i.e. HTML and RSS)
|
// The Name is used as an identifier. Internal output types (i.e. HTML and RSS)
|
||||||
|
|
Loading…
Reference in a new issue