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
210 stars 45 forks source link

Output to top of page? #138

Closed mihaigalos closed 4 months ago

mihaigalos commented 5 months ago

Hi,

Is there any property one can use to output to top of the page? Potentially after the 1st h1?

timvink commented 5 months ago

Hee,

Have a look at the docs for customizing a theme.

mihaigalos commented 4 months ago

Hi Tim,

I've used this maybe naive approach:

cat <<EOF >docs/mkdocs/settings/overrides/content.html
{% if page.meta.source %}
    <div class="source-links">
    {% for filename in page.meta.source %}
        <span class="label label-primary">{{ filename }}</span>
    {% endfor %}
    </div>
{% endif %}

{% if page.meta.git_revision_date_localized %}
    <small>Last update: {{ page.meta.git_revision_date_localized }}</small>
{% endif %}
{% if page.meta.git_created_date_localized %}
    <small>Created: {{ page.meta.git_created_date_localized }}</small>
{% endif %}

{{ page.content }}
EOF

Then referenced it:

 theme:
   name: material
+  custom_dir: docs/mkdocs/settings/overrides

This path seems to be understood by mkdocs serve, but the change dates don't end up towards the top of the page (still at the bottom of it). Could the path be wrong? - I've tried using custom_dir: mkdocs/settings/overrides and I get an error while rebuilding the docs.

timvink commented 4 months ago

Try putting some plain text there, outside of the if blocks. Then you can see if your override works.

See the docs of mkdocs, or mkdocs-material for details on how to create overrides.

Also note that mkdocs-material has built-in support for this plugin, adding it to the bottom for you.

You can open an issue if you encounter a bug specific to this plugin

mihaigalos commented 4 months ago

Hi Tim,

Thanks for the info. I got it running with: docs/mkdocs/settings/overrides/partials/content.html:

{% if "material/tags" in config.plugins and tags %}
  {% include "partials/tags.html" %}
{% endif %}
{% include "partials/actions.html" %}
{% if "\x3ch1" not in page.content %}
  <h1>{{ page.title | d(config.site_name, true)}}</h1>
{% endif %}
-{{ page.content }}
{% include "partials/source-file.html" %}
+{{ page.content }}
{% include "partials/feedback.html" %}
{% include "partials/comments.html" %}