github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/config/allconfig/configlanguage.go (about)

     1  // Copyright 2023 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/gohugoio/hugo/common/urls"
    20  	"github.com/gohugoio/hugo/config"
    21  	"github.com/gohugoio/hugo/langs"
    22  )
    23  
    24  type ConfigLanguage struct {
    25  	config     *Config
    26  	baseConfig config.BaseConfig
    27  
    28  	m        *Configs
    29  	language *langs.Language
    30  }
    31  
    32  func (c ConfigLanguage) Language() *langs.Language {
    33  	return c.language
    34  }
    35  
    36  func (c ConfigLanguage) Languages() langs.Languages {
    37  	return c.m.Languages
    38  }
    39  
    40  func (c ConfigLanguage) LanguagesDefaultFirst() langs.Languages {
    41  	return c.m.LanguagesDefaultFirst
    42  }
    43  
    44  func (c ConfigLanguage) LanguagePrefix() string {
    45  	if c.DefaultContentLanguageInSubdir() && c.DefaultContentLanguage() == c.Language().Lang {
    46  		return c.Language().Lang
    47  	}
    48  	if !c.IsMultiLingual() || c.DefaultContentLanguage() == c.Language().Lang {
    49  		return ""
    50  	}
    51  	return c.Language().Lang
    52  }
    53  
    54  func (c ConfigLanguage) BaseURL() urls.BaseURL {
    55  	return c.config.C.BaseURL
    56  }
    57  
    58  func (c ConfigLanguage) BaseURLLiveReload() urls.BaseURL {
    59  	return c.config.C.BaseURLLiveReload
    60  }
    61  
    62  func (c ConfigLanguage) Environment() string {
    63  	return c.config.Environment
    64  }
    65  
    66  func (c ConfigLanguage) IsMultihost() bool {
    67  	return c.m.IsMultihost
    68  }
    69  
    70  func (c ConfigLanguage) IsMultiLingual() bool {
    71  	return len(c.m.Languages) > 1
    72  }
    73  
    74  func (c ConfigLanguage) TemplateMetrics() bool {
    75  	return c.config.TemplateMetrics
    76  }
    77  
    78  func (c ConfigLanguage) TemplateMetricsHints() bool {
    79  	return c.config.TemplateMetricsHints
    80  }
    81  
    82  func (c ConfigLanguage) IsLangDisabled(lang string) bool {
    83  	return c.config.C.DisabledLanguages[lang]
    84  }
    85  
    86  func (c ConfigLanguage) IgnoredErrors() map[string]bool {
    87  	return c.config.C.IgnoredErrors
    88  }
    89  
    90  func (c ConfigLanguage) NoBuildLock() bool {
    91  	return c.config.NoBuildLock
    92  }
    93  
    94  func (c ConfigLanguage) NewContentEditor() string {
    95  	return c.config.NewContentEditor
    96  }
    97  
    98  func (c ConfigLanguage) Timeout() time.Duration {
    99  	return c.config.C.Timeout
   100  }
   101  
   102  func (c ConfigLanguage) BaseConfig() config.BaseConfig {
   103  	return c.baseConfig
   104  }
   105  
   106  func (c ConfigLanguage) Dirs() config.CommonDirs {
   107  	return c.config.CommonDirs
   108  }
   109  
   110  func (c ConfigLanguage) DirsBase() config.CommonDirs {
   111  	return c.m.Base.CommonDirs
   112  }
   113  
   114  func (c ConfigLanguage) WorkingDir() string {
   115  	return c.m.Base.WorkingDir
   116  }
   117  
   118  func (c ConfigLanguage) Quiet() bool {
   119  	return c.m.Base.Internal.Quiet
   120  }
   121  
   122  // GetConfigSection is mostly used in tests. The switch statement isn't complete, but what's in use.
   123  func (c ConfigLanguage) GetConfigSection(s string) any {
   124  	switch s {
   125  	case "security":
   126  		return c.config.Security
   127  	case "build":
   128  		return c.config.Build
   129  	case "frontmatter":
   130  		return c.config.Frontmatter
   131  	case "caches":
   132  		return c.config.Caches
   133  	case "markup":
   134  		return c.config.Markup
   135  	case "mediaTypes":
   136  		return c.config.MediaTypes.Config
   137  	case "outputFormats":
   138  		return c.config.OutputFormats.Config
   139  	case "permalinks":
   140  		return c.config.Permalinks
   141  	case "minify":
   142  		return c.config.Minify
   143  	case "allModules":
   144  		return c.m.Modules
   145  	case "deployment":
   146  		return c.config.Deployment
   147  	default:
   148  		panic("not implemented: " + s)
   149  	}
   150  }
   151  
   152  func (c ConfigLanguage) GetConfig() any {
   153  	return c.config
   154  }
   155  
   156  func (c ConfigLanguage) CanonifyURLs() bool {
   157  	return c.config.CanonifyURLs
   158  }
   159  
   160  func (c ConfigLanguage) IsUglyURLs(section string) bool {
   161  	return c.config.C.IsUglyURLSection(section)
   162  }
   163  
   164  func (c ConfigLanguage) IgnoreFile(s string) bool {
   165  	return c.config.C.IgnoreFile(s)
   166  }
   167  
   168  func (c ConfigLanguage) DisablePathToLower() bool {
   169  	return c.config.DisablePathToLower
   170  }
   171  
   172  func (c ConfigLanguage) RemovePathAccents() bool {
   173  	return c.config.RemovePathAccents
   174  }
   175  
   176  func (c ConfigLanguage) DefaultContentLanguage() string {
   177  	return c.config.DefaultContentLanguage
   178  }
   179  
   180  func (c ConfigLanguage) DefaultContentLanguageInSubdir() bool {
   181  	return c.config.DefaultContentLanguageInSubdir
   182  }
   183  
   184  func (c ConfigLanguage) SummaryLength() int {
   185  	return c.config.SummaryLength
   186  }
   187  
   188  func (c ConfigLanguage) BuildExpired() bool {
   189  	return c.config.BuildExpired
   190  }
   191  
   192  func (c ConfigLanguage) BuildFuture() bool {
   193  	return c.config.BuildFuture
   194  }
   195  
   196  func (c ConfigLanguage) BuildDrafts() bool {
   197  	return c.config.BuildDrafts
   198  }
   199  
   200  func (c ConfigLanguage) Running() bool {
   201  	return c.config.Internal.Running
   202  }
   203  
   204  func (c ConfigLanguage) PrintUnusedTemplates() bool {
   205  	return c.config.PrintUnusedTemplates
   206  }
   207  
   208  func (c ConfigLanguage) EnableMissingTranslationPlaceholders() bool {
   209  	return c.config.EnableMissingTranslationPlaceholders
   210  }
   211  
   212  func (c ConfigLanguage) PrintI18nWarnings() bool {
   213  	return c.config.PrintI18nWarnings
   214  }
   215  
   216  func (c ConfigLanguage) CreateTitle(s string) string {
   217  	return c.config.C.CreateTitle(s)
   218  }
   219  
   220  func (c ConfigLanguage) Paginate() int {
   221  	return c.config.Paginate
   222  }
   223  
   224  func (c ConfigLanguage) PaginatePath() string {
   225  	return c.config.PaginatePath
   226  }
   227  
   228  func (c ConfigLanguage) StaticDirs() []string {
   229  	return c.config.staticDirs()
   230  }