mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	hugolib: Add basic setup for output def per Kind
This commit is contained in:
		@@ -548,12 +548,7 @@ func (s *Site) preparePagesForRender(cfg *BuildCfg) {
 | 
				
			|||||||
					p.Content = helpers.BytesToHTML(workContentCopy)
 | 
										p.Content = helpers.BytesToHTML(workContentCopy)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// TODO(bep) output this is temporary
 | 
									p.outputTypes = defaultOutputDefinitions.ForKind(p.Kind)
 | 
				
			||||||
				if p.IsNode() {
 | 
					 | 
				
			||||||
					p.outputTypes = outputTypesWithRSS
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					p.outputTypes = outputTypesHTML
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//analyze for raw stats
 | 
									//analyze for raw stats
 | 
				
			||||||
				p.analyzePage()
 | 
									p.analyzePage()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1642,6 +1642,10 @@ func (s *Site) kindFromSections(sections []string) string {
 | 
				
			|||||||
	return KindSection
 | 
						return KindSection
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *Site) layouts(p *PageOutput) []string {
 | 
				
			||||||
 | 
						return s.layoutHandler.For(p.layoutIdentifier, "", p.outputType)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *Site) preparePages() error {
 | 
					func (s *Site) preparePages() error {
 | 
				
			||||||
	var errors []error
 | 
						var errors []error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										50
									
								
								hugolib/site_output.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								hugolib/site_output.go
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										42
									
								
								hugolib/site_output_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								hugolib/site_output_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -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)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -73,7 +73,7 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
 | 
				
			|||||||
				// TODO(bep) output
 | 
									// TODO(bep) output
 | 
				
			||||||
				layouts = pageOutput.layoutsCalculated
 | 
									layouts = pageOutput.layoutsCalculated
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				layouts = s.layoutHandler.For(pageOutput.layoutIdentifier, "", pageOutput.outputType)
 | 
									layouts = s.layouts(pageOutput)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			switch pageOutput.outputType {
 | 
								switch pageOutput.outputType {
 | 
				
			||||||
@@ -87,7 +87,6 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
 | 
				
			|||||||
					results <- err
 | 
										results <- err
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Taxonomy terms have no page set to paginate, so skip that for now.
 | 
					 | 
				
			||||||
				if pageOutput.IsNode() {
 | 
									if pageOutput.IsNode() {
 | 
				
			||||||
					if err := s.renderPaginator(pageOutput); err != nil {
 | 
										if err := s.renderPaginator(pageOutput); err != nil {
 | 
				
			||||||
						results <- err
 | 
											results <- err
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,11 +21,13 @@ var (
 | 
				
			|||||||
	HTMLType = Type{
 | 
						HTMLType = Type{
 | 
				
			||||||
		Name:      "HTML",
 | 
							Name:      "HTML",
 | 
				
			||||||
		MediaType: media.HTMLType,
 | 
							MediaType: media.HTMLType,
 | 
				
			||||||
 | 
							BaseName:  "index",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	RSSType = Type{
 | 
						RSSType = Type{
 | 
				
			||||||
		Name:      "RSS",
 | 
							Name:      "RSS",
 | 
				
			||||||
		MediaType: media.RSSType,
 | 
							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.
 | 
						// Must be set to a value when there are two or more conflicting mediatype for the same resource.
 | 
				
			||||||
	Path string
 | 
						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
 | 
						// IsPlainText decides whether to use text/template or html/template
 | 
				
			||||||
	// as template parser.
 | 
						// as template parser.
 | 
				
			||||||
	IsPlainText bool
 | 
						IsPlainText bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Enable to ignore the global uglyURLs setting.
 | 
				
			||||||
 | 
						NoUgly bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user