mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Rename OutputType to OutputFormat
This commit is contained in:
parent
6bf010fed4
commit
4c2abe0015
14 changed files with 84 additions and 84 deletions
|
@ -176,8 +176,8 @@ func (h *HugoSites) assemble(config *BuildCfg) error {
|
||||||
for _, s := range h.Sites {
|
for _, s := range h.Sites {
|
||||||
for _, p := range s.Pages {
|
for _, p := range s.Pages {
|
||||||
// May have been set in front matter
|
// May have been set in front matter
|
||||||
if len(p.outputTypes) == 0 {
|
if len(p.outputFormats) == 0 {
|
||||||
p.outputTypes = s.defaultOutputDefinitions.ForKind(p.Kind)
|
p.outputFormats = s.defaultOutputDefinitions.ForKind(p.Kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.assembleMenus()
|
s.assembleMenus()
|
||||||
|
|
|
@ -198,10 +198,10 @@ type Page struct {
|
||||||
|
|
||||||
lang string
|
lang string
|
||||||
|
|
||||||
// The output types this page will be rendered to.
|
// The output formats this page will be rendered to.
|
||||||
outputTypes output.Types
|
outputFormats output.Formats
|
||||||
|
|
||||||
// This is the PageOutput that represents the first item in outputTypes.
|
// This is the PageOutput that represents the first item in outputFormats.
|
||||||
// Use with care, as there are potential for inifinite loops.
|
// Use with care, as there are potential for inifinite loops.
|
||||||
mainPageOutput *PageOutput
|
mainPageOutput *PageOutput
|
||||||
|
|
||||||
|
@ -792,7 +792,7 @@ func (p *Page) Extension() string {
|
||||||
return p.extension
|
return p.extension
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// TODO(bep) return p.outputType.MediaType.Suffix
|
// TODO(bep) return MediaType.Suffix
|
||||||
|
|
||||||
// TODO(bep) remove this config option =>
|
// TODO(bep) remove this config option =>
|
||||||
return p.s.Cfg.GetString("defaultExtension")
|
return p.s.Cfg.GetString("defaultExtension")
|
||||||
|
@ -952,13 +952,13 @@ func (p *Page) update(f interface{}) error {
|
||||||
case "outputs":
|
case "outputs":
|
||||||
outputs := cast.ToStringSlice(v)
|
outputs := cast.ToStringSlice(v)
|
||||||
if len(outputs) > 0 {
|
if len(outputs) > 0 {
|
||||||
// Output types are exlicitly set in front matter, use those.
|
// Output formats are exlicitly set in front matter, use those.
|
||||||
outTypes, err := output.GetTypes(outputs...)
|
outFormats, err := output.GetTypes(outputs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.s.Log.ERROR.Printf("Failed to resolve output types: %s", err)
|
p.s.Log.ERROR.Printf("Failed to resolve output formats: %s", err)
|
||||||
} else {
|
} else {
|
||||||
p.outputTypes = outTypes
|
p.outputFormats = outFormats
|
||||||
p.Params[loki] = outTypes
|
p.Params[loki] = outFormats
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,11 @@ type PageOutput struct {
|
||||||
// Keep this to create URL/path variations, i.e. paginators.
|
// Keep this to create URL/path variations, i.e. paginators.
|
||||||
targetPathDescriptor targetPathDescriptor
|
targetPathDescriptor targetPathDescriptor
|
||||||
|
|
||||||
outputType output.Type
|
outputFormat output.Format
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PageOutput) targetPath(addends ...string) (string, error) {
|
func (p *PageOutput) targetPath(addends ...string) (string, error) {
|
||||||
tp, err := p.createTargetPath(p.outputType, addends...)
|
tp, err := p.createTargetPath(p.outputFormat, addends...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,13 @@ func (p *PageOutput) targetPath(addends ...string) (string, error) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPageOutput(p *Page, createCopy bool, outputType output.Type) (*PageOutput, error) {
|
func newPageOutput(p *Page, createCopy bool, f output.Format) (*PageOutput, error) {
|
||||||
if createCopy {
|
if createCopy {
|
||||||
p.initURLs()
|
p.initURLs()
|
||||||
p = p.copy()
|
p = p.copy()
|
||||||
}
|
}
|
||||||
|
|
||||||
td, err := p.createTargetPathDescriptor(outputType)
|
td, err := p.createTargetPathDescriptor(f)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -57,7 +57,7 @@ func newPageOutput(p *Page, createCopy bool, outputType output.Type) (*PageOutpu
|
||||||
|
|
||||||
return &PageOutput{
|
return &PageOutput{
|
||||||
Page: p,
|
Page: p,
|
||||||
outputType: outputType,
|
outputFormat: f,
|
||||||
targetPathDescriptor: td,
|
targetPathDescriptor: td,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ func newPageOutput(p *Page, createCopy bool, outputType output.Type) (*PageOutpu
|
||||||
// copy creates a copy of this PageOutput with the lazy sync.Once vars reset
|
// copy creates a copy of this PageOutput with the lazy sync.Once vars reset
|
||||||
// so they will be evaluated again, for word count calculations etc.
|
// so they will be evaluated again, for word count calculations etc.
|
||||||
func (p *PageOutput) copy() *PageOutput {
|
func (p *PageOutput) copy() *PageOutput {
|
||||||
c, err := newPageOutput(p.Page, true, p.outputType)
|
c, err := newPageOutput(p.Page, true, p.outputFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ import (
|
||||||
type targetPathDescriptor struct {
|
type targetPathDescriptor struct {
|
||||||
PathSpec *helpers.PathSpec
|
PathSpec *helpers.PathSpec
|
||||||
|
|
||||||
Type output.Type
|
Type output.Format
|
||||||
Kind string
|
Kind string
|
||||||
|
|
||||||
Sections []string
|
Sections []string
|
||||||
|
@ -66,10 +66,10 @@ type targetPathDescriptor struct {
|
||||||
UglyURLs bool
|
UglyURLs bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// createTargetPathDescriptor adapts a Page and the given output.Type into
|
// createTargetPathDescriptor adapts a Page and the given output.Format into
|
||||||
// a targetPathDescriptor. This descriptor can then be used to create paths
|
// a targetPathDescriptor. This descriptor can then be used to create paths
|
||||||
// and URLs for this Page.
|
// and URLs for this Page.
|
||||||
func (p *Page) createTargetPathDescriptor(t output.Type) (targetPathDescriptor, error) {
|
func (p *Page) createTargetPathDescriptor(t output.Format) (targetPathDescriptor, error) {
|
||||||
d := targetPathDescriptor{
|
d := targetPathDescriptor{
|
||||||
PathSpec: p.s.PathSpec,
|
PathSpec: p.s.PathSpec,
|
||||||
Type: t,
|
Type: t,
|
||||||
|
@ -107,9 +107,9 @@ func (p *Page) createTargetPathDescriptor(t output.Type) (targetPathDescriptor,
|
||||||
}
|
}
|
||||||
|
|
||||||
// createTargetPath creates the target filename for this Page for the given
|
// createTargetPath creates the target filename for this Page for the given
|
||||||
// output.Type. Some additional URL parts can also be provided, the typical
|
// output.Format. Some additional URL parts can also be provided, the typical
|
||||||
// use case being pagination.
|
// use case being pagination.
|
||||||
func (p *Page) createTargetPath(t output.Type, addends ...string) (string, error) {
|
func (p *Page) createTargetPath(t output.Format, addends ...string) (string, error) {
|
||||||
d, err := p.createTargetPathDescriptor(t)
|
d, err := p.createTargetPathDescriptor(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", nil
|
return "", nil
|
||||||
|
@ -205,20 +205,20 @@ func createTargetPath(d targetPathDescriptor) string {
|
||||||
|
|
||||||
func (p *Page) createRelativePermalink() string {
|
func (p *Page) createRelativePermalink() string {
|
||||||
|
|
||||||
if len(p.outputTypes) == 0 {
|
if len(p.outputFormats) == 0 {
|
||||||
panic(fmt.Sprintf("Page %q missing output format(s)", p.Title))
|
panic(fmt.Sprintf("Page %q missing output format(s)", p.Title))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Choose the main output format. In most cases, this will be HTML.
|
// Choose the main output format. In most cases, this will be HTML.
|
||||||
outputType := p.outputTypes[0]
|
outFormat := p.outputFormats[0]
|
||||||
tp, err := p.createTargetPath(outputType)
|
tp, err := p.createTargetPath(outFormat)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.s.Log.ERROR.Printf("Failed to create permalink for page %q: %s", p.FullFilePath(), err)
|
p.s.Log.ERROR.Printf("Failed to create permalink for page %q: %s", p.FullFilePath(), err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
tp = strings.TrimSuffix(tp, outputType.BaseFilename())
|
tp = strings.TrimSuffix(tp, outFormat.BaseFilename())
|
||||||
|
|
||||||
return p.s.PathSpec.URLizeFilename(tp)
|
return p.s.PathSpec.URLizeFilename(tp)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1661,7 +1661,7 @@ func (s *Site) kindFromSections(sections []string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) layouts(p *PageOutput) []string {
|
func (s *Site) layouts(p *PageOutput) []string {
|
||||||
return s.layoutHandler.For(p.layoutIdentifier, "", p.outputType)
|
return s.layoutHandler.For(p.layoutIdentifier, "", p.outputFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) preparePages() error {
|
func (s *Site) preparePages() error {
|
||||||
|
@ -1806,7 +1806,7 @@ func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layout
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) renderAndWritePage(tp output.Type, name string, dest string, d interface{}, layouts ...string) error {
|
func (s *Site) renderAndWritePage(f output.Format, name string, dest string, d interface{}, layouts ...string) error {
|
||||||
renderBuffer := bp.GetBuffer()
|
renderBuffer := bp.GetBuffer()
|
||||||
defer bp.PutBuffer(renderBuffer)
|
defer bp.PutBuffer(renderBuffer)
|
||||||
|
|
||||||
|
@ -1878,7 +1878,7 @@ Your rendered home page is blank: /index.html is zero-length
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.writeDestPage(tp, dest, outBuffer); err != nil {
|
if err = w.writeDestPage(f, dest, outBuffer); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2061,7 +2061,7 @@ func (s *Site) newNodePage(typ string) *Page {
|
||||||
Data: make(map[string]interface{}),
|
Data: make(map[string]interface{}),
|
||||||
Site: &s.Info,
|
Site: &s.Info,
|
||||||
s: s}
|
s: s}
|
||||||
p.outputTypes = p.s.defaultOutputDefinitions.ForKind(typ)
|
p.outputFormats = p.s.defaultOutputDefinitions.ForKind(typ)
|
||||||
p.layoutIdentifier = pageLayoutIdentifier{p}
|
p.layoutIdentifier = pageLayoutIdentifier{p}
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ type siteOutputDefinition struct {
|
||||||
// Comma separated list (for now).
|
// Comma separated list (for now).
|
||||||
ExcludedKinds string
|
ExcludedKinds string
|
||||||
|
|
||||||
Outputs []output.Type
|
Outputs []output.Format
|
||||||
}
|
}
|
||||||
|
|
||||||
func (defs siteOutputDefinitions) ForKind(kind string) []output.Type {
|
func (defs siteOutputDefinitions) ForKind(kind string) []output.Format {
|
||||||
var result []output.Type
|
var result []output.Format
|
||||||
|
|
||||||
for _, def := range defs {
|
for _, def := range defs {
|
||||||
if def.ExcludedKinds == "" || !strings.Contains(def.ExcludedKinds, kind) {
|
if def.ExcludedKinds == "" || !strings.Contains(def.ExcludedKinds, kind) {
|
||||||
|
@ -49,7 +49,7 @@ func createSiteOutputDefinitions(cfg config.Provider) siteOutputDefinitions {
|
||||||
var defs siteOutputDefinitions
|
var defs siteOutputDefinitions
|
||||||
|
|
||||||
// All have HTML
|
// All have HTML
|
||||||
defs = append(defs, siteOutputDefinition{ExcludedKinds: "", Outputs: []output.Type{output.HTMLType}})
|
defs = append(defs, siteOutputDefinition{ExcludedKinds: "", Outputs: []output.Format{output.HTMLType}})
|
||||||
|
|
||||||
// TODO(bep) output deprecate rssURI
|
// TODO(bep) output deprecate rssURI
|
||||||
rssBase := cfg.GetString("rssURI")
|
rssBase := cfg.GetString("rssURI")
|
||||||
|
@ -63,7 +63,7 @@ func createSiteOutputDefinitions(cfg config.Provider) siteOutputDefinitions {
|
||||||
rssType.BaseName = rssBase
|
rssType.BaseName = rssBase
|
||||||
|
|
||||||
// Some have RSS
|
// Some have RSS
|
||||||
defs = append(defs, siteOutputDefinition{ExcludedKinds: "page", Outputs: []output.Type{rssType}})
|
defs = append(defs, siteOutputDefinition{ExcludedKinds: "page", Outputs: []output.Format{rssType}})
|
||||||
|
|
||||||
return defs
|
return defs
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,10 @@ func TestDefaultOutputDefinitions(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
kind string
|
kind string
|
||||||
want []output.Type
|
want []output.Format
|
||||||
}{
|
}{
|
||||||
{"RSS not for regular pages", KindPage, []output.Type{output.HTMLType}},
|
{"RSS not for regular pages", KindPage, []output.Format{output.HTMLType}},
|
||||||
{"Home Sweet Home", KindHome, []output.Type{output.HTMLType, output.RSSType}},
|
{"Home Sweet Home", KindHome, []output.Format{output.HTMLType, output.RSSType}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -88,7 +88,7 @@ outputs: ["json"]
|
||||||
|
|
||||||
require.NotNil(t, home)
|
require.NotNil(t, home)
|
||||||
|
|
||||||
require.Len(t, home.outputTypes, 1)
|
require.Len(t, home.outputFormats, 1)
|
||||||
|
|
||||||
// TODO(bep) output assert template/text
|
// TODO(bep) output assert template/text
|
||||||
|
|
||||||
|
|
|
@ -65,10 +65,10 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
var mainPageOutput *PageOutput
|
var mainPageOutput *PageOutput
|
||||||
|
|
||||||
for page := range pages {
|
for page := range pages {
|
||||||
for i, outputType := range page.outputTypes {
|
for i, outFormat := range page.outputFormats {
|
||||||
pageOutput, err := newPageOutput(page, i > 0, outputType)
|
pageOutput, err := newPageOutput(page, i > 0, outFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.ERROR.Printf("Failed to create output page for type %q for page %q: %s", outputType.Name, page, err)
|
s.Log.ERROR.Printf("Failed to create output page for type %q for page %q: %s", outFormat.Name, page, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
@ -85,7 +85,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
layouts = s.layouts(pageOutput)
|
layouts = s.layouts(pageOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch pageOutput.outputType.Name {
|
switch pageOutput.outputFormat.Name {
|
||||||
|
|
||||||
case "RSS":
|
case "RSS":
|
||||||
if err := s.renderRSS(pageOutput); err != nil {
|
if err := s.renderRSS(pageOutput); err != nil {
|
||||||
|
@ -94,13 +94,13 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
|
||||||
default:
|
default:
|
||||||
targetPath, err := pageOutput.targetPath()
|
targetPath, err := pageOutput.targetPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.Log.ERROR.Printf("Failed to create target path for output %q for page %q: %s", outputType.Name, page, err)
|
s.Log.ERROR.Printf("Failed to create target path for output %q for page %q: %s", outFormat.Name, page, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Log.DEBUG.Printf("Render %s to %q with layouts %q", pageOutput.Kind, targetPath, layouts)
|
s.Log.DEBUG.Printf("Render %s to %q with layouts %q", pageOutput.Kind, targetPath, layouts)
|
||||||
|
|
||||||
if err := s.renderAndWritePage(outputType, "page "+pageOutput.FullFilePath(), targetPath, pageOutput, layouts...); err != nil {
|
if err := s.renderAndWritePage(outFormat, "page "+pageOutput.FullFilePath(), targetPath, pageOutput, layouts...); err != nil {
|
||||||
results <- err
|
results <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ func (s *Site) renderPaginator(p *PageOutput) error {
|
||||||
addend := fmt.Sprintf("/%s/%d", paginatePath, pageNumber)
|
addend := fmt.Sprintf("/%s/%d", paginatePath, pageNumber)
|
||||||
targetPath, _ := p.targetPath(addend)
|
targetPath, _ := p.targetPath(addend)
|
||||||
|
|
||||||
if err := s.renderAndWritePage(p.outputType, pagerNode.Title,
|
if err := s.renderAndWritePage(p.outputFormat, pagerNode.Title,
|
||||||
targetPath, pagerNode, p.layouts()...); err != nil {
|
targetPath, pagerNode, p.layouts()...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// We may find some abstractions/interface(s) here once we star with
|
// We may find some abstractions/interface(s) here once we star with
|
||||||
// "Multiple Output Types".
|
// "Multiple Output Formats".
|
||||||
type siteWriter struct {
|
type siteWriter struct {
|
||||||
langDir string
|
langDir string
|
||||||
publishDir string
|
publishDir string
|
||||||
|
@ -40,8 +40,8 @@ type siteWriter struct {
|
||||||
log *jww.Notepad
|
log *jww.Notepad
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w siteWriter) targetPathPage(tp output.Type, src string) (string, error) {
|
func (w siteWriter) targetPathPage(f output.Format, src string) (string, error) {
|
||||||
dir, err := w.baseTargetPathPage(tp, src)
|
dir, err := w.baseTargetPathPage(f, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (w siteWriter) targetPathPage(tp output.Type, src string) (string, error) {
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w siteWriter) baseTargetPathPage(tp output.Type, src string) (string, error) {
|
func (w siteWriter) baseTargetPathPage(f output.Format, src string) (string, error) {
|
||||||
if src == helpers.FilePathSeparator {
|
if src == helpers.FilePathSeparator {
|
||||||
return "index.html", nil
|
return "index.html", nil
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ func filename(f string) string {
|
||||||
return f[:len(f)-len(ext)]
|
return f[:len(f)-len(ext)]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w siteWriter) writeDestPage(tp output.Type, path string, reader io.Reader) error {
|
func (w siteWriter) writeDestPage(f output.Format, path string, reader io.Reader) error {
|
||||||
w.log.DEBUG.Println("creating page:", path)
|
w.log.DEBUG.Println("creating page:", path)
|
||||||
path, _ = w.targetPathFile(path)
|
path, _ = w.targetPathFile(path)
|
||||||
// TODO(bep) output remove this file ... targetPath, err := w.targetPathPage(tp, path)
|
// TODO(bep) output remove this file ... targetPath, err := w.targetPathPage(tp, path)
|
||||||
|
|
|
@ -127,9 +127,9 @@ func _TestTargetPathUglyURLs(t *testing.T) {
|
||||||
w := siteWriter{log: newErrorLogger(), uglyURLs: true}
|
w := siteWriter{log: newErrorLogger(), uglyURLs: true}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
outputType output.Type
|
outFormat output.Format
|
||||||
content string
|
content string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{output.HTMLType, "foo.html", "foo.html"},
|
{output.HTMLType, "foo.html", "foo.html"},
|
||||||
{output.HTMLType, "/", "index.html"},
|
{output.HTMLType, "/", "index.html"},
|
||||||
|
@ -139,7 +139,7 @@ func _TestTargetPathUglyURLs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
dest, err := w.targetPathPage(test.outputType, filepath.FromSlash(test.content))
|
dest, err := w.targetPathPage(test.outFormat, filepath.FromSlash(test.content))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf(" [%d] targetPathPage returned an unexpected err: %s", i, err)
|
t.Fatalf(" [%d] targetPathPage returned an unexpected err: %s", i, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ indexes/indexes.NAME.SUFFIX indexes/indexes.SUFFIX
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type) []string {
|
func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, f Format) []string {
|
||||||
var layouts []string
|
var layouts []string
|
||||||
|
|
||||||
layout := id.PageLayout()
|
layout := id.PageLayout()
|
||||||
|
@ -72,15 +72,15 @@ func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type)
|
||||||
switch id.PageKind() {
|
switch id.PageKind() {
|
||||||
// TODO(bep) move the Kind constants some common place.
|
// TODO(bep) move the Kind constants some common place.
|
||||||
case "home":
|
case "home":
|
||||||
layouts = resolveTemplate(layoutsHome, id, tp)
|
layouts = resolveTemplate(layoutsHome, id, f)
|
||||||
case "section":
|
case "section":
|
||||||
layouts = resolveTemplate(layoutsSection, id, tp)
|
layouts = resolveTemplate(layoutsSection, id, f)
|
||||||
case "taxonomy":
|
case "taxonomy":
|
||||||
layouts = resolveTemplate(layoutTaxonomy, id, tp)
|
layouts = resolveTemplate(layoutTaxonomy, id, f)
|
||||||
case "taxonomyTerm":
|
case "taxonomyTerm":
|
||||||
layouts = resolveTemplate(layoutTaxonomyTerm, id, tp)
|
layouts = resolveTemplate(layoutTaxonomyTerm, id, f)
|
||||||
case "page":
|
case "page":
|
||||||
layouts = regularPageLayouts(id.PageType(), layout, tp)
|
layouts = regularPageLayouts(id.PageType(), layout, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
if l.hasTheme {
|
if l.hasTheme {
|
||||||
|
@ -112,10 +112,10 @@ func (l *LayoutHandler) For(id LayoutIdentifier, layoutOverride string, tp Type)
|
||||||
return layouts
|
return layouts
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveTemplate(templ string, id LayoutIdentifier, tp Type) []string {
|
func resolveTemplate(templ string, id LayoutIdentifier, f Format) []string {
|
||||||
return strings.Fields(replaceKeyValues(templ,
|
return strings.Fields(replaceKeyValues(templ,
|
||||||
"SUFFIX", tp.MediaType.Suffix,
|
"SUFFIX", f.MediaType.Suffix,
|
||||||
"NAME", strings.ToLower(tp.Name),
|
"NAME", strings.ToLower(f.Name),
|
||||||
"SECTION", id.PageSection()))
|
"SECTION", id.PageSection()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,13 +124,13 @@ func replaceKeyValues(s string, oldNew ...string) string {
|
||||||
return replacer.Replace(s)
|
return replacer.Replace(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func regularPageLayouts(types string, layout string, tp Type) (layouts []string) {
|
func regularPageLayouts(types string, layout string, f Format) (layouts []string) {
|
||||||
if layout == "" {
|
if layout == "" {
|
||||||
layout = "single"
|
layout = "single"
|
||||||
}
|
}
|
||||||
|
|
||||||
suffix := tp.MediaType.Suffix
|
suffix := f.MediaType.Suffix
|
||||||
name := strings.ToLower(tp.Name)
|
name := strings.ToLower(f.Name)
|
||||||
|
|
||||||
if types != "" {
|
if types != "" {
|
||||||
t := strings.Split(types, "/")
|
t := strings.Split(types, "/")
|
||||||
|
|
|
@ -44,7 +44,7 @@ func (l testLayoutIdentifier) PageSection() string {
|
||||||
return l.pageSection
|
return l.pageSection
|
||||||
}
|
}
|
||||||
|
|
||||||
var ampType = Type{
|
var ampType = Format{
|
||||||
Name: "AMP",
|
Name: "AMP",
|
||||||
MediaType: media.HTMLType,
|
MediaType: media.HTMLType,
|
||||||
BaseName: "index",
|
BaseName: "index",
|
||||||
|
@ -57,7 +57,7 @@ func TestLayout(t *testing.T) {
|
||||||
li testLayoutIdentifier
|
li testLayoutIdentifier
|
||||||
hasTheme bool
|
hasTheme bool
|
||||||
layoutOverride string
|
layoutOverride string
|
||||||
tp Type
|
tp Format
|
||||||
expect []string
|
expect []string
|
||||||
}{
|
}{
|
||||||
{"Home", testLayoutIdentifier{"home", "", "", ""}, true, "", ampType,
|
{"Home", testLayoutIdentifier{"home", "", "", ""}, true, "", ampType,
|
||||||
|
|
|
@ -23,33 +23,33 @@ import (
|
||||||
var (
|
var (
|
||||||
// An ordered list of built-in output formats
|
// An ordered list of built-in output formats
|
||||||
// See https://www.ampproject.org/learn/overview/
|
// See https://www.ampproject.org/learn/overview/
|
||||||
AMPType = Type{
|
AMPType = Format{
|
||||||
Name: "AMP",
|
Name: "AMP",
|
||||||
MediaType: media.HTMLType,
|
MediaType: media.HTMLType,
|
||||||
BaseName: "index",
|
BaseName: "index",
|
||||||
Path: "amp",
|
Path: "amp",
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSType = Type{
|
CSSType = Format{
|
||||||
Name: "CSS",
|
Name: "CSS",
|
||||||
MediaType: media.CSSType,
|
MediaType: media.CSSType,
|
||||||
BaseName: "styles",
|
BaseName: "styles",
|
||||||
}
|
}
|
||||||
|
|
||||||
HTMLType = Type{
|
HTMLType = Format{
|
||||||
Name: "HTML",
|
Name: "HTML",
|
||||||
MediaType: media.HTMLType,
|
MediaType: media.HTMLType,
|
||||||
BaseName: "index",
|
BaseName: "index",
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONType = Type{
|
JSONType = Format{
|
||||||
Name: "JSON",
|
Name: "JSON",
|
||||||
MediaType: media.JSONType,
|
MediaType: media.JSONType,
|
||||||
BaseName: "index",
|
BaseName: "index",
|
||||||
IsPlainText: true,
|
IsPlainText: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
RSSType = Type{
|
RSSType = Format{
|
||||||
Name: "RSS",
|
Name: "RSS",
|
||||||
MediaType: media.RSSType,
|
MediaType: media.RSSType,
|
||||||
BaseName: "index",
|
BaseName: "index",
|
||||||
|
@ -57,7 +57,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var builtInTypes = map[string]Type{
|
var builtInTypes = map[string]Format{
|
||||||
strings.ToLower(AMPType.Name): AMPType,
|
strings.ToLower(AMPType.Name): AMPType,
|
||||||
strings.ToLower(CSSType.Name): CSSType,
|
strings.ToLower(CSSType.Name): CSSType,
|
||||||
strings.ToLower(HTMLType.Name): HTMLType,
|
strings.ToLower(HTMLType.Name): HTMLType,
|
||||||
|
@ -65,11 +65,11 @@ var builtInTypes = map[string]Type{
|
||||||
strings.ToLower(RSSType.Name): RSSType,
|
strings.ToLower(RSSType.Name): RSSType,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Types []Type
|
type Formats []Format
|
||||||
|
|
||||||
// Type represents an output represenation, usually to a file on disk.
|
// Format represents an output represenation, usually to a file on disk.
|
||||||
type Type struct {
|
type Format 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 formats (i.e. HTML and RSS)
|
||||||
// can be overridden by providing a new definition for those types.
|
// can be overridden by providing a new definition for those types.
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ type Type struct {
|
||||||
NoUgly bool
|
NoUgly bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetType(key string) (Type, bool) {
|
func GetType(key string) (Format, bool) {
|
||||||
found, ok := builtInTypes[key]
|
found, ok := builtInTypes[key]
|
||||||
if !ok {
|
if !ok {
|
||||||
found, ok = builtInTypes[strings.ToLower(key)]
|
found, ok = builtInTypes[strings.ToLower(key)]
|
||||||
|
@ -101,13 +101,13 @@ func GetType(key string) (Type, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(bep) outputs rewamp on global config?
|
// TODO(bep) outputs rewamp on global config?
|
||||||
func GetTypes(keys ...string) (Types, error) {
|
func GetTypes(keys ...string) (Formats, error) {
|
||||||
var types []Type
|
var types []Format
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
tpe, ok := GetType(key)
|
tpe, ok := GetType(key)
|
||||||
if !ok {
|
if !ok {
|
||||||
return types, fmt.Errorf("OutputType with key %q not found", key)
|
return types, fmt.Errorf("OutputFormat with key %q not found", key)
|
||||||
}
|
}
|
||||||
types = append(types, tpe)
|
types = append(types, tpe)
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,6 @@ func GetTypes(keys ...string) (Types, error) {
|
||||||
return types, nil
|
return types, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Type) BaseFilename() string {
|
func (t Format) BaseFilename() string {
|
||||||
return t.BaseName + "." + t.MediaType.Suffix
|
return t.BaseName + "." + t.MediaType.Suffix
|
||||||
}
|
}
|
Loading…
Reference in a new issue