11import re
2+ import subprocess
23from contextlib import suppress
34from pathlib import Path
45
@@ -245,9 +246,26 @@ def create_node():
245246 "description" : None ,
246247 "link" : None ,
247248 "children" : [],
249+ "last_modified" : None ,
248250 }
249251
250252
253+ def get_git_last_modified_time (path ):
254+ """
255+ Get the last modified time of a file using Git metadata.
256+ """
257+ try :
258+ result = subprocess .run (
259+ ["git" , "log" , "-1" , "--format=%cI" , str (path )],
260+ capture_output = True ,
261+ text = True ,
262+ check = True ,
263+ )
264+ return result .stdout .strip ()
265+ except subprocess .CalledProcessError :
266+ return None
267+
268+
251269def scan_directory (path_name , base = None ):
252270 """
253271 We scan a given directory for valid pages and return a tree
@@ -277,6 +295,10 @@ def scan_directory(path_name, base=None):
277295 # Get tags, add as child
278296 tags = get_tags_rolling_buffer (index_path )
279297 node = update_tags (node , tags )
298+ # Add last modified time for index.html
299+ lastmod_time = get_git_last_modified_time (index_path )
300+ if lastmod_time :
301+ node ["last_modified" ] = lastmod_time
280302
281303 # Cycle through other files in this directory
282304 for child in node_path .iterdir ():
@@ -292,6 +314,11 @@ def scan_directory(path_name, base=None):
292314 child_tags ["link" ] = get_extended_copydoc (
293315 extended_path , base = base
294316 )
317+ # Add last modified time for child paths
318+ child_lastmod_time = get_git_last_modified_time (child )
319+ if child_lastmod_time :
320+ child_tags ["last_modified" ] = child_lastmod_time
321+
295322 node ["children" ].append (child_tags )
296323 # If the child is a directory, scan it
297324 if child .is_dir ():
0 commit comments