Skip to content

Commit f1b2399

Browse files
committed
Wrap date outputs in span element for styling
1 parent fe3e722 commit f1b2399

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _date_formats(
6464
+ loc_revision_date.strftime("%H:%M:%S"),
6565
"iso_date": loc_revision_date.strftime("%Y-%m-%d"),
6666
"iso_datetime": loc_revision_date.strftime("%Y-%m-%d %H:%M:%S"),
67-
"timeago": "<span class='timeago' datetime='%s' locale='%s'></span>"
67+
"timeago": '<span class="timeago" datetime="%s" locale="%s"></span>'
6868
% (loc_revision_date.isoformat(), locale),
6969
}
7070

@@ -132,6 +132,15 @@ def get_revision_date_for_file(
132132
% path
133133
)
134134

135-
return self._date_formats(
135+
date_formats = self._date_formats(
136136
unix_timestamp=unix_timestamp, time_zone=time_zone, locale=locale
137137
)
138+
139+
# Wrap in <span> for styling
140+
for date_type, date_string in date_formats.items():
141+
date_formats[date_type] = (
142+
'<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>'
143+
% (date_type, date_string)
144+
)
145+
146+
return date_formats

tests/test_builds.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def validate_build(testproject_path, plugin_config: dict = {}):
200200
fallback_to_build_date=plugin_config.get("fallback_to_build_date"),
201201
)
202202

203-
searches = [re.search(x, contents) for x in date_formats.values()]
203+
searches = [x in contents for x in date_formats.values()]
204204
assert any(searches), "No correct date formats output was found"
205205

206206

@@ -240,7 +240,7 @@ def test_date_formats():
240240
"datetime": "February 22, 2020 18:52:09",
241241
"iso_date": "2020-02-22",
242242
"iso_datetime": "2020-02-22 18:52:09",
243-
"timeago": "<span class='timeago' datetime='2020-02-22T18:52:09+00:00' locale='en'></span>",
243+
"timeago": '<span class="timeago" datetime="2020-02-22T18:52:09+00:00" locale="en"></span>',
244244
}
245245

246246

@@ -301,7 +301,7 @@ def test_build_material_theme(tmp_path):
301301
# in German because locale is set to 'de'
302302
index_file = testproject_path / "site/index.html"
303303
contents = index_file.read_text(encoding="utf8")
304-
assert re.search(r"Letztes Update\:\s[\w].+", contents)
304+
assert re.search(r"Letztes Update\:\s[<span class].+", contents)
305305

306306

307307
def test_material_theme_locale(tmp_path):
@@ -318,7 +318,7 @@ def test_material_theme_locale(tmp_path):
318318
# The date will be in german though
319319
index_file = testproject_path / "site/index.html"
320320
contents = index_file.read_text(encoding="utf8")
321-
assert re.search(r"Last update\:\s[\w].+", contents)
321+
assert re.search(r"Last update\:\s[<span class].+", contents)
322322

323323

324324
def test_material_theme_no_locale(tmp_path):
@@ -334,7 +334,7 @@ def test_material_theme_no_locale(tmp_path):
334334
# in German because locale is set to 'de'
335335
index_file = testproject_path / "site/index.html"
336336
contents = index_file.read_text(encoding="utf8")
337-
assert re.search(r"Last update\:\s[\w].+", contents)
337+
assert re.search(r"Last update\:\s[<span class].+", contents)
338338

339339

340340
def test_type_timeago(tmp_path):

0 commit comments

Comments
 (0)