diff options
author | Bjørn Erik Pedersen <[email protected]> | 2024-06-05 09:21:45 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-06-05 12:16:40 +0200 |
commit | 2b05a50f8f89e4e2f5f7a8ea7ae7993a2c0f3524 (patch) | |
tree | c1692563b326ff6928523955dd17d42d9973d980 /hugolib | |
parent | bc05d854b270dcabd9fb49ae031bb011d37cad2e (diff) | |
download | hugo-2b05a50f8f89e4e2f5f7a8ea7ae7993a2c0f3524.tar.gz hugo-2b05a50f8f89e4e2f5f7a8ea7ae7993a2c0f3524.zip |
Misc remote HTTP/content adapter enhancements
* Recover from server errors
* Improve go adapter rebuilds when adding new content
See #12502
Fixes #12570
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/content_map.go | 15 | ||||
-rw-r--r-- | hugolib/hugo_sites_build.go | 6 | ||||
-rw-r--r-- | hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go | 9 |
3 files changed, 29 insertions, 1 deletions
diff --git a/hugolib/content_map.go b/hugolib/content_map.go index 6ab945209..55c96c9a0 100644 --- a/hugolib/content_map.go +++ b/hugolib/content_map.go @@ -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) + } } } diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go index fe05f5174..12eb6a5f8 100644 --- a/hugolib/hugo_sites_build.go +++ b/hugolib/hugo_sites_build.go @@ -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) diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index f351cbb98..3c50f87f7 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -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) |