Skip to content

Commit ff73362

Browse files
committed
Add some page.meta tags with raw date strings
1 parent 32ac3c1 commit ff73362

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

docs/howto/override-a-theme.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,21 @@ When writing your own [custom themes](https://www.mkdocs.org/user-guide/custom-t
8787
Last update: {{ page.meta.git_revision_date_localized }}
8888
{% endif %}
8989
```
90+
91+
As a developer you might want access to more raw date formats that also do not have the `<span>` elements. You can also use:
92+
93+
- `page.meta.git_revision_date_localized`
94+
- `page.meta.git_revision_date_localized_raw_date`
95+
- `page.meta.git_revision_date_localized_raw_datetime`
96+
- `page.meta.git_revision_date_localized_raw_iso_date`
97+
- `page.meta.git_revision_date_localized_raw_iso_datetime`
98+
- `page.meta.git_revision_date_localized_raw_timeago`
99+
100+
And if you've enable creation date in the config:
101+
102+
- `page.meta.git_creation_date_localized`
103+
- `page.meta.git_creation_date_localized_raw_date`
104+
- `page.meta.git_creation_date_localized_raw_datetime`
105+
- `page.meta.git_creation_date_localized_raw_iso_date`
106+
- `page.meta.git_creation_date_localized_raw_iso_datetime`
107+
- `page.meta.git_creation_date_localized_raw_timeago`

mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,31 @@ def on_page_markdown(
204204
flags=re.IGNORECASE,
205205
)
206206

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")
216+
)
217+
for date_type, date_string in revision_dates.items():
218+
page.meta["git_revision_date_localized_raw_%s" % date_type] = date_string
219+
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
231+
207232
return markdown
208233

209234
def on_post_build(self, config: Dict[str, Any], **kwargs) -> None:

setup.py

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

1313
setup(
1414
name="mkdocs-git-revision-date-localized-plugin",
15-
version="0.10.0",
15+
version="0.10.1",
1616
description="Mkdocs plugin that enables displaying the localized date of the last git modification of a markdown file.",
1717
long_description=LONG_DESCRIPTION,
1818
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)