github.com/neohugo/neohugo@v0.123.8/config/allconfig/configlanguage.go (about)

     1  // Copyright 2024 The Hugo Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package allconfig
    15  
    16  import (
    17  	"time"
    18  
    19  	"github.com/neohugo/neohugo/common/paths"
    20  	"github.com/neohugo/neohugo/common/urls"
    21  	"github.com/neohugo/neohugo/config"
    22  	"github.com/neohugo/neohugo/identity"
    23  	"github.com/neohugo/neohugo/langs"
    24  )
    25  
    26  type ConfigLanguage struct {
    27  	config     *Config
    28  	baseConfig config.BaseConfig
    29  
    30  	m        *Configs
    31  	language *langs.Language
    32  }
    33  
    34  func (c ConfigLanguage) Language() *langs.Language {
    35  	return c.language
    36  }
    37  
    38  func (c ConfigLanguage) Languages() langs.Languages {
    39  	return c.m.Languages
    40  }
    41  
    42  func (c ConfigLanguage) LanguagesDefaultFirst() langs.Languages {
    43  	return c.m.LanguagesDefaultFirst
    44  }
    45  
    46  func (c ConfigLanguage) PathParser() *paths.PathParser {
    47  	return c.m.ContentPathParser
    48  }
    49  
    50  func (c ConfigLanguage) LanguagePrefix() string {
    51  	if c.DefaultContentLanguageInSubdir() && c.DefaultContentLanguage() == c.Language().Lang {
    52  		return c.Language().Lang
    53  	}
    54  
    55  	if !c.IsMultiLingual() || c.DefaultContentLanguage() == c.Language().Lang {
    56  		return ""
    57  	}
    58  	return c.Language().Lang
    59  }
    60  
    61  func (c ConfigLanguage) BaseURL() urls.BaseURL {
    62  	return c.config.C.BaseURL
    63  }
    64  
    65  func (c ConfigLanguage) BaseURLLiveReload() urls.BaseURL {
    66  	return c.config.C.BaseURLLiveReload
    67  }
    68  
    69  func (c ConfigLanguage) Environment() string {
    70  	return c.config.Environment
    71  }
    72  
    73  func (c ConfigLanguage) IsMultihost() bool {
    74  	return c.m.IsMultihost
    75  }
    76  
    77  func (c ConfigLanguage) FastRenderMode() bool {
    78  	return c.config.Internal.FastRenderMode
    79  }
    80  
    81  func (c ConfigLanguage) IsMultiLingual() bool {
    82  	return len(c.m.Languages) > 1
    83  }
    84  
    85  func (c ConfigLanguage) TemplateMetrics() bool {
    86  	return c.config.TemplateMetrics
    87  }
    88  
    89  func (c ConfigLanguage) TemplateMetricsHints() bool {
    90  	return c.config.TemplateMetricsHints
    91  }
    92  
    93  func (c ConfigLanguage) IsLangDisabled(lang string) bool {
    94  	return c.config.C.DisabledLanguages[lang]
    95  }
    96  
    97  func (c ConfigLanguage) IgnoredLogs() map[string]bool {
    98  	return c.config.C.IgnoredLogs
    99  }
   100  
   101  func (c ConfigLanguage) NoBuildLock() bool {
   102  	return c.config.NoBuildLock
   103  }
   104  
   105  func (c ConfigLanguage) NewContentEditor() string {
   106  	return c.config.NewContentEditor
   107  }
   108  
   109  func (c ConfigLanguage) Timeout() time.Duration {
   110  	return c.config.C.Timeout
   111  }
   112  
   113  func (c ConfigLanguage) BaseConfig() config.BaseConfig {
   114  	return c.baseConfig
   115  }
   116  
   117  func (c ConfigLanguage) Dirs() config.CommonDirs {
   118  	return c.config.CommonDirs
   119  }
   120  
   121  func (c ConfigLanguage) DirsBase() config.CommonDirs {
   122  	return c.m.Base.CommonDirs
   123  }
   124  
   125  func (c ConfigLanguage) WorkingDir() string {
   126  	return c.m.Base.WorkingDir
   127  }
   128  
   129  func (c ConfigLanguage) Quiet() bool {
   130  	return c.m.Base.Internal.Quiet
   131  }
   132  
   133  func (c ConfigLanguage) Watching() bool {
   134  	return c.m.Base.Internal.Watch
   135  }
   136  
   137  func (c ConfigLanguage) NewIdentityManager(name string) identity.Manager {
   138  	if !c.Watching() {
   139  		return identity.NopManager
   140  	}
   141  	return identity.NewManager(name)
   142  }
   143  
   144  // GetConfigSection is mostly used in tests. The switch statement isn't complete, but what's in use.
   145  func (c ConfigLanguage) GetConfigSection(s string) any {
   146  	switch s {
   147  	case "security":
   148  		return c.config.Security
   149  	case "build":
   150  		return c.config.Build
   151  	case "frontmatter":
   152  		return c.config.Frontmatter
   153  	case "caches":
   154  		return c.config.Caches
   155  	case "markup":
   156  		return c.config.Markup
   157  	case "mediaTypes":
   158  		return c.config.MediaTypes.Config
   159  	case "outputFormats":
   160  		return c.config.OutputFormats.Config
   161  	case "permalinks":
   162  		return c.config.Permalinks
   163  	case "minify":
   164  		return c.config.Minify
   165  	case "allModules":
   166  		return c.m.Modules
   167  	case "deployment":
   168  		return c.config.Deployment
   169  	default:
   170  		panic("not implemented: " + s)
   171  	}
   172  }
   173  
   174  func (c ConfigLanguage) GetConfig() any {
   175  	return c.config
   176  }
   177  
   178  func (c ConfigLanguage) CanonifyURLs() bool {
   179  	return c.config.CanonifyURLs
   180  }
   181  
   182  func (c ConfigLanguage) IsUglyURLs(section string) bool {
   183  	return c.config.C.IsUglyURLSection(section)
   184  }
   185  
   186  func (c ConfigLanguage) IgnoreFile(s string) bool {
   187  	return c.config.C.IgnoreFile(s)
   188  }
   189  
   190  func (c ConfigLanguage) DisablePathToLower() bool {
   191  	return c.config.DisablePathToLower
   192  }
   193  
   194  func (c ConfigLanguage) RemovePathAccents() bool {
   195  	return c.config.RemovePathAccents
   196  }
   197  
   198  func (c ConfigLanguage) DefaultContentLanguage() string {
   199  	return c.config.DefaultContentLanguage
   200  }
   201  
   202  func (c ConfigLanguage) DefaultContentLanguageInSubdir() bool {
   203  	return c.config.DefaultContentLanguageInSubdir
   204  }
   205  
   206  func (c ConfigLanguage) SummaryLength() int {
   207  	return c.config.SummaryLength
   208  }
   209  
   210  func (c ConfigLanguage) BuildExpired() bool {
   211  	return c.config.BuildExpired
   212  }
   213  
   214  func (c ConfigLanguage) BuildFuture() bool {
   215  	return c.config.BuildFuture
   216  }
   217  
   218  func (c ConfigLanguage) BuildDrafts() bool {
   219  	return c.config.BuildDrafts
   220  }
   221  
   222  func (c ConfigLanguage) Running() bool {
   223  	return c.config.Internal.Running
   224  }
   225  
   226  func (c ConfigLanguage) PrintUnusedTemplates() bool {
   227  	return c.config.PrintUnusedTemplates
   228  }
   229  
   230  func (c ConfigLanguage) EnableMissingTranslationPlaceholders() bool {
   231  	return c.config.EnableMissingTranslationPlaceholders
   232  }
   233  
   234  func (c ConfigLanguage) PrintI18nWarnings() bool {
   235  	return c.config.PrintI18nWarnings
   236  }
   237  
   238  func (c ConfigLanguage) CreateTitle(s string) string {
   239  	return c.config.C.CreateTitle(s)
   240  }
   241  
   242  func (c ConfigLanguage) Paginate() int {
   243  	return c.config.Paginate
   244  }
   245  
   246  func (c ConfigLanguage) PaginatePath() string {
   247  	return c.config.PaginatePath
   248  }
   249  
   250  func (c ConfigLanguage) StaticDirs() []string {
   251  	return c.config.staticDirs()
   252  }
   253  
   254  func (c ConfigLanguage) EnableEmoji() bool {
   255  	return c.config.EnableEmoji
   256  }