aboutsummaryrefslogtreecommitdiffhomepage
path: root/output
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-12-02 13:23:25 +0100
committerBjørn Erik Pedersen <[email protected]>2020-12-03 13:12:58 +0100
commitd90e37e0c6e812f9913bf256c9c81aa05b7a08aa (patch)
tree7b1b14464eefec1188ca2eed53c64e4823453cc9 /output
parent32471b57bde51c55a15dbf1db75d6e5f7232c347 (diff)
downloadhugo-d90e37e0c6e812f9913bf256c9c81aa05b7a08aa.tar.gz
hugo-d90e37e0c6e812f9913bf256c9c81aa05b7a08aa.zip
all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
Diffstat (limited to 'output')
-rw-r--r--output/docshelper.go5
-rw-r--r--output/layout_test.go144
-rw-r--r--output/outputFormat.go4
-rw-r--r--output/outputFormat_test.go39
4 files changed, 134 insertions, 58 deletions
diff --git a/output/docshelper.go b/output/docshelper.go
index 450c323d1..42b871ab5 100644
--- a/output/docshelper.go
+++ b/output/docshelper.go
@@ -23,7 +23,6 @@ func init() {
}
func createLayoutExamples() interface{} {
-
type Example struct {
Example string
Kind string
@@ -78,11 +77,11 @@ func createLayoutExamples() interface{} {
Kind: example.d.Kind,
OutputFormat: example.f.Name,
Suffix: example.f.MediaType.Suffix(),
- Layouts: makeLayoutsPresentable(layouts)})
+ Layouts: makeLayoutsPresentable(layouts),
+ })
}
return basicExamples
-
}
func makeLayoutsPresentable(l []string) []string {
diff --git a/output/layout_test.go b/output/layout_test.go
index 853b2475a..f98eea960 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -65,7 +65,9 @@ func TestLayout(t *testing.T) {
expect []string
}{
{
- "Home", LayoutDescriptor{Kind: "home"}, "", ampType,
+ "Home",
+ LayoutDescriptor{Kind: "home"},
+ "", ampType,
[]string{
"index.amp.html",
"home.amp.html",
@@ -82,7 +84,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home baseof", LayoutDescriptor{Kind: "home", Baseof: true}, "", ampType,
+ "Home baseof",
+ LayoutDescriptor{Kind: "home", Baseof: true},
+ "", ampType,
[]string{
"index-baseof.amp.html",
"home-baseof.amp.html",
@@ -103,7 +107,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home, HTML", LayoutDescriptor{Kind: "home"}, "", htmlFormat,
+ "Home, HTML",
+ LayoutDescriptor{Kind: "home"},
+ "", htmlFormat,
// We will eventually get to index.html. This looks stuttery, but makes the lookup logic easy to understand.
[]string{
"index.html.html",
@@ -121,7 +127,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home, HTML, baseof", LayoutDescriptor{Kind: "home", Baseof: true}, "", htmlFormat,
+ "Home, HTML, baseof",
+ LayoutDescriptor{Kind: "home", Baseof: true},
+ "", htmlFormat,
[]string{
"index-baseof.html.html",
"home-baseof.html.html",
@@ -142,7 +150,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home, french language", LayoutDescriptor{Kind: "home", Lang: "fr"}, "", ampType,
+ "Home, french language",
+ LayoutDescriptor{Kind: "home", Lang: "fr"},
+ "", ampType,
[]string{
"index.fr.amp.html",
"home.fr.amp.html",
@@ -171,7 +181,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home, no ext or delim", LayoutDescriptor{Kind: "home"}, "", noExtDelimFormat,
+ "Home, no ext or delim",
+ LayoutDescriptor{Kind: "home"},
+ "", noExtDelimFormat,
[]string{
"index.nem",
"home.nem",
@@ -182,7 +194,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home, no ext", LayoutDescriptor{Kind: "home"}, "", noExt,
+ "Home, no ext",
+ LayoutDescriptor{Kind: "home"},
+ "", noExt,
[]string{
"index.nex",
"home.nex",
@@ -193,11 +207,15 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page, no ext or delim", LayoutDescriptor{Kind: "page"}, "", noExtDelimFormat,
+ "Page, no ext or delim",
+ LayoutDescriptor{Kind: "page"},
+ "", noExtDelimFormat,
[]string{"_default/single.nem"},
},
{
- "Section", LayoutDescriptor{Kind: "section", Section: "sect1"}, "", ampType,
+ "Section",
+ LayoutDescriptor{Kind: "section", Section: "sect1"},
+ "", ampType,
[]string{
"sect1/sect1.amp.html",
"sect1/section.amp.html",
@@ -220,7 +238,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Section, baseof", LayoutDescriptor{Kind: "section", Section: "sect1", Baseof: true}, "", ampType,
+ "Section, baseof",
+ LayoutDescriptor{Kind: "section", Section: "sect1", Baseof: true},
+ "", ampType,
[]string{
"sect1/sect1-baseof.amp.html",
"sect1/section-baseof.amp.html",
@@ -249,7 +269,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Section, baseof, French, AMP", LayoutDescriptor{Kind: "section", Section: "sect1", Lang: "fr", Baseof: true}, "", ampType,
+ "Section, baseof, French, AMP",
+ LayoutDescriptor{Kind: "section", Section: "sect1", Lang: "fr", Baseof: true},
+ "", ampType,
[]string{
"sect1/sect1-baseof.fr.amp.html",
"sect1/section-baseof.fr.amp.html",
@@ -302,7 +324,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Section with layout", LayoutDescriptor{Kind: "section", Section: "sect1", Layout: "mylayout"}, "", ampType,
+ "Section with layout",
+ LayoutDescriptor{Kind: "section", Section: "sect1", Layout: "mylayout"},
+ "", ampType,
[]string{
"sect1/mylayout.amp.html",
"sect1/sect1.amp.html",
@@ -331,7 +355,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Term, French, AMP", LayoutDescriptor{Kind: "term", Section: "tags", Lang: "fr"}, "", ampType,
+ "Term, French, AMP",
+ LayoutDescriptor{Kind: "term", Section: "tags", Lang: "fr"},
+ "", ampType,
[]string{
"term/term.fr.amp.html",
"term/tags.fr.amp.html",
@@ -400,7 +426,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Term, baseof, French, AMP", LayoutDescriptor{Kind: "term", Section: "tags", Lang: "fr", Baseof: true}, "", ampType,
+ "Term, baseof, French, AMP",
+ LayoutDescriptor{Kind: "term", Section: "tags", Lang: "fr", Baseof: true},
+ "", ampType,
[]string{
"term/term-baseof.fr.amp.html",
"term/tags-baseof.fr.amp.html",
@@ -485,7 +513,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Term", LayoutDescriptor{Kind: "term", Section: "tags"}, "", ampType,
+ "Term",
+ LayoutDescriptor{Kind: "term", Section: "tags"},
+ "", ampType,
[]string{
"term/term.amp.html",
"term/tags.amp.html",
@@ -522,7 +552,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "categories"}, "", ampType,
+ "Taxonomy",
+ LayoutDescriptor{Kind: "taxonomy", Section: "categories"},
+ "", ampType,
[]string{
"categories/categories.terms.amp.html",
"categories/terms.amp.html",
@@ -551,14 +583,18 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page", LayoutDescriptor{Kind: "page"}, "", ampType,
+ "Page",
+ LayoutDescriptor{Kind: "page"},
+ "", ampType,
[]string{
"_default/single.amp.html",
"_default/single.html",
},
},
{
- "Page, baseof", LayoutDescriptor{Kind: "page", Baseof: true}, "", ampType,
+ "Page, baseof",
+ LayoutDescriptor{Kind: "page", Baseof: true},
+ "", ampType,
[]string{
"_default/single-baseof.amp.html",
"_default/baseof.amp.html",
@@ -567,7 +603,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page with layout", LayoutDescriptor{Kind: "page", Layout: "mylayout"}, "", ampType,
+ "Page with layout",
+ LayoutDescriptor{Kind: "page", Layout: "mylayout"},
+ "", ampType,
[]string{
"_default/mylayout.amp.html",
"_default/single.amp.html",
@@ -576,7 +614,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page with layout, baseof", LayoutDescriptor{Kind: "page", Layout: "mylayout", Baseof: true}, "", ampType,
+ "Page with layout, baseof",
+ LayoutDescriptor{Kind: "page", Layout: "mylayout", Baseof: true},
+ "", ampType,
[]string{
"_default/mylayout-baseof.amp.html",
"_default/single-baseof.amp.html",
@@ -587,7 +627,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page with layout and type", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"}, "", ampType,
+ "Page with layout and type",
+ LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype"},
+ "", ampType,
[]string{
"myttype/mylayout.amp.html",
"myttype/single.amp.html",
@@ -600,7 +642,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page baseof with layout and type", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype", Baseof: true}, "", ampType,
+ "Page baseof with layout and type",
+ LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype", Baseof: true},
+ "", ampType,
[]string{
"myttype/mylayout-baseof.amp.html",
"myttype/single-baseof.amp.html",
@@ -617,7 +661,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page baseof with layout and type in French", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype", Lang: "fr", Baseof: true}, "", ampType,
+ "Page baseof with layout and type in French",
+ LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype", Lang: "fr", Baseof: true},
+ "", ampType,
[]string{
"myttype/mylayout-baseof.fr.amp.html",
"myttype/single-baseof.fr.amp.html",
@@ -646,7 +692,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page with layout and type with subtype", LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype/mysubtype"}, "", ampType,
+ "Page with layout and type with subtype",
+ LayoutDescriptor{Kind: "page", Layout: "mylayout", Type: "myttype/mysubtype"},
+ "", ampType,
[]string{
"myttype/mysubtype/mylayout.amp.html",
"myttype/mysubtype/single.amp.html",
@@ -660,7 +708,9 @@ func TestLayout(t *testing.T) {
},
// RSS
{
- "RSS Home", LayoutDescriptor{Kind: "home"}, "", RSSFormat,
+ "RSS Home",
+ LayoutDescriptor{Kind: "home"},
+ "", RSSFormat,
[]string{
"index.rss.xml",
"home.rss.xml",
@@ -680,7 +730,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "RSS Home, baseof", LayoutDescriptor{Kind: "home", Baseof: true}, "", RSSFormat,
+ "RSS Home, baseof",
+ LayoutDescriptor{Kind: "home", Baseof: true},
+ "", RSSFormat,
[]string{
"index-baseof.rss.xml",
"home-baseof.rss.xml",
@@ -701,7 +753,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "RSS Section", LayoutDescriptor{Kind: "section", Section: "sect1"}, "", RSSFormat,
+ "RSS Section",
+ LayoutDescriptor{Kind: "section", Section: "sect1"},
+ "", RSSFormat,
[]string{
"sect1/sect1.rss.xml",
"sect1/section.rss.xml",
@@ -728,7 +782,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "RSS Term", LayoutDescriptor{Kind: "term", Section: "tag"}, "", RSSFormat,
+ "RSS Term",
+ LayoutDescriptor{Kind: "term", Section: "tag"},
+ "", RSSFormat,
[]string{
"term/term.rss.xml",
"term/tag.rss.xml",
@@ -770,7 +826,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "RSS Taxonomy", LayoutDescriptor{Kind: "taxonomy", Section: "tag"}, "", RSSFormat,
+ "RSS Taxonomy",
+ LayoutDescriptor{Kind: "taxonomy", Section: "tag"},
+ "", RSSFormat,
[]string{
"tag/tag.terms.rss.xml",
"tag/terms.rss.xml",
@@ -803,7 +861,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Home plain text", LayoutDescriptor{Kind: "home"}, "", JSONFormat,
+ "Home plain text",
+ LayoutDescriptor{Kind: "home"},
+ "", JSONFormat,
[]string{
"index.json.json",
"home.json.json",
@@ -820,14 +880,18 @@ func TestLayout(t *testing.T) {
},
},
{
- "Page plain text", LayoutDescriptor{Kind: "page"}, "", JSONFormat,
+ "Page plain text",
+ LayoutDescriptor{Kind: "page"},
+ "", JSONFormat,
[]string{
"_default/single.json.json",
"_default/single.json",
},
},
{
- "Reserved section, shortcodes", LayoutDescriptor{Kind: "section", Section: "shortcodes", Type: "shortcodes"}, "", ampType,
+ "Reserved section, shortcodes",
+ LayoutDescriptor{Kind: "section", Section: "shortcodes", Type: "shortcodes"},
+ "", ampType,
[]string{
"section/shortcodes.amp.html",
"section/section.amp.html",
@@ -844,7 +908,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Reserved section, partials", LayoutDescriptor{Kind: "section", Section: "partials", Type: "partials"}, "", ampType,
+ "Reserved section, partials",
+ LayoutDescriptor{Kind: "section", Section: "partials", Type: "partials"},
+ "", ampType,
[]string{
"section/partials.amp.html",
"section/section.amp.html",
@@ -862,14 +928,18 @@ func TestLayout(t *testing.T) {
},
// This is currently always HTML only
{
- "404, HTML", LayoutDescriptor{Kind: "404"}, "", htmlFormat,
+ "404, HTML",
+ LayoutDescriptor{Kind: "404"},
+ "", htmlFormat,
[]string{
"404.html.html",
"404.html",
},
},
{
- "404, HTML baseof", LayoutDescriptor{Kind: "404", Baseof: true}, "", htmlFormat,
+ "404, HTML baseof",
+ LayoutDescriptor{Kind: "404", Baseof: true},
+ "", htmlFormat,
[]string{
"404-baseof.html.html",
"baseof.html.html",
@@ -882,7 +952,9 @@ func TestLayout(t *testing.T) {
},
},
{
- "Content hook", LayoutDescriptor{Kind: "render-link", RenderingHook: true, Layout: "mylayout", Section: "blog"}, "", ampType,
+ "Content hook",
+ LayoutDescriptor{Kind: "render-link", RenderingHook: true, Layout: "mylayout", Section: "blog"},
+ "", ampType,
[]string{
"blog/_markup/render-link.amp.html",
"blog/_markup/render-link.html",
diff --git a/output/outputFormat.go b/output/outputFormat.go
index c9c108ac5..ee5881e2a 100644
--- a/output/outputFormat.go
+++ b/output/outputFormat.go
@@ -16,11 +16,10 @@ package output
import (
"encoding/json"
"fmt"
+ "reflect"
"sort"
"strings"
- "reflect"
-
"github.com/mitchellh/mapstructure"
"github.com/gohugoio/hugo/media"
@@ -200,7 +199,6 @@ func (formats Formats) Less(i, j int) bool {
}
return fi.Weight > 0 && fi.Weight < fj.Weight
-
}
// GetBySuffix gets a output format given as suffix, e.g. "html".
diff --git a/output/outputFormat_test.go b/output/outputFormat_test.go
index 2b10c5a9e..d91f1e410 100644
--- a/output/outputFormat_test.go
+++ b/output/outputFormat_test.go
@@ -77,7 +77,6 @@ func TestDefaultTypes(t *testing.T) {
c.Assert(RSSFormat.IsPlainText, qt.Equals, false)
c.Assert(RSSFormat.NoUgly, qt.Equals, true)
c.Assert(CalendarFormat.IsHTML, qt.Equals, false)
-
}
func TestGetFormatByName(t *testing.T) {
@@ -144,7 +143,6 @@ func TestGetFormatByFilename(t *testing.T) {
c.Assert(f, eq, noExt)
_, found = formats.FromFilename("my.css")
c.Assert(found, qt.Equals, false)
-
}
func TestDecodeFormats(t *testing.T) {
@@ -152,7 +150,7 @@ func TestDecodeFormats(t *testing.T) {
mediaTypes := media.Types{media.JSONType, media.XMLType}
- var tests = []struct {
+ tests := []struct {
name string
maps []map[string]interface{}
shouldError bool
@@ -164,7 +162,10 @@ func TestDecodeFormats(t *testing.T) {
{
"JsON": map[string]interface{}{
"baseName": "myindex",
- "isPlainText": "false"}}},
+ "isPlainText": "false",
+ },
+ },
+ },
false,
func(t *testing.T, name string, f Formats) {
msg := qt.Commentf(name)
@@ -173,8 +174,8 @@ func TestDecodeFormats(t *testing.T) {
c.Assert(json.BaseName, qt.Equals, "myindex")
c.Assert(json.MediaType, eq, media.JSONType)
c.Assert(json.IsPlainText, qt.Equals, false)
-
- }},
+ },
+ },
{
"Add XML format with string as mediatype",
[]map[string]interface{}{
@@ -182,7 +183,9 @@ func TestDecodeFormats(t *testing.T) {
"MYXMLFORMAT": map[string]interface{}{
"baseName": "myxml",
"mediaType": "application/xml",
- }}},
+ },
+ },
+ },
false,
func(t *testing.T, name string, f Formats) {
c.Assert(len(f), qt.Equals, len(DefaultFormats)+1)
@@ -194,8 +197,8 @@ func TestDecodeFormats(t *testing.T) {
// Verify that we haven't changed the DefaultFormats slice.
json, _ := f.GetByName("JSON")
c.Assert(json.BaseName, qt.Equals, "index")
-
- }},
+ },
+ },
{
"Add format unknown mediatype",
[]map[string]interface{}{
@@ -203,11 +206,13 @@ func TestDecodeFormats(t *testing.T) {
"MYINVALID": map[string]interface{}{
"baseName": "mymy",
"mediaType": "application/hugo",
- }}},
+ },
+ },
+ },
true,
func(t *testing.T, name string, f Formats) {
-
- }},
+ },
+ },
{
"Add and redefine XML format",
[]map[string]interface{}{
@@ -215,11 +220,13 @@ func TestDecodeFormats(t *testing.T) {
"MYOTHERXMLFORMAT": map[string]interface{}{
"baseName": "myotherxml",
"mediaType": media.XMLType,
- }},
+ },
+ },
{
"MYOTHERXMLFORMAT": map[string]interface{}{
"baseName": "myredefined",
- }},
+ },
+ },
},
false,
func(t *testing.T, name string, f Formats) {
@@ -228,7 +235,8 @@ func TestDecodeFormats(t *testing.T) {
c.Assert(found, qt.Equals, true)
c.Assert(xml.BaseName, qt.Equals, "myredefined")
c.Assert(xml.MediaType, eq, media.XMLType)
- }},
+ },
+ },
}
for _, test := range tests {
@@ -263,5 +271,4 @@ func TestSort(t *testing.T) {
c.Assert(formats[0].Name, qt.Equals, "JSON")
c.Assert(formats[1].Name, qt.Equals, "HTML")
c.Assert(formats[2].Name, qt.Equals, "AMP")
-
}