aboutsummaryrefslogtreecommitdiffhomepage
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2017-03-25 17:46:09 +0100
committerBjørn Erik Pedersen <[email protected]>2017-03-27 15:43:56 +0200
commit3cd97951f1cb6d7169a8a84a7b86984c05b2d35c (patch)
tree17adf86a0af091981ee5f8145db70cc251b4d994 /output
parentee75e2999b66bd9f258a241c487b6677cf2fa071 (diff)
downloadhugo-3cd97951f1cb6d7169a8a84a7b86984c05b2d35c.tar.gz
hugo-3cd97951f1cb6d7169a8a84a7b86984c05b2d35c.zip
hugolib, layout: Consolidate RSS template handling
Diffstat (limited to 'output')
-rw-r--r--output/layout.go69
-rw-r--r--output/layout_test.go9
2 files changed, 65 insertions, 13 deletions
diff --git a/output/layout.go b/output/layout.go
index 833a6cf4a..70bf6f7c2 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -48,7 +48,20 @@ func NewLayoutHandler(hasTheme bool) *LayoutHandler {
return &LayoutHandler{hasTheme: hasTheme, cache: make(map[layoutCacheKey][]string)}
}
+// RSS:
+// Home:"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"
+// Section: "section/" + section + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"
+// Taxonomy "taxonomy/" + singular + ".rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"
+// Tax term: taxonomy/" + singular + ".terms.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"
+
const (
+
+ // The RSS templates doesn't map easily into the regular pages.
+ layoutsRSSHome = `NAME.SUFFIX _default/NAME.SUFFIX _internal/_default/rss.xml`
+ layoutsRSSSection = `section/SECTION.NAME.SUFFIX _default/NAME.SUFFIX NAME.SUFFIX _internal/_default/rss.xml`
+ layoutsRSSTaxonomy = `taxonomy/SECTION.NAME.SUFFIX _default/NAME.SUFFIX NAME.SUFFIX _internal/_default/rss.xml`
+ layoutsRSSTaxonomyTerm = `taxonomy/SECTION.terms.NAME.SUFFIX _default/NAME.SUFFIX NAME.SUFFIX _internal/_default/rss.xml`
+
layoutsHome = "index.NAME.SUFFIX index.SUFFIX _default/list.NAME.SUFFIX _default/list.SUFFIX"
layoutsSection = `
section/SECTION.NAME.SUFFIX section/SECTION.SUFFIX
@@ -58,13 +71,13 @@ _default/list.NAME.SUFFIX _default/list.SUFFIX
indexes/SECTION.NAME.SUFFIX indexes/SECTION.SUFFIX
_default/indexes.NAME.SUFFIX _default/indexes.SUFFIX
`
- layoutTaxonomy = `
+ layoutsTaxonomy = `
taxonomy/SECTION.NAME.SUFFIX taxonomy/SECTION.SUFFIX
indexes/SECTION.NAME.SUFFIX indexes/SECTION.SUFFIX
_default/taxonomy.NAME.SUFFIX _default/taxonomy.SUFFIX
_default/list.NAME.SUFFIX _default/list.SUFFIX
`
- layoutTaxonomyTerm = `
+ layoutsTaxonomyTerm = `
taxonomy/SECTION.terms.NAME.SUFFIX taxonomy/SECTION.terms.SUFFIX
_default/terms.NAME.SUFFIX _default/terms.SUFFIX
indexes/indexes.NAME.SUFFIX indexes/indexes.SUFFIX
@@ -90,18 +103,27 @@ func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format)
layout = layoutOverride
}
- switch d.Kind {
- // TODO(bep) move the Kind constants some common place.
- case "home":
- layouts = resolveTemplate(layoutsHome, d, f)
- case "section":
- layouts = resolveTemplate(layoutsSection, d, f)
- case "taxonomy":
- layouts = resolveTemplate(layoutTaxonomy, d, f)
- case "taxonomyTerm":
- layouts = resolveTemplate(layoutTaxonomyTerm, d, f)
- case "page":
+ isRSS := f.Name == RSSType.Name
+
+ if d.Kind == "page" {
+ if isRSS {
+ return []string{}
+ }
layouts = regularPageLayouts(d.Type, layout, f)
+ } else {
+ if isRSS {
+ layouts = resolveListTemplate(d, f,
+ layoutsRSSHome,
+ layoutsRSSSection,
+ layoutsRSSTaxonomy,
+ layoutsRSSTaxonomyTerm)
+ } else {
+ layouts = resolveListTemplate(d, f,
+ layoutsHome,
+ layoutsSection,
+ layoutsTaxonomy,
+ layoutsTaxonomyTerm)
+ }
}
if l.hasTheme {
@@ -137,6 +159,27 @@ func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format)
return layouts
}
+func resolveListTemplate(d LayoutDescriptor, f Format,
+ homeLayouts,
+ sectionLayouts,
+ taxonomyLayouts,
+ taxonomyTermLayouts string) []string {
+ var layouts []string
+
+ switch d.Kind {
+ case "home":
+ layouts = resolveTemplate(homeLayouts, d, f)
+ case "section":
+ layouts = resolveTemplate(sectionLayouts, d, f)
+ case "taxonomy":
+ layouts = resolveTemplate(taxonomyLayouts, d, f)
+ case "taxonomyTerm":
+ layouts = resolveTemplate(taxonomyTermLayouts, d, f)
+ }
+
+ return layouts
+}
+
func resolveTemplate(templ string, d LayoutDescriptor, f Format) []string {
return strings.Fields(replaceKeyValues(templ,
"SUFFIX", f.MediaType.Suffix,
diff --git a/output/layout_test.go b/output/layout_test.go
index aa0657a36..ad9b65f2c 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -55,6 +55,15 @@ func TestLayout(t *testing.T) {
[]string{"myttype/mysubtype/mylayout.amp.html", "myttype/mysubtype/mylayout.html", "myttype/mylayout.amp.html"}},
{"Page with overridden layout", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"}, false, "myotherlayout", ampType,
[]string{"myttype/myotherlayout.amp.html", "myttype/myotherlayout.html"}},
+ // RSS
+ {"RSS Home with theme", LayoutDescriptor{Kind: "home"}, true, "", RSSType,
+ []string{"rss.xml", "_default/rss.xml", "theme/rss.xml", "theme/_default/rss.xml", "_internal/_default/rss.xml"}},
+ {"RSS Section", LayoutDescriptor{Kind: "section", Section: "sect1"}, false, "", RSSType,
+ []string{"section/sect1.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}},
+ {"RSS Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "tag"}, false, "", RSSType,
+ []string{"taxonomy/tag.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}},
+ {"RSS Taxonomy term", LayoutDescriptor{Kind: "taxonomyTerm", Section: "tag"}, false, "", RSSType,
+ []string{"taxonomy/tag.terms.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}},
} {
t.Run(this.name, func(t *testing.T) {
l := NewLayoutHandler(this.hasTheme)