shithub: hugo

Download patch

ref: f091fc23edfa912ae3e6e2d3a80d65432db6e35e
parent: 03122e51fa41d0a289054eedc2d6fffd7f9f2e0b
author: Bjørn Erik Pedersen <[email protected]>
date: Tue Mar 7 09:20:39 EST 2017

hugolib: Add basic setup for output def per Kind

--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -548,12 +548,7 @@
 					p.Content = helpers.BytesToHTML(workContentCopy)
 				}
 
-				// TODO(bep) output this is temporary
-				if p.IsNode() {
-					p.outputTypes = outputTypesWithRSS
-				} else {
-					p.outputTypes = outputTypesHTML
-				}
+				p.outputTypes = defaultOutputDefinitions.ForKind(p.Kind)
 
 				//analyze for raw stats
 				p.analyzePage()
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1642,6 +1642,10 @@
 	return KindSection
 }
 
+func (s *Site) layouts(p *PageOutput) []string {
+	return s.layoutHandler.For(p.layoutIdentifier, "", p.outputType)
+}
+
 func (s *Site) preparePages() error {
 	var errors []error
 
--- /dev/null
+++ b/hugolib/site_output.go
@@ -1,0 +1,50 @@
+// Copyright 2017-present The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package hugolib
+
+import (
+	"strings"
+
+	"github.com/spf13/hugo/output"
+)
+
+var defaultOutputDefinitions = siteOutputDefinitions{
+	// All have HTML
+	siteOutputDefinition{ExcludedKinds: "", Outputs: []output.Type{output.HTMLType}},
+	// Some have RSS
+	siteOutputDefinition{ExcludedKinds: "page", Outputs: []output.Type{output.RSSType}},
+}
+
+type siteOutputDefinitions []siteOutputDefinition
+
+type siteOutputDefinition struct {
+	// What Kinds of pages are excluded in this definition.
+	// A blank strings means NONE.
+	// Comma separated list (for now).
+	ExcludedKinds string
+
+	Outputs []output.Type
+}
+
+func (defs siteOutputDefinitions) ForKind(kind string) []output.Type {
+	var result []output.Type
+
+	for _, def := range defs {
+		if def.ExcludedKinds == "" || !strings.Contains(def.ExcludedKinds, kind) {
+			result = append(result, def.Outputs...)
+		}
+	}
+
+	return result
+}
--- /dev/null
+++ b/hugolib/site_output_test.go
@@ -1,0 +1,42 @@
+// Copyright 2017-present The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package hugolib
+
+import (
+	"reflect"
+	"testing"
+
+	"github.com/spf13/hugo/output"
+)
+
+func TestDefaultOutputDefinitions(t *testing.T) {
+	defs := defaultOutputDefinitions
+
+	tests := []struct {
+		name string
+		kind string
+		want []output.Type
+	}{
+		{"RSS not for regular pages", KindPage, []output.Type{output.HTMLType}},
+		{"Home Sweet Home", KindHome, []output.Type{output.HTMLType, output.RSSType}},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := defs.ForKind(tt.kind); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("siteOutputDefinitions.ForKind(%v) = %v, want %v", tt.kind, got, tt.want)
+			}
+		})
+	}
+}
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -73,7 +73,7 @@
 				// TODO(bep) output
 				layouts = pageOutput.layoutsCalculated
 			} else {
-				layouts = s.layoutHandler.For(pageOutput.layoutIdentifier, "", pageOutput.outputType)
+				layouts = s.layouts(pageOutput)
 			}
 
 			switch pageOutput.outputType {
@@ -87,7 +87,6 @@
 					results <- err
 				}
 
-				// Taxonomy terms have no page set to paginate, so skip that for now.
 				if pageOutput.IsNode() {
 					if err := s.renderPaginator(pageOutput); err != nil {
 						results <- err
--- a/output/outputType.go
+++ b/output/outputType.go
@@ -21,11 +21,13 @@
 	HTMLType = Type{
 		Name:      "HTML",
 		MediaType: media.HTMLType,
+		BaseName:  "index",
 	}
 
 	RSSType = Type{
 		Name:      "RSS",
 		MediaType: media.RSSType,
+		BaseName:  "index",
 	}
 )
 
@@ -42,7 +44,16 @@
 	// Must be set to a value when there are two or more conflicting mediatype for the same resource.
 	Path string
 
+	// The base output file name used when not using "ugly URLs", defaults to "index".
+	BaseName string
+
+	// The protocol to use, i.e. "webcal://". Defaults to the protocol of the baseURL.
+	Protocol string
+
 	// IsPlainText decides whether to use text/template or html/template
 	// as template parser.
 	IsPlainText bool
+
+	// Enable to ignore the global uglyURLs setting.
+	NoUgly bool
 }