@@ -140,34 +140,34 @@ def main():
140140 config .webdev = True
141141 assert config .mail_domain
142142
143- # start web page generation, open a browser and wait for changes
144143 www_path , src_path , build_dir = get_paths (config )
145144 build_dir = build_webpages (src_path , build_dir , config )
146145 index_path = build_dir .joinpath ("index.html" )
147146 webbrowser .open (str (index_path ))
148- stats = snapshot_dir_stats ( src_path )
147+
149148 print (f"\n Opened URL: file://{ index_path .resolve ()} \n " )
150- print (f"watching { src_path } directory for changes" )
149+ print (f"Watching { src_path } directory for changes... " )
151150
151+ stats = snapshot_dir_stats (src_path )
152152 changenum = 0
153- count = 0
153+ debounce_time = 0.5 # wait 0.5s after detecting a change
154+
154155 while True :
156+ time .sleep (1 )
155157 newstats = snapshot_dir_stats (src_path )
156- if newstats == stats and count % 60 != 0 :
157- count += 1
158- time .sleep (1.0 )
159- continue
160-
161- for key in newstats :
162- if stats [key ] != newstats [key ]:
163- print (f"*** CHANGED: { key } " )
164- changenum += 1
165-
166- stats = newstats
167- build_webpages (src_path , build_dir , config )
168- print (f"[{ changenum } ] regenerated web pages at: { index_path } " )
169- print (f"URL: file://{ index_path .resolve ()} \n \n " )
170- count = 0
158+
159+ if newstats != stats :
160+ changed_files = [f for f in newstats if stats .get (f ) != newstats [f ]]
161+ for f in changed_files :
162+ print (f"*** CHANGED: { f } " )
163+
164+ stats = newstats
165+ changenum += 1
166+ build_webpages (src_path , build_dir , config )
167+ print (f"[{ changenum } ] regenerated web pages at: { index_path } " )
168+ print (f"URL: file://{ index_path .resolve ()} \n \n " )
169+
170+ time .sleep (debounce_time ) # simple debounce
171171
172172
173173if __name__ == "__main__" :
0 commit comments