hugolib: Add basic setup for output def per Kind
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 7 Mar 2017 13:20:39 +0000 (14:20 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 27 Mar 2017 13:43:56 +0000 (15:43 +0200)
hugolib/hugo_sites.go
hugolib/site.go
hugolib/site_output.go [new file with mode: 0644]
hugolib/site_output_test.go [new file with mode: 0644]
hugolib/site_render.go
output/outputType.go

index 3cd44e46d80e014d5d62f01a102cccf9f126a95d..0ffc286d67f8673678c528620683038f9b32557e 100644 (file)
@@ -548,12 +548,7 @@ func (s *Site) preparePagesForRender(cfg *BuildCfg) {
                                        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()
index b3825a9bb7d804c318b33cb186a09dee41f186da..2a9db1abe664bef7a400aacc2ed298a471ac096c 100644 (file)
@@ -1642,6 +1642,10 @@ func (s *Site) kindFromSections(sections []string) string {
        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
 
diff --git a/hugolib/site_output.go b/hugolib/site_output.go
new file mode 100644 (file)
index 0000000..7f6fa2d
--- /dev/null
@@ -0,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
+}
diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go
new file mode 100644 (file)
index 0000000..e67818f
--- /dev/null
@@ -0,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)
+                       }
+               })
+       }
+}
index 54cba59bcf93309bd7fca3afcd09cf010d839386..466e01ffb7c55de7af7fe7b5c8c3d3647baa759f 100644 (file)
@@ -73,7 +73,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
                                // 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 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
                                        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
index 222494b090ae28e477ba7b4a57bf9e7025031155..cf5fff76e46e0de21c60773875db5832127bb397 100644 (file)
@@ -21,11 +21,13 @@ var (
        HTMLType = Type{
                Name:      "HTML",
                MediaType: media.HTMLType,
+               BaseName:  "index",
        }
 
        RSSType = Type{
                Name:      "RSS",
                MediaType: media.RSSType,
+               BaseName:  "index",
        }
 )
 
@@ -42,7 +44,16 @@ type Type struct {
        // 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
 }