Skip to content

Commit 72903be

Browse files
committed
commands: Make sure all language homes are always re-rendered in fast render mode
Fixes #4125
1 parent 1c114d5 commit 72903be

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

commands/hugo.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,17 @@ func (c *commandeer) rebuildSites(events []fsnotify.Event) error {
940940
visited := c.visitedURLs.PeekAllSet()
941941
doLiveReload := !buildWatch && !c.Cfg.GetBool("disableLiveReload")
942942
if doLiveReload && !c.Cfg.GetBool("disableFastRender") {
943-
home := c.pathSpec.PrependBasePath("/")
944-
// Make sure we always render the home page
945-
visited[home] = true
943+
944+
// Make sure we always render the home pages
945+
for _, l := range c.languages {
946+
langPath := c.PathSpec().GetLangSubDir(l.Lang)
947+
if langPath != "" {
948+
langPath = langPath + "/"
949+
}
950+
home := c.pathSpec.PrependBasePath("/" + langPath)
951+
visited[home] = true
952+
}
953+
946954
}
947955
return Hugo.Build(hugolib.BuildCfg{RecentlyVisited: visited}, events...)
948956
}

helpers/pathspec.go

+16-7
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ type PathSpec struct {
3131
uglyURLs bool
3232
canonifyURLs bool
3333

34-
language *Language
35-
//StatsCounter *siteSta
34+
language *Language
35+
languages Languages
3636

3737
// pagination path handling
3838
paginatePath string
@@ -85,9 +85,20 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
8585
staticDirs = append(staticDirs, getStringOrStringSlice(cfg, "staticDir", i)...)
8686
}
8787

88-
var lang string
88+
var (
89+
lang string
90+
language *Language
91+
languages Languages
92+
)
93+
8994
if l, ok := cfg.(*Language); ok {
95+
language = l
9096
lang = l.Lang
97+
98+
}
99+
100+
if l, ok := cfg.Get("languagesSorted").(Languages); ok {
101+
languages = l
91102
}
92103

93104
ps := &PathSpec{
@@ -98,6 +109,8 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
98109
uglyURLs: cfg.GetBool("uglyURLs"),
99110
canonifyURLs: cfg.GetBool("canonifyURLs"),
100111
multilingual: cfg.GetBool("multilingual"),
112+
language: language,
113+
languages: languages,
101114
defaultContentLanguageInSubdir: cfg.GetBool("defaultContentLanguageInSubdir"),
102115
defaultContentLanguage: cfg.GetString("defaultContentLanguage"),
103116
paginatePath: cfg.GetString("paginatePath"),
@@ -119,10 +132,6 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) (*PathSpec, error) {
119132

120133
ps.PublishDir = publishDir
121134

122-
if language, ok := cfg.(*Language); ok {
123-
ps.language = language
124-
}
125-
126135
return ps, nil
127136
}
128137

helpers/url.go

+17
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,23 @@ func (p *PathSpec) getLanguagePrefix() string {
215215
return currentLang
216216
}
217217

218+
// GetLangSubDir returns the given language's subdir if needed.
219+
func (p *PathSpec) GetLangSubDir(lang string) string {
220+
if !p.multilingual {
221+
return ""
222+
}
223+
224+
if p.languages.IsMultihost() {
225+
return ""
226+
}
227+
228+
if lang == "" || (lang == p.defaultContentLanguage && !p.defaultContentLanguageInSubdir) {
229+
return ""
230+
}
231+
232+
return lang
233+
}
234+
218235
// IsAbsURL determines whether the given path points to an absolute URL.
219236
func IsAbsURL(path string) bool {
220237
url, err := url.Parse(path)

0 commit comments

Comments
 (0)