diff options
Diffstat (limited to 'output')
-rw-r--r-- | output/layout.go | 2 | ||||
-rw-r--r-- | output/layout_base.go | 1 | ||||
-rw-r--r-- | output/layout_test.go | 10 | ||||
-rw-r--r-- | output/outputFormat.go | 26 | ||||
-rw-r--r-- | output/outputFormat_test.go | 58 |
5 files changed, 48 insertions, 49 deletions
diff --git a/output/layout.go b/output/layout.go index 01dcba6ed..cda6eb8a0 100644 --- a/output/layout.go +++ b/output/layout.go @@ -102,7 +102,7 @@ func (l *LayoutHandler) For(d LayoutDescriptor, layoutOverride string, f Format) layout = layoutOverride } - isRSS := f.Name == RSSType.Name + isRSS := f.Name == RSSFormat.Name if d.Kind == "page" { if isRSS { diff --git a/output/layout_base.go b/output/layout_base.go index 6b26a4c5b..47d0c3d48 100644 --- a/output/layout_base.go +++ b/output/layout_base.go @@ -34,7 +34,6 @@ type TemplateNames struct { MasterFilename string } -// TODO(bep) output this is refactoring in progress. type TemplateLookupDescriptor struct { // The full path to the site or theme root. WorkingDir string diff --git a/output/layout_test.go b/output/layout_test.go index ad9b65f2c..b38bd9c13 100644 --- a/output/layout_test.go +++ b/output/layout_test.go @@ -56,13 +56,13 @@ func TestLayout(t *testing.T) { {"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, + {"RSS Home with theme", LayoutDescriptor{Kind: "home"}, true, "", RSSFormat, []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, + {"RSS Section", LayoutDescriptor{Kind: "section", Section: "sect1"}, false, "", RSSFormat, []string{"section/sect1.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}}, - {"RSS Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "tag"}, false, "", RSSType, + {"RSS Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "tag"}, false, "", RSSFormat, []string{"taxonomy/tag.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}}, - {"RSS Taxonomy term", LayoutDescriptor{Kind: "taxonomyTerm", Section: "tag"}, false, "", RSSType, + {"RSS Taxonomy term", LayoutDescriptor{Kind: "taxonomyTerm", Section: "tag"}, false, "", RSSFormat, []string{"taxonomy/tag.terms.rss.xml", "_default/rss.xml", "rss.xml", "_internal/_default/rss.xml"}}, } { t.Run(this.name, func(t *testing.T) { @@ -90,7 +90,7 @@ func BenchmarkLayout(b *testing.B) { l := NewLayoutHandler(false) for i := 0; i < b.N; i++ { - layouts := l.For(descriptor, "", HTMLType) + layouts := l.For(descriptor, "", HTMLFormat) require.NotEmpty(b, layouts) } } diff --git a/output/outputFormat.go b/output/outputFormat.go index 7137775db..33ab71d43 100644 --- a/output/outputFormat.go +++ b/output/outputFormat.go @@ -22,9 +22,9 @@ import ( var ( // An ordered list of built-in output formats + // // See https://www.ampproject.org/learn/overview/ - // TODO(bep) output rename to AMPFormat etc. - AMPType = Format{ + AMPFormat = Format{ Name: "AMP", MediaType: media.HTMLType, BaseName: "index", @@ -33,7 +33,7 @@ var ( IsHTML: true, } - CalendarType = Format{ + CalendarFormat = Format{ Name: "Calendar", MediaType: media.CalendarType, IsPlainText: true, @@ -42,14 +42,14 @@ var ( Rel: "alternate", } - CSSType = Format{ + CSSFormat = Format{ Name: "CSS", MediaType: media.CSSType, BaseName: "styles", Rel: "stylesheet", } - HTMLType = Format{ + HTMLFormat = Format{ Name: "HTML", MediaType: media.HTMLType, BaseName: "index", @@ -57,7 +57,7 @@ var ( IsHTML: true, } - JSONType = Format{ + JSONFormat = Format{ Name: "JSON", MediaType: media.JSONType, BaseName: "index", @@ -65,7 +65,7 @@ var ( Rel: "alternate", } - RSSType = Format{ + RSSFormat = Format{ Name: "RSS", MediaType: media.RSSType, BaseName: "index", @@ -75,12 +75,12 @@ var ( ) var builtInTypes = map[string]Format{ - strings.ToLower(AMPType.Name): AMPType, - strings.ToLower(CalendarType.Name): CalendarType, - strings.ToLower(CSSType.Name): CSSType, - strings.ToLower(HTMLType.Name): HTMLType, - strings.ToLower(JSONType.Name): JSONType, - strings.ToLower(RSSType.Name): RSSType, + strings.ToLower(AMPFormat.Name): AMPFormat, + strings.ToLower(CalendarFormat.Name): CalendarFormat, + strings.ToLower(CSSFormat.Name): CSSFormat, + strings.ToLower(HTMLFormat.Name): HTMLFormat, + strings.ToLower(JSONFormat.Name): JSONFormat, + strings.ToLower(RSSFormat.Name): RSSFormat, } type Formats []Format diff --git a/output/outputFormat_test.go b/output/outputFormat_test.go index 5ef57f975..1d3700f4b 100644 --- a/output/outputFormat_test.go +++ b/output/outputFormat_test.go @@ -21,41 +21,41 @@ import ( ) func TestDefaultTypes(t *testing.T) { - require.Equal(t, "Calendar", CalendarType.Name) - require.Equal(t, media.CalendarType, CalendarType.MediaType) - require.Equal(t, "webcal://", CalendarType.Protocol) - require.Empty(t, CalendarType.Path) - require.True(t, CalendarType.IsPlainText) - require.False(t, CalendarType.IsHTML) - - require.Equal(t, "HTML", HTMLType.Name) - require.Equal(t, media.HTMLType, HTMLType.MediaType) - require.Empty(t, HTMLType.Path) - require.Empty(t, HTMLType.Protocol) // Will inherit the BaseURL protocol. - require.False(t, HTMLType.IsPlainText) - require.True(t, HTMLType.IsHTML) - - require.Equal(t, "AMP", AMPType.Name) - require.Equal(t, media.HTMLType, AMPType.MediaType) - require.Equal(t, "amp", AMPType.Path) - require.Empty(t, AMPType.Protocol) // Will inherit the BaseURL protocol. - require.False(t, AMPType.IsPlainText) - require.True(t, AMPType.IsHTML) - - require.Equal(t, "RSS", RSSType.Name) - require.Equal(t, media.RSSType, RSSType.MediaType) - require.Empty(t, RSSType.Path) - require.False(t, RSSType.IsPlainText) - require.True(t, RSSType.NoUgly) - require.False(t, CalendarType.IsHTML) + require.Equal(t, "Calendar", CalendarFormat.Name) + require.Equal(t, media.CalendarType, CalendarFormat.MediaType) + require.Equal(t, "webcal://", CalendarFormat.Protocol) + require.Empty(t, CalendarFormat.Path) + require.True(t, CalendarFormat.IsPlainText) + require.False(t, CalendarFormat.IsHTML) + + require.Equal(t, "HTML", HTMLFormat.Name) + require.Equal(t, media.HTMLType, HTMLFormat.MediaType) + require.Empty(t, HTMLFormat.Path) + require.Empty(t, HTMLFormat.Protocol) // Will inherit the BaseURL protocol. + require.False(t, HTMLFormat.IsPlainText) + require.True(t, HTMLFormat.IsHTML) + + require.Equal(t, "AMP", AMPFormat.Name) + require.Equal(t, media.HTMLType, AMPFormat.MediaType) + require.Equal(t, "amp", AMPFormat.Path) + require.Empty(t, AMPFormat.Protocol) // Will inherit the BaseURL protocol. + require.False(t, AMPFormat.IsPlainText) + require.True(t, AMPFormat.IsHTML) + + require.Equal(t, "RSS", RSSFormat.Name) + require.Equal(t, media.RSSType, RSSFormat.MediaType) + require.Empty(t, RSSFormat.Path) + require.False(t, RSSFormat.IsPlainText) + require.True(t, RSSFormat.NoUgly) + require.False(t, CalendarFormat.IsHTML) } func TestGetType(t *testing.T) { tp, _ := GetFormat("html") - require.Equal(t, HTMLType, tp) + require.Equal(t, HTMLFormat, tp) tp, _ = GetFormat("HTML") - require.Equal(t, HTMLType, tp) + require.Equal(t, HTMLFormat, tp) _, found := GetFormat("FOO") require.False(t, found) } |