99import os .path
1010import re
1111import sys
12+ import subprocess
1213from collections import defaultdict
1314
1415from html .parser import HTMLParser
@@ -59,6 +60,13 @@ def handle_endtag(self, tag):
5960 return parser .title if parser .done else None
6061
6162
63+ def get_date_authored_timestamp_from_git (path ):
64+ source = os .path .realpath (path )
65+ proc = subprocess .run (["git" , "log" , "-1" , "--format=%at" , source ],
66+ capture_output = True , encoding = "utf_8" )
67+ return int (proc .stdout .splitlines ()[- 1 ])
68+
69+
6270def get_bs_spec_metadata (folder_name , path ):
6371 spec = Spec (path )
6472 spec .assembleDocument ()
@@ -84,6 +92,7 @@ def get_bs_spec_metadata(folder_name, path):
8492 shortname = spec .md .shortname
8593
8694 return {
95+ "timestamp" : get_date_authored_timestamp_from_git (path ),
8796 "shortname" : shortname ,
8897 "level" : level ,
8998 "title" : spec .md .title ,
@@ -112,6 +121,9 @@ def create_symlink(shortname, spec_folder):
112121 """Creates a <shortname> symlink pointing to the given <spec_folder>.
113122 """
114123
124+ if spec_folder in timestamps :
125+ timestamps [shortname ] = timestamps [spec_folder ]
126+
115127 try :
116128 os .symlink (spec_folder , shortname )
117129 except OSError :
@@ -134,6 +146,7 @@ def create_symlink(shortname, spec_folder):
134146constants .setErrorLevel ("nothing" )
135147
136148specgroups = defaultdict (list )
149+ timestamps = defaultdict (list )
137150
138151for entry in os .scandir ("." ):
139152 if entry .is_dir (follow_symlinks = False ):
@@ -145,6 +158,7 @@ def create_symlink(shortname, spec_folder):
145158 html_file = os .path .join (entry .path , "Overview.html" )
146159 if os .path .exists (bs_file ):
147160 metadata = get_bs_spec_metadata (entry .name , bs_file )
161+ timestamps [entry .name ] = metadata ["timestamp" ]
148162 elif os .path .exists (html_file ):
149163 metadata = get_html_spec_metadata (entry .name , html_file )
150164 else :
@@ -186,6 +200,9 @@ def create_symlink(shortname, spec_folder):
186200 if shortname == "css-snapshot" :
187201 create_symlink ("css" , currentWorkDir )
188202
203+ with open ('./timestamps.json' , 'w' ) as f :
204+ json .dump (dict (sorted (timestamps .items ())), f , indent = 2 )
205+
189206with open ("./index.html" , mode = 'w' , encoding = "UTF-8" ) as f :
190207 template = jinja_env .get_template ("index.html.j2" )
191208 f .write (template .render (specgroups = specgroups ))
0 commit comments