@@ -116,7 +116,7 @@ func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
116
116
conf := & config
117
117
if conf .whatChanged == nil {
118
118
// Assume everything has changed
119
- conf .whatChanged = & whatChanged {contentChanged : true }
119
+ conf .whatChanged = & whatChanged {needsPagesAssemble : true }
120
120
}
121
121
122
122
var prepareErr error
@@ -224,7 +224,7 @@ func (h *HugoSites) initRebuild(config *BuildCfg) error {
224
224
})
225
225
226
226
for _ , s := range h .Sites {
227
- s .resetBuildState (config .whatChanged .contentChanged )
227
+ s .resetBuildState (config .whatChanged .needsPagesAssemble )
228
228
}
229
229
230
230
h .reset (config )
@@ -252,7 +252,15 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil
252
252
l = l .WithField ("step" , "assemble" )
253
253
defer loggers .TimeTrackf (l , time .Now (), nil , "" )
254
254
255
- if ! bcfg .whatChanged .contentChanged {
255
+ if ! bcfg .whatChanged .needsPagesAssemble {
256
+ changes := bcfg .whatChanged .Changes ()
257
+
258
+ if len (changes ) > 0 {
259
+ // TODO1 consolidate.
260
+ if err := h .resolveAndClearStateForIdentities (ctx , l , nil , changes ); err != nil {
261
+ return err
262
+ }
263
+ }
256
264
return nil
257
265
}
258
266
@@ -626,10 +634,10 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
626
634
logger := h .Log
627
635
628
636
var (
629
- tmplAdded bool
630
- tmplChanged bool
631
- i18nChanged bool
632
- contentChanged bool
637
+ tmplAdded bool
638
+ tmplChanged bool
639
+ i18nChanged bool
640
+ needsPagesAssemble bool
633
641
)
634
642
635
643
changedPaths := struct {
@@ -709,13 +717,21 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
709
717
changes = append (changes , ids ... )
710
718
}
711
719
} else {
712
- h .pageTrees .treePagesFromTemplateOptions .GetAll (pathInfo .Base (),
713
- func (n * pagesfromdata.PagesFromTemplate ) {
720
+ h .pageTrees .treePagesFromTemplateOptions .DeleteAllFunc (pathInfo .Base (),
721
+ func (s string , n * pagesfromdata.PagesFromTemplate ) bool {
714
722
changes = append (changes , n .DependencyManager )
723
+
724
+ // Try to open the file to see if has been deleted.
725
+ f , err := n .GoTmplFi .Meta ().Open ()
726
+ if err == nil {
727
+ f .Close ()
728
+ }
729
+ // TODO1 also remove all pages and resources below this path.
730
+ return err != nil
715
731
})
716
732
}
717
733
718
- contentChanged = true
734
+ needsPagesAssemble = true
719
735
720
736
if config .RecentlyVisited != nil {
721
737
// Fast render mode. Adding them to the visited queue
@@ -778,13 +794,15 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
778
794
case files .ComponentFolderAssets :
779
795
logger .Println ("Asset changed" , pathInfo .Path ())
780
796
changes = append (changes , pathInfo )
797
+ needsPagesAssemble = true
781
798
case files .ComponentFolderData :
782
799
logger .Println ("Data changed" , pathInfo .Path ())
783
800
784
801
// This should cover all usage of site.Data.
785
802
// Currently very coarse grained.
786
803
changes = append (changes , siteidentities .Data )
787
804
h .init .data .Reset ()
805
+ needsPagesAssemble = true
788
806
case files .ComponentFolderI18n :
789
807
logger .Println ("i18n changed" , pathInfo .Path ())
790
808
i18nChanged = true
@@ -868,8 +886,8 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
868
886
resourceFiles := h .fileEventsContentPaths (addedOrChangedContent )
869
887
870
888
changed := & whatChanged {
871
- contentChanged : contentChanged ,
872
- identitySet : make (identity.Identities ),
889
+ needsPagesAssemble : needsPagesAssemble ,
890
+ identitySet : make (identity.Identities ),
873
891
}
874
892
changed .Add (changes ... )
875
893
@@ -928,7 +946,7 @@ func (h *HugoSites) processPartial(ctx context.Context, l logg.LevelLogger, conf
928
946
}
929
947
930
948
if h .isRebuild () {
931
- if err := h .processContentAdaptersOnRebuild (ctx ); err != nil {
949
+ if err := h .processContentAdaptersOnRebuild (ctx , config ); err != nil {
932
950
return err
933
951
}
934
952
}
@@ -955,16 +973,39 @@ func (h *HugoSites) processFull(ctx context.Context, l logg.LevelLogger, config
955
973
return err
956
974
}
957
975
958
- func (h * HugoSites ) processContentAdaptersOnRebuild (ctx context.Context ) error {
976
+ func (s * Site ) handleContentAdapterChanges (bi pagesfromdata.BuildInfo , whatChanged * whatChanged ) {
977
+ if ! s .h .isRebuild () {
978
+ return
979
+ }
980
+
981
+ if len (bi .ChangedIdentities ) > 0 {
982
+ whatChanged .Add (bi .ChangedIdentities ... )
983
+ }
984
+
985
+ for _ , p := range bi .DeletedPaths {
986
+ pp := path .Join (bi .Path .Base (), p )
987
+ if v , ok := s .pageMap .treePages .Delete (pp ); ok {
988
+ whatChanged .Add (v .GetIdentity ())
989
+ }
990
+ }
991
+ }
992
+
993
+ func (h * HugoSites ) processContentAdaptersOnRebuild (ctx context.Context , buildConfig * BuildCfg ) error {
959
994
g := rungroup .Run [* pagesfromdata.PagesFromTemplate ](ctx , rungroup.Config [* pagesfromdata.PagesFromTemplate ]{
960
995
NumWorkers : h .numWorkers ,
961
996
Handle : func (ctx context.Context , p * pagesfromdata.PagesFromTemplate ) error {
962
- return p .Execute (ctx )
997
+ bi , err := p .Execute (ctx )
998
+ if err != nil {
999
+ return err
1000
+ }
1001
+ s := p .Site .(* Site )
1002
+ s .handleContentAdapterChanges (bi , buildConfig .whatChanged )
1003
+ return nil
963
1004
},
964
1005
})
965
1006
966
1007
h .pageTrees .treePagesFromTemplateOptions .WalkPrefixRaw (doctree .LockTypeRead , "" , func (key string , p * pagesfromdata.PagesFromTemplate ) (bool , error ) {
967
- if p .BuildState . Rebuild {
1008
+ if p .StaleVersion () > 0 {
968
1009
g .Enqueue (p )
969
1010
}
970
1011
return false , nil
0 commit comments