@@ -112,6 +112,7 @@ def on_post_page(self, output_content: str, **kwargs) -> str:
112
112
if self .config .get ("type" ) != "timeago" :
113
113
return output_content
114
114
115
+ # Insert timeago.js dependencies
115
116
extra_js = """
116
117
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.0-beta.2/timeago.min.js"></script>
117
118
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.0-beta.2/timeago.locales.min.js"></script>
@@ -122,7 +123,23 @@ def on_post_page(self, output_content: str, **kwargs) -> str:
122
123
</script>
123
124
"""
124
125
idx = output_content .index ("</body>" )
125
- return output_content [:idx ] + extra_js + output_content [idx :]
126
+ output_content = output_content [:idx ] + extra_js + output_content [idx :]
127
+
128
+ # timeago output is dynamic, which breaks when you print a page
129
+ # This ensures fallback to type "iso_date"
130
+ extra_css = """
131
+ <style>
132
+ .git-revision-date-localized-plugin-iso_date { display: none }
133
+ @media print {
134
+ .git-revision-date-localized-plugin-iso_date { display: inline }
135
+ .git-revision-date-localized-plugin-timeago { display: none }
136
+ }
137
+ </style>
138
+ """
139
+ idx = output_content .index ("</head>" )
140
+ output_content = output_content [:idx ] + extra_css + output_content [idx :]
141
+
142
+ return output_content
126
143
127
144
def on_page_markdown (
128
145
self , markdown : str , page : Page , config : config_options .Config , files , ** kwargs
@@ -154,6 +171,13 @@ def on_page_markdown(
154
171
fallback_to_build_date = self .config .get ("fallback_to_build_date" ),
155
172
)
156
173
revision_date = revision_dates [self .config ["type" ]]
174
+
175
+ # timeago output is dynamic, which breaks when you print a page
176
+ # This ensures fallback to type "iso_date"
177
+ # controlled via CSS (see on_post_page() event)
178
+ if self .config ["type" ] == "timeago" :
179
+ revision_date += revision_dates ["iso_date" ]
180
+
157
181
page .meta ["git_revision_date_localized" ] = revision_date
158
182
return re .sub (
159
183
r"\{\{\s*[page\.meta\.]*git_revision_date_localized\s*\}\}" ,
0 commit comments