mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Misc remote HTTP/content adapter enhancements
* Recover from server errors * Improve go adapter rebuilds when adding new content See #12502 Fixes #12570
This commit is contained in:
parent
bc05d854b2
commit
2b05a50f8f
4 changed files with 33 additions and 2 deletions
|
@ -345,6 +345,7 @@ func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*wa
|
|||
for {
|
||||
select {
|
||||
case changes := <-c.r.changesFromBuild:
|
||||
c.errState.setBuildErr(nil)
|
||||
unlock, err := h.LockBuild()
|
||||
if err != nil {
|
||||
c.r.logger.Errorln("Failed to acquire a build lock: %s", err)
|
||||
|
@ -356,7 +357,9 @@ func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*wa
|
|||
c.r.logger.Errorln("Error while watching:", err)
|
||||
}
|
||||
if c.s != nil && c.s.doLiveReload {
|
||||
if c.changeDetector == nil || len(c.changeDetector.changed()) > 0 {
|
||||
doReload := c.changeDetector == nil || len(c.changeDetector.changed()) > 0
|
||||
doReload = doReload || c.showErrorInBrowser && c.errCount() > 0
|
||||
if doReload {
|
||||
livereload.ForceRefresh()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -386,6 +386,21 @@ func (m *pageMap) addPagesFromGoTmplFi(fi hugofs.FileMetaInfo, buildConfig *Buil
|
|||
pt.AddChange(n.GetIdentity())
|
||||
} else {
|
||||
pt.AddChange(u.GetIdentity())
|
||||
// New content not in use anywhere.
|
||||
// To make sure that these gets listed in any site.RegularPages ranges or similar
|
||||
// we could invalidate everything, but first try to collect a sample set
|
||||
// from the surrounding pages.
|
||||
var surroundingIDs []identity.Identity
|
||||
ids := h.pageTrees.collectIdentitiesSurrounding(pi.Base(), 10)
|
||||
if len(ids) > 0 {
|
||||
surroundingIDs = append(surroundingIDs, ids...)
|
||||
} else {
|
||||
// No surrounding pages found, so invalidate everything.
|
||||
surroundingIDs = []identity.Identity{identity.GenghisKhan}
|
||||
}
|
||||
for _, id := range surroundingIDs {
|
||||
pt.AddChange(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -244,9 +244,13 @@ func (h *HugoSites) process(ctx context.Context, l logg.LevelLogger, config *Bui
|
|||
}
|
||||
|
||||
if len(events) > 0 {
|
||||
// This is a rebuild
|
||||
// This is a rebuild triggered from file events.
|
||||
return h.processPartialFileEvents(ctx, l, config, init, events)
|
||||
} else if len(config.WhatChanged.Changes()) > 0 {
|
||||
// Rebuild triggered from remote events.
|
||||
if err := init(config); err != nil {
|
||||
return err
|
||||
}
|
||||
return h.processPartialRebuildChanges(ctx, l, config)
|
||||
}
|
||||
return h.processFull(ctx, l, config)
|
||||
|
|
|
@ -80,6 +80,7 @@ Pfile Content
|
|||
{{ $.AddPage (dict "kind" "page" "path" "p2" "title" "p2title" "dates" $dates "content" $contentHTML ) }}
|
||||
{{ $.AddPage (dict "kind" "page" "path" "p3" "title" "p3title" "dates" $dates "content" $contentMarkdownDefault "draft" false ) }}
|
||||
{{ $.AddPage (dict "kind" "page" "path" "p4" "title" "p4title" "dates" $dates "content" $contentMarkdownDefault "draft" $data.draft ) }}
|
||||
ADD_MORE_PLACEHOLDER
|
||||
|
||||
|
||||
{{ $resourceContent := dict "value" $dataResource }}
|
||||
|
@ -279,6 +280,14 @@ func TestPagesFromGoTmplRemovePage(t *testing.T) {
|
|||
b.AssertFileContent("public/index.html", "RegularPagesRecursive: p1:p1:/docs/p1|p3title:/docs/p3|p4title:/docs/p4|pfile:/docs/pfile|$")
|
||||
}
|
||||
|
||||
func TestPagesFromGoTmplAddPage(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := hugolib.TestRunning(t, filesPagesFromDataTempleBasic)
|
||||
b.EditFileReplaceAll("content/docs/_content.gotmpl", "ADD_MORE_PLACEHOLDER", `{{ $.AddPage (dict "kind" "page" "path" "page_added" "title" "page_added_title" "dates" $dates "content" $contentHTML ) }}`).Build()
|
||||
b.AssertFileExists("public/docs/page_added/index.html", true)
|
||||
b.AssertFileContent("public/index.html", "RegularPagesRecursive: p1:p1:/docs/p1|p2title:/docs/p2|p3title:/docs/p3|p4title:/docs/p4|page_added_title:/docs/page_added|pfile:/docs/pfile|$")
|
||||
}
|
||||
|
||||
func TestPagesFromGoTmplDraftPage(t *testing.T) {
|
||||
t.Parallel()
|
||||
b := hugolib.TestRunning(t, filesPagesFromDataTempleBasic)
|
||||
|
|
Loading…
Reference in a new issue