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
206 stars 44 forks source link

timeago is static #6

Closed timvink closed 4 years ago

timvink commented 4 years ago

I optimistically added the type: timeago option, but only now realise this is fixed after building and thus quite static (unless you rebuild your website very regularly..)

Either I should remove the type, or update README to explain how to use timeago.js with mkdocs.

timvink commented 4 years ago

I can implement this without asking the user to configure anything. Rough plan:

When config has type: timeago the {{ git_revision_date_localized }} tag should produce a tag like

<div class="timeago" datetime="2016-06-30 09:20:00"></div>

Then I could use on_page_content to insert some javascript at the bottom of the page before </body>, like

<!-- Get latest version from https://cdnjs.com/libraries/timeago.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.0-beta.2/timeago.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/timeago.js/4.0.0-beta.2/timeago.locales.min.js" type="text/javascript"></script>
<script>
  const nodes = document.querySelectorAll('.timeago');
  timeago.render(nodes, 'nl');
</script>