timvink / mkdocs-git-revision-date-localized-plugin

MkDocs plugin to add a last updated date to your site pages
https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/index.html
MIT License
198 stars 40 forks source link

Custom meta variable for date of publish of article #48

Closed michalzobec closed 3 years ago

michalzobec commented 3 years ago

Hello,

thank you very much for your plugin. is very useful for me and it works.

but I have one little problem, because it automatically generate at end of article information about last update.

I have my custom meta variable PublishedDate like

---
template: overrides/main.html
PublishedDate: 01.12.2020
---

it is possible add of support of this variable from your side? because I would like to avoid editing the template, if is possible.

and if is possible define of possition of update information in article (top/end), it will be great. :)

thank you very much for your help.

timvink commented 3 years ago

Hi @michalzobec. Good to hear it's useful for you!

So if I understand correctly, you would like the revision date to be based off of a page meta variable like PublishedDate, instead of the last git commit on a file?

The date would have to be in ISO8601 format, and the variable name to look for should be configurable in the config.

Could be useful, but not sure if it fits in the scope of the plugin (which is revision-date based on git). I'll think about it, and also wait and see if some users upvote the issue.

michalzobec commented 3 years ago

Hello @timvink

thank you for your fast reply :)

So if I understand correctly, you would like the revision date to be based off of a page meta variable like PublishedDate, instead of the last git commit on a file?

sorry, no. I need use both, your information, and my information (variable).

your plugin inserts information about last update. my variable inserts the date of first publish of same article.

for examle:

Published: <some date here>
Last update: <some date here>

Last update is your information from your plugin. Published is my information from my variable in same article.

Here is real example: https://pomoc2.zobecdev.cz/testpage/

2021-02-28 22_45_09-Test Page - Pomoc a podpora

you will found on begin of page:

Vydáno: 01.12.2020 14:00:00
Změněno: 27. února 2021 22:38:39

It is clear for you now? :)

The date would have to be in ISO8601 format, and the variable name to look for should be configurable in the config.

yes, I understand that. :)

Have nice day.

Michal

timvink commented 3 years ago

Oh I see. The {{ page.meta.git_revision_date_localized }} tag has been embedded into mkdocs-material (see https://github.com/squidfunk/mkdocs-material/blob/master/material/partials/source-date.html), which is why you don't need an override for that one.

Using overrides is the preferred way to go. You can improve your setup by overriding the source-date.html instead of main.html, which will make your customization much more stable (as mkdocs-material's main.html is updated much more frequently, meaning you will have to update your override more often).

michalzobec commented 3 years ago

yeah, but if you add you support for custom meta variable (to your plugin), I do not must use override. and that's why I asked you, for exactly the reasons you're giving. so that I don't have to deal with customizations at all and have problems with upgrades.

timvink commented 3 years ago

Initially to use this plugin's {{ page.meta.git_revision_date_localized }} with mkdocs-material theme, you also needed to use an override. Because so many people use this plugin, I was able to convince the author of mkdocs-material to update his template to include it.

If you want support for your PublishedDate variable inside mkdocs-material, you will have to open an issue in that repository. Overriding partials is the preferred way of extending a theme, and mkdocs-material providing the very specific partials/source-date.html makes it really easy already. But if you can make a strong case in an issue to mkdocs-material perhaps you will be able to convince the author.

michalzobec commented 3 years ago

ahh, okay, thanks :)