-
I want to set automatic outdated warnings for some documents. For example, if an article was last updated a year ago, it will automatically add the document written a long time ago at the beginning of the document, which may contain outdated information. I tried to add logic in overrides/main.html, as follows: {% block content %}
{{ super() }}
{% if page and page.meta.date %}
{% set doc_date = page.meta.date %}
{% set today = "" | as_datetime("%Y-%m-%d") %}
{% set diff_days = (today | date("%s") - doc_date | date("%s")) // 86400 %}
{% if diff_days > 365 %}
<div class="md-typeset">
<div class="md-admonition warning outdated-warning">
<p class="md-admonition__title">
⚠️ Document Outdated Reminder
</p>
<p>
This document was last updated<strong>{doc_date}</strong>({diff_days}} days ago),
May contain outdated information, please refer to the latest documentation for use.
</p>
</div>
</div>
{% endif %}
{% endif %}
{% endblock %} Meanwhile, I add plugin config in the plugins:
- meta But it didn't take effect. Hope someone who knows can give me some guidance, thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I assume you have set the The overrides file should be called I am not sure what you are using the Meta Plugin in this? Do you mean to apply the same revision date to a bunch of files? I would have expected there to be a Finally, AFAIK you cannot execute arbitrary Python code in a Jinja template but are limited to the functions defined in Jinja because of sandboxing. The best approach IMHO would be to calculate the flag whether a page if outdated or not in a MkDocs hook, then use it in the template. |
Beta Was this translation helpful? Give feedback.
-
I've already implemented it here and wrote a small demo, hoping it can help other friends. |
Beta Was this translation helpful? Give feedback.
I've already implemented it here and wrote a small demo, hoping it can help other friends.
Demo: https://github.com/SWHL/DemoMkdocsExpirationRemider