shithub: hugo

Download patch

ref: 7da1b65968cd78970de8c8b61f5056dc7b0ec6b2
parent: 868f89d5c69c1f028b4d8900ccddd671a8d1922c
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Apr 4 10:10:20 EDT 2017

all: Use the configured output types to resolve template type

Closes #320

--- a/deps/deps.go
+++ b/deps/deps.go
@@ -8,6 +8,7 @@
 	"github.com/spf13/hugo/config"
 	"github.com/spf13/hugo/helpers"
 	"github.com/spf13/hugo/hugofs"
+	"github.com/spf13/hugo/output"
 	"github.com/spf13/hugo/tpl"
 	jww "github.com/spf13/jwalterweatherman"
 )
@@ -38,6 +39,9 @@
 	Translate func(translationID string, args ...interface{}) string `json:"-"`
 
 	Language *helpers.Language
+
+	// All the output formats available for the current site.
+	OutputFormatsConfig output.Formats
 
 	templateProvider ResourceProvider
 	WithTemplate     func(templ tpl.TemplateHandler) error `json:"-"`
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -101,6 +101,7 @@
 				return err
 			}
 
+			d.OutputFormatsConfig = s.outputFormatsConfig
 			s.Deps = d
 
 			if err = d.LoadResources(); err != nil {
@@ -112,6 +113,7 @@
 			if err != nil {
 				return err
 			}
+			d.OutputFormatsConfig = s.outputFormatsConfig
 			s.Deps = d
 		}
 
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -276,8 +276,7 @@
 // A prefix can be given to indicate a template namespace to load the templates
 // into, i.e. "_internal" etc.
 func (t *templateHandler) LoadTemplates(absPath, prefix string) {
-	// TODO(bep) output formats. Will have to get to complete list when that is ready.
-	t.loadTemplates(absPath, prefix, output.Formats{output.HTMLFormat, output.RSSFormat, output.CalendarFormat, output.AMPFormat, output.JSONFormat})
+	t.loadTemplates(absPath, prefix)
 
 }
 
@@ -376,7 +375,7 @@
 	t.text.clone = texttemplate.Must(t.text.cloneClone.Clone())
 }
 
-func (t *templateHandler) loadTemplates(absPath string, prefix string, formats output.Formats) {
+func (t *templateHandler) loadTemplates(absPath string, prefix string) {
 	t.Log.DEBUG.Printf("Load templates from path %q prefix %q", absPath, prefix)
 	walker := func(path string, fi os.FileInfo, err error) error {
 		if err != nil {
@@ -428,7 +427,7 @@
 				RelPath:       relPath,
 				Prefix:        prefix,
 				Theme:         t.PathSpec.Theme(),
-				OutputFormats: formats,
+				OutputFormats: t.OutputFormatsConfig,
 				FileExists: func(filename string) (bool, error) {
 					return helpers.Exists(filename, t.Fs.Source)
 				},