Skip to content

Commit 202ea2c

Browse files
committed
More TODOs
1 parent 9c91110 commit 202ea2c

File tree

15 files changed

+109
-49
lines changed

15 files changed

+109
-49
lines changed

‎config/allconfig/allconfig.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ func (c *Configs) Init(logger loggers.Logger) error {
934934
}
935935

936936
// Apply default project mounts.
937-
if err := modules.ApplyProjectConfigDefaults(c.Modules[0], c.configLangs...); err != nil {
937+
if err := modules.ApplyProjectConfigDefaults(logger.Logger(), c.Modules[0], c.configLangs...); err != nil {
938938
return err
939939
}
940940

‎config/allconfig/alldecoders.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ var allDecoderSetups = map[string]decodeWeight{
309309
key: "module",
310310
decode: func(d decodeWeight, p decodeConfig) error {
311311
var err error
312-
p.c.Module, err = modules.DecodeConfig(p.p)
312+
p.c.Module, err = modules.DecodeConfig(p.logger.Logger(), p.p)
313313
return err
314314
},
315315
},

‎hugolib/filesystems/basefs.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ func (b *sourceFilesystemsBuilder) createOverlayFs(
709709

710710
patterns, hasLegacyIncludes, hasLegacyExcludes := mount.FilesToFilter()
711711
if hasLegacyIncludes {
712-
hugo.Deprecate("module.mounts.includeFiles", "Replaced by the simpler 'files' setting, see https://gohugo.io/configuration/module/#files", "v0.152.0")
712+
hugo.Deprecate("module.mounts.includeFiles", "Replaced by the simpler 'files' setting, see https://gohugo.io/configuration/module/#files", "v0.153.0")
713713
}
714714
if hasLegacyExcludes {
715-
hugo.Deprecate("module.mounts.excludeFiles", "Replaced by the simpler 'files' setting, see https://gohugo.io/configuration/module/#files", "v0.152.0")
715+
hugo.Deprecate("module.mounts.excludeFiles", "Replaced by the simpler 'files' setting, see https://gohugo.io/configuration/module/#files", "v0.153.0")
716716
}
717717

718718
inclusionFilter, err := hglob.NewFilenameFilterV2(patterns)

‎hugolib/page.go‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"iter"
2020
"path/filepath"
21+
"slices"
2122
"strconv"
2223
"strings"
2324
"sync/atomic"
@@ -495,8 +496,7 @@ func (ps *pageState) AllTranslations() page.Pages {
495496
if ps.m.pageConfig.TranslationKey != "" {
496497
// translationKey set by user.
497498
pas, _ := ps.s.h.translationKeyPages.Get(ps.m.pageConfig.TranslationKey)
498-
pasc := make(page.Pages, len(pas))
499-
copy(pasc, pas)
499+
pasc := slices.Clone(pas)
500500
page.SortByLanguage(pasc)
501501
return pasc, nil
502502
}
@@ -537,7 +537,6 @@ func (ps *pageState) siteVectors() sitesmatrix.VectorIterator {
537537

538538
// TODO1 name.
539539
func (ps *pageState) Rotate(dimensionStr string) (page.Pages, error) {
540-
// TODO1: For language, consider the special case with translationKey.
541540
dimensionStr = strings.ToLower(dimensionStr)
542541
key := ps.Path() + "/" + "rotate-" + dimensionStr
543542
d, err := sitesmatrix.ParseDimension(dimensionStr)
@@ -557,6 +556,17 @@ func (ps *pageState) Rotate(dimensionStr string) (page.Pages, error) {
557556
},
558557
)
559558

559+
if dimensionStr == "language" && ps.m.pageConfig.TranslationKey != "" {
560+
// translationKey set by user.
561+
// This is an old construct back from when languages were introduced.
562+
// We keep it for backward compatibility.
563+
// ALso see AllTranslations.
564+
pas, _ := ps.s.h.translationKeyPages.Get(ps.m.pageConfig.TranslationKey)
565+
pasc := slices.Clone(pas)
566+
page.SortByLanguage(pasc)
567+
return pasc, nil
568+
}
569+
560570
pas = pagePredicates.ShouldLink.Filter(pas)
561571
page.SortByDims(pas)
562572
return pas, nil
@@ -858,7 +868,6 @@ func (ps *pageState) posOffset(offset int) text.Position {
858868
// shiftToOutputFormat is serialized. The output format idx refers to the
859869
// full set of output formats for all sites.
860870
// This is serialized.
861-
// TODO1 with the added dimensions, we need to compress the pageOutputs slice.
862871
func (ps *pageState) shiftToOutputFormat(isRenderingSite bool, idx int) error {
863872
if err := ps.initPage(); err != nil {
864873
return err

‎hugolib/page__paths.go‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package hugolib
1515

1616
import (
1717
"net/url"
18+
"path"
1819
"strings"
1920

2021
"github.com/gohugoio/hugo/output"
@@ -185,11 +186,7 @@ func createTargetPathDescriptor(p *pageState) (page.TargetPathDescriptor, error)
185186

186187
if opath != "" {
187188
opath, _ = url.QueryUnescape(opath)
188-
if strings.HasSuffix(opath, "//") {
189-
// When rewriting the _index of the section the permalink config is applied to,
190-
// we get double slashes at the end sometimes; clear them up here
191-
opath = strings.TrimSuffix(opath, "/")
192-
}
189+
opath = path.Clean(opath)
193190

194191
desc.ExpandedPermalink = opath
195192

‎hugolib/page_test.go‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,41 @@ Resources: {{ range .Resources }}{{ .RelPermalink }}|{{ .Content }}|{{ end }}|
14031403
)
14041404
}
14051405

1406+
func TestTranslationKeyRotate(t *testing.T) {
1407+
t.Parallel()
1408+
1409+
files := `
1410+
-- hugo.toml --
1411+
disableKinds = ['home','rss','section','sitemap','taxonomy']
1412+
defaultContentLanguage = 'en'
1413+
defaultContentLanguageInSubdir = true
1414+
[languages]
1415+
[languages.en]
1416+
weight = 1
1417+
[languages.pt]
1418+
weight = 2
1419+
-- content/foo.md --
1420+
---
1421+
title: Foo
1422+
translationkey: "mykey"
1423+
---
1424+
-- content/bar.md --
1425+
---
1426+
title: Bar
1427+
translationkey: "mykey"
1428+
---
1429+
-- layouts/all.html --
1430+
Rotate(language): {{ with .Rotate "language" }}{{ range . }}{{ template "printp" . }}|{{ end }}{{ end }}$
1431+
{{ define "printp" }}{{ .RelPermalink }}:{{ with .Site }}{{ template "prints" . }}{{ end }}{{ end }}
1432+
{{ define "prints" }}/l:{{ .Language.Name }}/v:{{ .Version.Name }}/r:{{ .Role.Name }}{{ end }}
1433+
`
1434+
1435+
b := Test(t, files)
1436+
1437+
b.AssertFileContent("public/en/foo/index.html", "Rotate(language): /en/bar/:/l:en/v:v1/r:guest|/en/foo/:/l:en/v:v1/r:guest|$")
1438+
b.AssertFileContent("public/en/bar/index.html", "Rotate(language): /en/bar/:/l:en/v:v1/r:guest|/en/foo/:/l:en/v:v1/r:guest|$")
1439+
}
1440+
14061441
func TestChompBOM(t *testing.T) {
14071442
t.Parallel()
14081443
c := qt.New(t)

‎hugolib/segments/segments.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (s *segmentsBuilder) buildOne(f []SegmentMatcherFields) (predicate.PR[Segme
151151
}
152152
}
153153
if fields.Lang != "" {
154-
hugo.DeprecateWithLogger("config segments.[...]lang ", "Use sites.matrix instead, see https://gohugo.io/configuration/segments/#segment-definition", "v0.152.0", s.logger.Logger())
154+
hugo.DeprecateWithLogger("config segments.[...]lang ", "Use sites.matrix instead, see https://gohugo.io/configuration/segments/#segment-definition", "v0.153.0", s.logger.Logger())
155155
fields.Sites.Matrix.Languages = []string{fields.Lang}
156156
}
157157
if !fields.Sites.Matrix.IsZero() {

‎hugolib/site.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,8 @@ func newHugoSites(
523523
tplimpl.StoreOptions{
524524
Fs: s.BaseFs.Layouts.Fs,
525525
Log: s.Log,
526-
DefaultContentLanguage: s.Conf.DefaultContentLanguage(),
527526
Watching: s.Conf.Watching(),
528-
PathHandler: s.Conf.PathParser(),
527+
PathParser: s.Conf.PathParser(),
529528
Metrics: d.Metrics,
530529
OutputFormats: s.conf.OutputFormats.Config,
531530
MediaTypes: s.conf.MediaTypes.Config,

‎modules/collect.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ LOOP:
531531
}
532532
}
533533

534-
config, err := decodeConfig(tc.cfg, c.moduleConfig.replacementsMap)
534+
config, err := decodeConfig(c.logger.Logger(), tc.cfg, c.moduleConfig.replacementsMap)
535535
if err != nil {
536536
return err
537537
}
@@ -796,7 +796,7 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
796796
return nil, fmt.Errorf("%s: mount target must be one of: %v", errMsg, files.ComponentFolders)
797797
}
798798

799-
if err := mnt.init(); err != nil {
799+
if err := mnt.init(c.logger.Logger()); err != nil {
800800
return nil, fmt.Errorf("%s: %w", errMsg, err)
801801
}
802802

‎modules/config.go‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"slices"
2121
"strings"
2222

23+
"github.com/bep/logg"
2324
"github.com/gohugoio/hugo/common/hstrings"
2425
"github.com/gohugoio/hugo/common/hugo"
2526
"github.com/gohugoio/hugo/common/types"
@@ -63,7 +64,7 @@ var DefaultModuleConfig = Config{
6364

6465
// ApplyProjectConfigDefaults applies default/missing module configuration for
6566
// the main project.
66-
func ApplyProjectConfigDefaults(mod Module, cfgs ...config.AllProvider) error {
67+
func ApplyProjectConfigDefaults(logger logg.Logger, mod Module, cfgs ...config.AllProvider) error {
6768
moda := mod.(*moduleAdapter)
6869

6970
// To bridge between old and new configuration format we need
@@ -157,7 +158,7 @@ func ApplyProjectConfigDefaults(mod Module, cfgs ...config.AllProvider) error {
157158

158159
if dir != "" {
159160
mnt := Mount{Lang: lang, Source: dir, Target: component}
160-
if err := mnt.init(); err != nil {
161+
if err := mnt.init(logger); err != nil {
161162
return fmt.Errorf("failed to init mount %q %d: %w", lang, i, err)
162163
}
163164
mounts = append(mounts, mnt)
@@ -173,11 +174,11 @@ func ApplyProjectConfigDefaults(mod Module, cfgs ...config.AllProvider) error {
173174
}
174175

175176
// DecodeConfig creates a modules Config from a given Hugo configuration.
176-
func DecodeConfig(cfg config.Provider) (Config, error) {
177-
return decodeConfig(cfg, nil)
177+
func DecodeConfig(logger logg.Logger, cfg config.Provider) (Config, error) {
178+
return decodeConfig(logger, cfg, nil)
178179
}
179180

180-
func decodeConfig(cfg config.Provider, pathReplacements map[string]string) (Config, error) {
181+
func decodeConfig(logger logg.Logger, cfg config.Provider, pathReplacements map[string]string) (Config, error) {
181182
c := DefaultModuleConfig
182183
c.replacementsMap = pathReplacements
183184

@@ -228,7 +229,7 @@ func decodeConfig(cfg config.Provider, pathReplacements map[string]string) (Conf
228229
for i, mnt := range c.Mounts {
229230
mnt.Source = filepath.Clean(mnt.Source)
230231
mnt.Target = filepath.Clean(mnt.Target)
231-
if err := mnt.init(); err != nil {
232+
if err := mnt.init(logger); err != nil {
232233
return c, fmt.Errorf("failed to init mount %d: %w", i, err)
233234
}
234235
c.Mounts[i] = mnt
@@ -492,11 +493,13 @@ func (m Mount) ComponentAndName() (string, string) {
492493
return c, n
493494
}
494495

495-
func (m *Mount) init() error {
496+
func (m *Mount) init(logger logg.Logger) error {
496497
if m.Lang != "" {
497498
// We moved this to a more flixeble setup in Hugo 0.148.0.
498499
m.Sites.Matrix.Languages = append(m.Sites.Matrix.Languages, m.Lang)
499-
m.Lang = "" // TODO1 deprecate.
500+
m.Lang = ""
501+
502+
hugo.DeprecateWithLogger("module.mounts.lang", "Replaced by the more powerful 'sites.matrix' setting, see https://gohugo.io/configuration/module/#mounts", "v0.153.0", logger)
500503
}
501504

502505
if len(m.Sites.Matrix.Languages) == 0 {

0 commit comments

Comments
 (0)