Skip to content

Commit dcf0e85

Browse files
committed
7 fix edge case for new file not in git
1 parent b8d5cdc commit dcf0e85

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ def get_revision_date_for_file(self, path: str, locale: str = 'en'):
1919
dict: localized date variants
2020
"""
2121

22-
unix_timestamp = int(self.g.log(path, n=1, date='short', format='%at'))
23-
timestamp_in_ms = unix_timestamp * 1000
22+
unix_timestamp = self.g.log(path, n=1, date='short', format='%at')
2423

2524
if not unix_timestamp:
26-
revision_date = datetime.now()
27-
print('WARNING - %s has no git logs, revision date defaulting to today\'s date' % path)
28-
else:
29-
revision_date = datetime.utcfromtimestamp(unix_timestamp)
30-
25+
unix_timestamp = datetime.now().timestamp()
26+
print('WARNING - %s has no git logs, using current timestamp' % path)
27+
28+
unix_timestamp = int(unix_timestamp)
29+
timestamp_in_ms = unix_timestamp * 1000
30+
31+
revision_date = datetime.utcfromtimestamp(unix_timestamp)
32+
3133
return {
3234
'date' : format_date(revision_date, format="long", locale=locale),
3335
'datetime' : format_date(revision_date, format="long", locale=locale) + ' ' +revision_date.strftime("%H:%M:%S"),

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='mkdocs-git-revision-date-localized-plugin',
8-
version='0.4.3',
8+
version='0.4.4',
99
description='Mkdocs plugin that enables displaying the localized date of the last git modification of a markdown file.',
1010
long_description=long_description,
1111
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)