mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2019 The Hugo Authors. All rights reserved.
|
||||
// Copyright 2023 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.
|
||||
@@ -26,9 +26,6 @@ import (
|
||||
"github.com/gohugoio/hugo/markup/tableofcontents"
|
||||
"github.com/gohugoio/hugo/tpl"
|
||||
|
||||
"github.com/gohugoio/hugo/modules"
|
||||
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
"github.com/gohugoio/hugo/resources/resource"
|
||||
|
||||
"github.com/gohugoio/hugo/navigation"
|
||||
@@ -58,6 +55,19 @@ func newTestPage() *testPage {
|
||||
func newTestPageWithFile(filename string) *testPage {
|
||||
filename = filepath.FromSlash(filename)
|
||||
file := source.NewTestFile(filename)
|
||||
|
||||
l, err := langs.NewLanguage(
|
||||
"en",
|
||||
"en",
|
||||
"UTC",
|
||||
langs.LanguageConfig{
|
||||
LanguageName: "English",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &testPage{
|
||||
params: make(map[string]any),
|
||||
data: make(map[string]any),
|
||||
@@ -65,30 +75,10 @@ func newTestPageWithFile(filename string) *testPage {
|
||||
currentSection: &testPage{
|
||||
sectionEntries: []string{"a", "b", "c"},
|
||||
},
|
||||
site: testSite{l: langs.NewDefaultLanguage(config.New())},
|
||||
site: testSite{l: l},
|
||||
}
|
||||
}
|
||||
|
||||
func newTestPathSpec() *helpers.PathSpec {
|
||||
return newTestPathSpecFor(config.New())
|
||||
}
|
||||
|
||||
func newTestPathSpecFor(cfg config.Provider) *helpers.PathSpec {
|
||||
config.SetBaseTestDefaults(cfg)
|
||||
langs.LoadLanguageSettings(cfg, nil)
|
||||
mod, err := modules.CreateProjectModule(cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg.Set("allModules", modules.Modules{mod})
|
||||
fs := hugofs.NewMem(cfg)
|
||||
s, err := helpers.NewPathSpec(fs, cfg, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
type testPage struct {
|
||||
kind string
|
||||
description string
|
||||
@@ -128,15 +118,15 @@ func (p *testPage) Err() resource.ResourceError {
|
||||
}
|
||||
|
||||
func (p *testPage) Aliases() []string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) AllTranslations() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) AlternativeOutputFormats() OutputFormats {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Author() Author {
|
||||
@@ -148,19 +138,19 @@ func (p *testPage) Authors() AuthorList {
|
||||
}
|
||||
|
||||
func (p *testPage) BaseFileName() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) BundleType() files.ContentClass {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Content(context.Context) (any, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) ContentBaseName() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) CurrentSection() Page {
|
||||
@@ -171,8 +161,8 @@ func (p *testPage) Data() any {
|
||||
return p.data
|
||||
}
|
||||
|
||||
func (p *testPage) Sitemap() config.Sitemap {
|
||||
return config.Sitemap{}
|
||||
func (p *testPage) Sitemap() config.SitemapConfig {
|
||||
return config.SitemapConfig{}
|
||||
}
|
||||
|
||||
func (p *testPage) Layout() string {
|
||||
@@ -188,11 +178,11 @@ func (p *testPage) Description() string {
|
||||
}
|
||||
|
||||
func (p *testPage) Dir() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Draft() bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Eq(other any) bool {
|
||||
@@ -204,11 +194,11 @@ func (p *testPage) ExpiryDate() time.Time {
|
||||
}
|
||||
|
||||
func (p *testPage) Ext() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Extension() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) File() source.File {
|
||||
@@ -216,15 +206,15 @@ func (p *testPage) File() source.File {
|
||||
}
|
||||
|
||||
func (p *testPage) FileInfo() hugofs.FileMetaInfo {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Filename() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) FirstSection() Page {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) FuzzyWordCount(context.Context) int {
|
||||
@@ -232,19 +222,19 @@ func (p *testPage) FuzzyWordCount(context.Context) int {
|
||||
}
|
||||
|
||||
func (p *testPage) GetPage(ref string) (Page, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) GetPageWithTemplateInfo(info tpl.Info, ref string) (Page, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) GetParam(key string) any {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) GetTerms(taxonomy string) Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) GetRelatedDocsHandler() *RelatedDocsHandler {
|
||||
@@ -260,27 +250,27 @@ func (p *testPage) CodeOwners() []string {
|
||||
}
|
||||
|
||||
func (p *testPage) HasMenuCurrent(menuID string, me *navigation.MenuEntry) bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) HasShortcode(name string) bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Hugo() hugo.Info {
|
||||
panic("not implemented")
|
||||
func (p *testPage) Hugo() hugo.HugoInfo {
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) InSection(other any) (bool, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsAncestor(other any) (bool, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsDescendant(other any) (bool, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsDraft() bool {
|
||||
@@ -288,27 +278,27 @@ func (p *testPage) IsDraft() bool {
|
||||
}
|
||||
|
||||
func (p *testPage) IsHome() bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsMenuCurrent(menuID string, inme *navigation.MenuEntry) bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsNode() bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsPage() bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsSection() bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) IsTranslated() bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Keywords() []string {
|
||||
@@ -324,7 +314,7 @@ func (p *testPage) Lang() string {
|
||||
}
|
||||
|
||||
func (p *testPage) Language() *langs.Language {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) LanguagePrefix() string {
|
||||
@@ -358,11 +348,11 @@ func (p *testPage) LinkTitle() string {
|
||||
}
|
||||
|
||||
func (p *testPage) LogicalName() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) MediaType() media.Type {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Menus() navigation.PageMenus {
|
||||
@@ -370,11 +360,11 @@ func (p *testPage) Menus() navigation.PageMenus {
|
||||
}
|
||||
|
||||
func (p *testPage) Name() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Next() Page {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) NextInSection() Page {
|
||||
@@ -386,19 +376,19 @@ func (p *testPage) NextPage() Page {
|
||||
}
|
||||
|
||||
func (p *testPage) OutputFormats() OutputFormats {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Pages() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RegularPages() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RegularPagesRecursive() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Paginate(seq any, options ...any) (*Pager, error) {
|
||||
@@ -422,11 +412,11 @@ func (p *testPage) Page() Page {
|
||||
}
|
||||
|
||||
func (p *testPage) Parent() Page {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Ancestors() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Path() string {
|
||||
@@ -438,19 +428,19 @@ func (p *testPage) Pathc() string {
|
||||
}
|
||||
|
||||
func (p *testPage) Permalink() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Plain(context.Context) string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) PlainWords(context.Context) []string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Prev() Page {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) PrevInSection() Page {
|
||||
@@ -470,15 +460,15 @@ func (p *testPage) RSSLink() template.URL {
|
||||
}
|
||||
|
||||
func (p *testPage) RawContent() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) ReadingTime(context.Context) int {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Ref(argsm map[string]any) (string, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RefFrom(argsm map[string]any, source any) (string, error) {
|
||||
@@ -486,11 +476,11 @@ func (p *testPage) RefFrom(argsm map[string]any, source any) (string, error) {
|
||||
}
|
||||
|
||||
func (p *testPage) RelPermalink() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RelRef(argsm map[string]any) (string, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RelRefFrom(argsm map[string]any, source any) (string, error) {
|
||||
@@ -498,27 +488,27 @@ func (p *testPage) RelRefFrom(argsm map[string]any, source any) (string, error)
|
||||
}
|
||||
|
||||
func (p *testPage) Render(ctx context.Context, layout ...string) (template.HTML, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RenderString(ctx context.Context, args ...any) (template.HTML, error) {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) ResourceType() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Resources() resource.Resources {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Scratch() *maps.Scratch {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Store() *maps.Scratch {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) RelatedKeywords(cfg related.IndexConfig) ([]related.Keyword, error) {
|
||||
@@ -535,7 +525,7 @@ func (p *testPage) Section() string {
|
||||
}
|
||||
|
||||
func (p *testPage) Sections() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) SectionsEntries() []string {
|
||||
@@ -551,7 +541,7 @@ func (p *testPage) Site() Site {
|
||||
}
|
||||
|
||||
func (p *testPage) Sites() Sites {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Slug() string {
|
||||
@@ -563,11 +553,11 @@ func (p *testPage) String() string {
|
||||
}
|
||||
|
||||
func (p *testPage) Summary(context.Context) template.HTML {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) TableOfContents(context.Context) template.HTML {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Title() string {
|
||||
@@ -575,7 +565,7 @@ func (p *testPage) Title() string {
|
||||
}
|
||||
|
||||
func (p *testPage) TranslationBaseName() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) TranslationKey() string {
|
||||
@@ -583,11 +573,11 @@ func (p *testPage) TranslationKey() string {
|
||||
}
|
||||
|
||||
func (p *testPage) Translations() Pages {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Truncated(context.Context) bool {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Type() string {
|
||||
@@ -599,7 +589,7 @@ func (p *testPage) URL() string {
|
||||
}
|
||||
|
||||
func (p *testPage) UniqueID() string {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) Weight() int {
|
||||
@@ -607,11 +597,11 @@ func (p *testPage) Weight() int {
|
||||
}
|
||||
|
||||
func (p *testPage) WordCount(context.Context) int {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func (p *testPage) GetIdentity() identity.Identity {
|
||||
panic("not implemented")
|
||||
panic("tespage: not implemented")
|
||||
}
|
||||
|
||||
func createTestPages(num int) Pages {
|
||||
|
Reference in New Issue
Block a user