]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Misc remote HTTP/content adapter enhancements
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 5 Jun 2024 07:21:45 +0000 (09:21 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 5 Jun 2024 10:16:40 +0000 (12:16 +0200)
* Recover from server errors
* Improve go adapter rebuilds when adding new content

See #12502
Fixes #12570

commands/hugobuilder.go
hugolib/content_map.go
hugolib/hugo_sites_build.go
hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go

index 99bd8a04a9028d22d32c8905bc737a9816a30761..d77f1f178d88d1ec36aa662af26584e93ab2b280 100644 (file)
@@ -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()
                                        }
                                }
index 6ab945209ec193f7d6b9a03f820d6e6960b55da4..55c96c9a0532c660cdd2e08844906160555a499e 100644 (file)
@@ -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)
+                                                       }
                                                }
                                        }
 
index fe05f5174ea9b7d205fd7bdf7d280725a1503531..12eb6a5f8d7a5322eaf2ab0f1f1f4f29dfaf16a2 100644 (file)
@@ -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)
index f351cbb98714335c933ad3da925a395851d3ba69..3c50f87f7eaa3925df3619654c3d8f2fe3d576b7 100644 (file)
@@ -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)