@@ -54,6 +54,7 @@ public function origin(): Folder { return $this->origin; }
5454
5555 /** Yields all the media files in this source */
5656 protected function mediaIn (Files $ files ): iterable {
57+ $ updated = false ;
5758 $ images = [];
5859 foreach ($ this ->entry ['images ' ] ?? [] as $ image ) {
5960 $ images [$ image ['name ' ]]= $ image ;
@@ -63,13 +64,16 @@ protected function mediaIn(Files $files): iterable {
6364 $ name = $ file ->filename ;
6465 if (!isset ($ images [$ name ]) || $ file ->lastModified () > $ images [$ name ]['modified ' ]) {
6566 $ this ->entry ['images ' ][$ name ]= yield new UploadMedia ($ this ->entry ['slug ' ], $ file , $ processing );
67+ $ updated = true ;
6668 }
6769 unset($ images [$ name ]);
6870 }
6971
7072 foreach ($ images as $ rest ) {
7173 yield new DeleteMedia ($ this ->entry ['slug ' ], $ rest ['name ' ]);
74+ $ updated = true ;
7275 }
76+ return $ updated ;
7377 }
7478
7579 /** Returns an entry from the given description */
@@ -79,23 +83,27 @@ public abstract function entryFrom(Description $description): array<string, mixe
7983 public abstract function contentsIn (Files $ files ): iterable ;
8084
8185 /** Yields tasks to synchronize this source */
82- public function synchronize (Files $ files ) {
86+ public function synchronize (Files $ files ): iterable {
8387 $ this ->entry ??= yield new FetchEntry ($ this ->name ());
8488 if (!isset ($ this ->entry ['modified ' ]) || $ this ->file ->lastModified () > $ this ->entry ['modified ' ]) {
8589 $ changes = $ this ->entryFrom (self ::$ descriptions ->parse ($ this ->file ));
86- $ updated = time ();
90+ $ this ->entry = $ changes + ($ this ->entry ?? []);
91+ $ updated = true ;
92+ } else {
93+ $ changes = [];
94+ $ updated = false ;
8795 }
8896
8997 // Although the description file may not have changed, nested contents
9098 // may have, so process them unconditionally.
91- yield from $ this ->contentsIn ($ files );
99+ $ updated |= yield from $ this ->contentsIn ($ files );
92100
93- if (isset ($ updated )) {
94- $ changes ['locations ' ]= yield new LookupLocationInfos ($ changes );
95- $ changes ['weather ' ]= yield new LookupWeather ($ changes , $ this ->entry ['images ' ] ?? []);
96- $ changes ['published ' ]= time ();
97- yield new PublishEntry ($ this ->entry ['slug ' ], $ changes );
101+ if ($ updated ) {
102+ $ changes ['locations ' ]= $ this ->entry ['locations ' ]= yield new LookupLocationInfos ($ this ->entry );
103+ $ changes ['weather ' ]= $ this ->entry ['weather ' ]= yield new LookupWeather ($ this ->entry );
104+ yield new PublishEntry ($ this ->entry ['slug ' ], $ changes + ['published ' => time ()]);
98105 }
106+ return $ updated ;
99107 }
100108
101109 /** @return string */
0 commit comments