Skip to content

Commit 4aff2b6

Browse files
committed
source: Cache language config
``` benchmark old ns/op new ns/op delta BenchmarkSiteBuilding/frontmatter=YAML|num_root_sections=1|num_pages=5000|tags_per_page=0|shortcodes=false|render=false-4 552742744 501838152 -9.21% benchmark old allocs new allocs delta BenchmarkSiteBuilding/frontmatter=YAML|num_root_sections=1|num_pages=5000|tags_per_page=0|shortcodes=false|render=false-4 3047393 2957378 -2.95% benchmark old bytes new bytes delta BenchmarkSiteBuilding/frontmatter=YAML|num_root_sections=1|num_pages=5000|tags_per_page=0|shortcodes=false|render=false-4 356533864 354291924 -0.63% ```
1 parent 2342df4 commit 4aff2b6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

‎source/file.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,15 @@ import (
2727
type SourceSpec struct {
2828
Cfg config.Provider
2929
Fs *hugofs.Fs
30+
31+
languages map[string]interface{}
32+
defaultContentLanguage string
3033
}
3134

3235
func NewSourceSpec(cfg config.Provider, fs *hugofs.Fs) SourceSpec {
33-
return SourceSpec{Cfg: cfg, Fs: fs}
36+
defaultLang := cfg.GetString("defaultContentLanguage")
37+
languages := cfg.GetStringMap("languages")
38+
return SourceSpec{Cfg: cfg, Fs: fs, languages: languages, defaultContentLanguage: defaultLang}
3439
}
3540

3641
// File represents a source content file.
@@ -139,8 +144,8 @@ func (sp SourceSpec) NewFile(relpath string) *File {
139144
f.baseName = helpers.Filename(f.LogicalName())
140145

141146
lang := strings.TrimPrefix(filepath.Ext(f.baseName), ".")
142-
if _, ok := sp.Cfg.GetStringMap("languages")[lang]; lang == "" || !ok {
143-
f.lang = sp.Cfg.GetString("defaultContentLanguage")
147+
if _, ok := sp.languages[lang]; lang == "" || !ok {
148+
f.lang = sp.defaultContentLanguage
144149
f.translationBaseName = f.baseName
145150
} else {
146151
f.lang = lang

0 commit comments

Comments
 (0)