ref: 09c88e84d196e6c0943b220cd6526d3473c530b6
parent: 24c1770288803bd7a344f5903dd4f03cccc6a8f0
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Mar 25 15:36:50 EDT 2017
output: Rename HTMLType etc. to HTMLFormat
--- a/helpers/url.go
+++ b/helpers/url.go
@@ -317,7 +317,6 @@
// URLizeAndPrep applies misc sanitation to the given URL to get it in line
// with the Hugo standard.
-// TODO(bep) output check usage
func (p *PathSpec) URLizeAndPrep(in string) string {
return p.URLPrep(p.URLize(in))
}
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -212,7 +212,7 @@
}
func (p *Page) RSSLink() template.URL {
- f, found := p.outputFormats.GetByName(output.RSSType.Name)
+ f, found := p.outputFormats.GetByName(output.RSSFormat.Name)
if !found {
return ""
}
--- a/hugolib/page_paths_test.go
+++ b/hugolib/page_paths_test.go
@@ -37,24 +37,24 @@
d targetPathDescriptor
expected string
}{
- {"JSON home", targetPathDescriptor{Kind: KindHome, Type: output.JSONType}, "/index.json"},
- {"AMP home", targetPathDescriptor{Kind: KindHome, Type: output.AMPType}, "/amp/index.html"},
- {"HTML home", targetPathDescriptor{Kind: KindHome, BaseName: "_index", Type: output.HTMLType}, "/index.html"},
+ {"JSON home", targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "/index.json"},
+ {"AMP home", targetPathDescriptor{Kind: KindHome, Type: output.AMPFormat}, "/amp/index.html"},
+ {"HTML home", targetPathDescriptor{Kind: KindHome, BaseName: "_index", Type: output.HTMLFormat}, "/index.html"},
{"HTML section list", targetPathDescriptor{
Kind: KindSection,
Sections: []string{"sect1"},
BaseName: "_index",
- Type: output.HTMLType}, "/sect1/index.html"},
+ Type: output.HTMLFormat}, "/sect1/index.html"},
{"HTML taxonomy list", targetPathDescriptor{
Kind: KindTaxonomy,
Sections: []string{"tags", "hugo"},
BaseName: "_index",
- Type: output.HTMLType}, "/tags/hugo/index.html"},
+ Type: output.HTMLFormat}, "/tags/hugo/index.html"},
{"HTML taxonomy term", targetPathDescriptor{
Kind: KindTaxonomy,
Sections: []string{"tags"},
BaseName: "_index",
- Type: output.HTMLType}, "/tags/index.html"},
+ Type: output.HTMLFormat}, "/tags/index.html"},
{
"HTML page", targetPathDescriptor{
Kind: KindPage,
@@ -61,24 +61,24 @@
Dir: "/a/b",
BaseName: "mypage",
Sections: []string{"a"},
- Type: output.HTMLType}, "/a/b/mypage/index.html"},
+ Type: output.HTMLFormat}, "/a/b/mypage/index.html"},
{
"HTML page with special chars", targetPathDescriptor{
Kind: KindPage,
Dir: "/a/b",
BaseName: "My Page!",
- Type: output.HTMLType}, "/a/b/My-Page/index.html"},
- {"RSS home", targetPathDescriptor{Kind: kindRSS, Type: output.RSSType}, "/index.xml"},
+ Type: output.HTMLFormat}, "/a/b/My-Page/index.html"},
+ {"RSS home", targetPathDescriptor{Kind: kindRSS, Type: output.RSSFormat}, "/index.xml"},
{"RSS section list", targetPathDescriptor{
Kind: kindRSS,
Sections: []string{"sect1"},
- Type: output.RSSType}, "/sect1/index.xml"},
+ Type: output.RSSFormat}, "/sect1/index.xml"},
{
"AMP page", targetPathDescriptor{
Kind: KindPage,
Dir: "/a/b/c",
BaseName: "myamp",
- Type: output.AMPType}, "/amp/a/b/c/myamp/index.html"},
+ Type: output.AMPFormat}, "/amp/a/b/c/myamp/index.html"},
{
"AMP page with URL with suffix", targetPathDescriptor{
Kind: KindPage,
@@ -85,7 +85,7 @@
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other/url.xhtml",
- Type: output.HTMLType}, "/some/other/url.xhtml"},
+ Type: output.HTMLFormat}, "/some/other/url.xhtml"},
{
"JSON page with URL without suffix", targetPathDescriptor{
Kind: KindPage,
@@ -92,7 +92,7 @@
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other/path/",
- Type: output.JSONType}, "/some/other/path/index.json"},
+ Type: output.JSONFormat}, "/some/other/path/index.json"},
{
"JSON page with URL without suffix and no trailing slash", targetPathDescriptor{
Kind: KindPage,
@@ -99,7 +99,7 @@
Dir: "/sect/",
BaseName: "mypage",
URL: "/some/other/path",
- Type: output.JSONType}, "/some/other/path/index.json"},
+ Type: output.JSONFormat}, "/some/other/path/index.json"},
{
"HTML page with expanded permalink", targetPathDescriptor{
Kind: KindPage,
@@ -106,12 +106,12 @@
Dir: "/a/b",
BaseName: "mypage",
ExpandedPermalink: "/2017/10/my-title",
- Type: output.HTMLType}, "/2017/10/my-title/index.html"},
+ Type: output.HTMLFormat}, "/2017/10/my-title/index.html"},
{
"Paginated HTML home", targetPathDescriptor{
Kind: KindHome,
BaseName: "_index",
- Type: output.HTMLType,
+ Type: output.HTMLFormat,
Addends: "page/3"}, "/page/3/index.html"},
{
"Paginated Taxonomy list", targetPathDescriptor{
@@ -118,7 +118,7 @@
Kind: KindTaxonomy,
BaseName: "_index",
Sections: []string{"tags", "hugo"},
- Type: output.HTMLType,
+ Type: output.HTMLFormat,
Addends: "page/3"}, "/tags/hugo/page/3/index.html"},
{
"Regular page with addend", targetPathDescriptor{
@@ -126,7 +126,7 @@
Dir: "/a/b",
BaseName: "mypage",
Addends: "c/d/e",
- Type: output.HTMLType}, "/a/b/mypage/c/d/e/index.html"},
+ Type: output.HTMLFormat}, "/a/b/mypage/c/d/e/index.html"},
}
for i, test := range tests {
--- a/hugolib/pagination_test.go
+++ b/hugolib/pagination_test.go
@@ -218,12 +218,12 @@
expected string
}{
{"HTML home page 32",
- targetPathDescriptor{Kind: KindHome, Type: output.HTMLType}, "http://example.com/", 32, "/zoo/32/"},
+ targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/", 32, "/zoo/32/"},
{"JSON home page 42",
- targetPathDescriptor{Kind: KindHome, Type: output.JSONType}, "http://example.com/", 42, "/zoo/42/"},
+ targetPathDescriptor{Kind: KindHome, Type: output.JSONFormat}, "http://example.com/", 42, "/zoo/42/"},
// Issue #1252
{"BaseURL with sub path",
- targetPathDescriptor{Kind: KindHome, Type: output.HTMLType}, "http://example.com/sub/", 999, "/sub/zoo/999/"},
+ targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat}, "http://example.com/sub/", 999, "/sub/zoo/999/"},
}
for _, test := range tests {
@@ -282,8 +282,8 @@
require.NoError(t, err)
pages := createTestPages(s, 12)
- n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
- n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
+ n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
n1.Data["Pages"] = pages
var paginator1 *Pager
@@ -309,7 +309,7 @@
require.Equal(t, paginator1, samePaginator)
pp, _ := s.NewPage("test")
- p, _ := newPageOutput(pp, false, output.HTMLType)
+ p, _ := newPageOutput(pp, false, output.HTMLFormat)
_, err = p.Paginator()
require.NotNil(t, err)
@@ -318,7 +318,7 @@
func TestPaginatorWithNegativePaginate(t *testing.T) {
t.Parallel()
s := newTestSite(t, "paginate", -1)
- n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err := n1.Paginator()
require.Error(t, err)
}
@@ -381,8 +381,8 @@
}
pages := createTestPages(s, 6)
- n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
- n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
+ n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
var paginator1, paginator2 *Pager
@@ -407,7 +407,7 @@
require.Equal(t, paginator2, paginator1.Next())
pp, err := s.NewPage("test")
- p, _ := newPageOutput(pp, false, output.HTMLType)
+ p, _ := newPageOutput(pp, false, output.HTMLFormat)
_, err = p.Paginate(pages)
require.NotNil(t, err)
@@ -416,7 +416,7 @@
func TestInvalidOptions(t *testing.T) {
t.Parallel()
s := newTestSite(t)
- n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err := n1.Paginate(createTestPages(s, 1), 1, 2)
require.NotNil(t, err)
@@ -434,7 +434,7 @@
s, err := NewSiteForCfg(deps.DepsCfg{Cfg: cfg, Fs: fs})
require.NoError(t, err)
- n, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err = n.Paginate(createTestPages(s, 2))
require.NotNil(t, err)
@@ -445,7 +445,7 @@
s := newTestSite(t)
groups, _ := createTestPages(s, 31).GroupBy("Weight", "desc")
- pd := targetPathDescriptor{Kind: KindHome, Type: output.HTMLType, PathSpec: s.PathSpec, Addends: "t"}
+ pd := targetPathDescriptor{Kind: KindHome, Type: output.HTMLFormat, PathSpec: s.PathSpec, Addends: "t"}
for i, seq := range []interface{}{createTestPages(s, 11), groups, WeightedPages{}, PageGroup{}, &Pages{}} {
v, err := paginatePages(pd, seq, 11)
@@ -461,8 +461,8 @@
func TestPaginatorFollowedByPaginateShouldFail(t *testing.T) {
t.Parallel()
s := newTestSite(t, "paginate", 10)
- n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
- n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
+ n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
_, err := n1.Paginator()
require.Nil(t, err)
@@ -478,8 +478,8 @@
t.Parallel()
s := newTestSite(t, "paginate", 10)
- n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
- n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLType)
+ n1, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
+ n2, _ := newPageOutput(s.newHomePage(), false, output.HTMLFormat)
p1 := createTestPages(s, 2)
p2 := createTestPages(s, 10)
--- a/hugolib/site_output.go
+++ b/hugolib/site_output.go
@@ -33,7 +33,6 @@
outputs := cfg.GetStringMap("outputs")
if outputs == nil || len(outputs) == 0 {
- // TODO(bep) outputs log a warning?
return outFormats, nil
}
@@ -56,7 +55,7 @@
// Make sure every kind has at least one output format
for _, kind := range allKinds {
if _, found := outFormats[kind]; !found {
- outFormats[kind] = output.Formats{output.HTMLType}
+ outFormats[kind] = output.Formats{output.HTMLFormat}
}
}
@@ -69,7 +68,7 @@
for _, kind := range allKinds {
var formats output.Formats
// All have HTML
- formats = append(formats, output.HTMLType)
+ formats = append(formats, output.HTMLFormat)
// All but page have RSS
if kind != KindPage {
@@ -81,7 +80,7 @@
// RSS has now a well defined media type, so strip any suffix provided
rssBase = strings.TrimSuffix(rssBase, path.Ext(rssBase))
- rssType := output.RSSType
+ rssType := output.RSSFormat
rssType.BaseName = rssBase
formats = append(formats, rssType)
--- a/hugolib/site_output_test.go
+++ b/hugolib/site_output_test.go
@@ -38,8 +38,8 @@
kind string
want output.Formats
}{
- {"RSS not for regular pages", KindPage, output.Formats{output.HTMLType}},
- {"Home Sweet Home", KindHome, output.Formats{output.HTMLType, output.RSSType}},
+ {"RSS not for regular pages", KindPage, output.Formats{output.HTMLFormat}},
+ {"Home Sweet Home", KindHome, output.Formats{output.HTMLFormat, output.RSSFormat}},
}
for _, tt := range tests {
@@ -59,7 +59,6 @@
}
}
-// TODO(bep) output add test for site outputs config
func doTestSiteWithPageOutputs(t *testing.T, outputs []string) {
t.Parallel()
@@ -147,7 +146,6 @@
require.Equal(t, "http://example.com/blog/index.json", json.Permalink())
if helpers.InStringArray(outputs, "cal") {
- // TODO(bep) output have do some protocil handling for the default too if set.
cal := of.Get("calendar")
require.NotNil(t, cal)
require.Equal(t, "/blog/index.ics", cal.RelPermalink())
--- a/output/layout.go
+++ b/output/layout.go
@@ -102,7 +102,7 @@
layout = layoutOverride
}
- isRSS := f.Name == RSSType.Name
+ isRSS := f.Name == RSSFormat.Name
if d.Kind == "page" {
if isRSS {
--- a/output/layout_base.go
+++ b/output/layout_base.go
@@ -34,7 +34,6 @@
MasterFilename string
}
-// TODO(bep) output this is refactoring in progress.
type TemplateLookupDescriptor struct {
// The full path to the site or theme root.
WorkingDir string
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -56,13 +56,13 @@
{"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 @@
l := NewLayoutHandler(false)
for i := 0; i < b.N; i++ {
- layouts := l.For(descriptor, "", HTMLType)
+ layouts := l.For(descriptor, "", HTMLFormat)
require.NotEmpty(b, layouts)
}
}
--- a/output/outputFormat.go
+++ b/output/outputFormat.go
@@ -22,9 +22,9 @@
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 @@
IsHTML: true,
}
- CalendarType = Format{
+ CalendarFormat = Format{
Name: "Calendar",
MediaType: media.CalendarType,
IsPlainText: true,
@@ -42,7 +42,7 @@
Rel: "alternate",
}
- CSSType = Format{
+ CSSFormat = Format{
Name: "CSS",
MediaType: media.CSSType,
BaseName: "styles",
@@ -49,7 +49,7 @@
Rel: "stylesheet",
}
- HTMLType = Format{
+ HTMLFormat = Format{
Name: "HTML",
MediaType: media.HTMLType,
BaseName: "index",
@@ -57,7 +57,7 @@
IsHTML: true,
}
- JSONType = Format{
+ JSONFormat = Format{
Name: "JSON",
MediaType: media.JSONType,
BaseName: "index",
@@ -65,7 +65,7 @@
Rel: "alternate",
}
- RSSType = Format{
+ RSSFormat = Format{
Name: "RSS",
MediaType: media.RSSType,
BaseName: "index",
@@ -75,12 +75,12 @@
)
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
--- a/output/outputFormat_test.go
+++ b/output/outputFormat_test.go
@@ -21,41 +21,41 @@
)
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, "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", 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, "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", 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, "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", 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, "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)
}