@@ -155,13 +155,14 @@ def on_page_markdown(
155155 logging .debug ("Excluding page " + page .file .src_path )
156156 return markdown
157157
158- # revision date
159- revision_dates = self .util .get_date_formats_for_timestamp (
160- commit_timestamp = self .util .get_git_commit_timestamp (
158+ # Retrieve git commit timestamp
159+ last_revision_timestamp = self .util .get_git_commit_timestamp (
161160 path = page .file .abs_src_path ,
162161 is_first_commit = False ,
163- )
164162 )
163+
164+ # Last revision date
165+ revision_dates = self .util .get_date_formats_for_timestamp (last_revision_timestamp )
165166 revision_date = revision_dates [self .config ["type" ]]
166167
167168 # timeago output is dynamic, which breaks when you print a page
@@ -170,8 +171,13 @@ def on_page_markdown(
170171 if self .config ["type" ] == "timeago" :
171172 revision_date += revision_dates ["iso_date" ]
172173
173- # Add to page meta information
174+ # Add to page meta information, for developers
175+ # Include variants without the CSS <span> elements (raw date strings)
174176 page .meta ["git_revision_date_localized" ] = revision_date
177+ revision_dates_raw = self .util .get_date_formats_for_timestamp (last_revision_timestamp , add_spans = False )
178+ for date_type , date_string in revision_dates_raw .items ():
179+ page .meta ["git_revision_date_localized_raw_%s" % date_type ] = date_string
180+
175181 # Replace any occurances in markdown page
176182 markdown = re .sub (
177183 r"\{\{\s*git_revision_date_localized\s*\}\}" ,
@@ -180,54 +186,41 @@ def on_page_markdown(
180186 flags = re .IGNORECASE ,
181187 )
182188
183- # Creation date
184- if self .config .get ("enable_creation_date" ):
185- creation_dates = self .util .get_date_formats_for_timestamp (
186- commit_timestamp = self .util .get_git_commit_timestamp (
187- path = page .file .abs_src_path ,
188- is_first_commit = True ,
189- )
190- )
191- creation_date = creation_dates [self .config ["type" ]]
192-
193- # timeago output is dynamic, which breaks when you print a page
194- # This ensures fallback to type "iso_date"
195- # controlled via CSS (see on_post_build() event)
196- if self .config ["type" ] == "timeago" :
197- creation_date += creation_dates ["iso_date" ]
198-
199- page .meta ["git_creation_date_localized" ] = creation_date
200- markdown = re .sub (
201- r"\{\{\s*git_creation_date_localized\s*\}\}" ,
202- creation_date ,
203- markdown ,
204- flags = re .IGNORECASE ,
205- )
206-
207- # Developers might want access to the raw date strings
208- # Let's expose them also
209- revision_dates = self .util ._date_formats (
210- unix_timestamp = self .util .get_git_commit_timestamp (
211- path = page .file .abs_src_path ,
212- is_first_commit = False ,
213- ),
214- time_zone = self .config .get ("time_zone" ),
215- locale = self .config .get ("locale" )
189+ # If creation date not enabled, return markdown
190+ # This is for speed: prevents another `git log` operation each file
191+ if not self .config .get ("enable_creation_date" ):
192+ return markdown
193+
194+ # Retrieve git commit timestamp
195+ first_revision_timestamp = self .util .get_git_commit_timestamp (
196+ path = page .file .abs_src_path ,
197+ is_first_commit = True ,
216198 )
217- for date_type , date_string in revision_dates .items ():
218- page .meta ["git_revision_date_localized_raw_%s" % date_type ] = date_string
219199
220- if self .config .get ("enable_creation_date" ):
221- creation_dates = self .util ._date_formats (
222- unix_timestamp = self .util .get_git_commit_timestamp (
223- path = page .file .abs_src_path ,
224- is_first_commit = False ,
225- ),
226- time_zone = self .config .get ("time_zone" ),
227- locale = self .config .get ("locale" )
228- )
229- for date_type , date_string in creation_dates .items ():
230- page .meta ["git_creation_date_localized_raw_%s" % date_type ] = date_string
200+ # Creation date formats
201+ creation_dates = self .util .get_date_formats_for_timestamp (first_revision_timestamp )
202+ creation_date = creation_dates [self .config ["type" ]]
203+
204+ # timeago output is dynamic, which breaks when you print a page
205+ # This ensures fallback to type "iso_date"
206+ # controlled via CSS (see on_post_build() event)
207+ if self .config ["type" ] == "timeago" :
208+ creation_date += creation_dates ["iso_date" ]
209+
210+ # Add to page meta information, for developers
211+ # Include variants without the CSS <span> elements (raw date strings)
212+ page .meta ["git_creation_date_localized" ] = creation_date
213+ creation_dates_raw = self .util .get_date_formats_for_timestamp (first_revision_timestamp , add_spans = False )
214+ for date_type , date_string in creation_dates_raw .items ():
215+ page .meta ["git_creation_date_localized_raw_%s" % date_type ] = date_string
216+
217+ # Replace any occurances in markdown page
218+ markdown = re .sub (
219+ r"\{\{\s*git_creation_date_localized\s*\}\}" ,
220+ creation_date ,
221+ markdown ,
222+ flags = re .IGNORECASE ,
223+ )
231224
232225 return markdown
233226
0 commit comments