Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to display raw_timeago value #81

Closed
Andre601 opened this issue Feb 6, 2022 · 3 comments
Closed

Unable to display raw_timeago value #81

Andre601 opened this issue Feb 6, 2022 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@Andre601
Copy link
Contributor

Andre601 commented Feb 6, 2022

My goal is to display both the last update and creation date as <day>. <month> <year> <h>:<m>:<s> (<relative time>)

For example, a page created on the 13th of June 2021 and last updated on the 18th of January 2022 should display something like this:

Last updated: 18. January 2022 00:00:01 (1 month ago)
Created: 13. June 2021 00:00:01 (7 months ago)

When I however use the {{ page.meta.git_creation_date_localized_raw_timeago }} value, as mentioned by the docs, inside the partial override does this end up in an empty parenthesis (()) being displayed.

I'm not sure if I'm doing anything wrong in particular, so feedback is appreciated.

Here is the current source-file.html override in its entirety:

{% import "partials/language.html" as lang with context %}

<hr />
<div class="md-source-file">
  <small>

    <!-- mkdocs-git-revision-date-localized-plugin -->
    {% if page.meta.git_revision_date_localized %}
      <span class="twemoji">
        {% include ".icons/octicons/pencil-24.svg" %}
      </span>
      {{ lang.t("source.file.date.updated") }}:
      {{ page.meta.git_revision_date_localized_raw_datetime }} ({{ page.meta.git_revision_date_localized_raw_timeago }})
      {% if page.meta.git_creation_date_localized %}
        <br />
        <span class="twemoji">
          {% include ".icons/octicons/checklist-24.svg" %}
        </span>
        {{ lang.t("source.file.date.created") }}:
        {{ page.meta.git_creation_date_localized_raw_datetime }} ({{ page.meta.git_creation_date_localized_raw_timeago }})
      {% endif %}

    <!-- mkdocs-git-revision-date-plugin -->
    {% elif page.meta.revision_date %}
      <span class="twemoji">
        {% include ".icons/octicons/pencil-24.svg" %}
      </span>
      {{ lang.t("source.file.date.updated") }}:
      {{ page.meta.revision_date }}
    {% endif %}
  </small>
</div>
@Andre601
Copy link
Contributor Author

Andre601 commented Feb 6, 2022

Small update.
Looking at the generated HTML source, does it seem like that {{page.meta.git_revision_date_localized_raw_timeago }} and its creation counterpart are replaces with a <span> element having the timeago class applied alongside a datetime and locale setting.
The span itself is completely empty.

@Andre601
Copy link
Contributor Author

Andre601 commented Feb 6, 2022

I found a temporary workaround for this weird situation.

I changed type in the mkdocs.yml to timeago and updated the above lines to {{ page.meta.git_revision_date_localized_raw_datetime }} ({{ page.meta.git_revision_date_localized }})


My personal guess as to why this acts so weird is the fact that the timeago.js isn't added by default, which causes this unwanted behaviour. Maybe a setting to manually enable this in the future would be useful?

@timvink
Copy link
Owner

timvink commented Feb 6, 2022

Hi @Andre601. You figured it out. timeago.js dependency is only added when type: timeago is set. The empty <span> is correct.. the javascript library will populate it.

I will update the documentation with instructions to use extra_javascript in mkdocs.yml.

Thanks for reporting!

@timvink timvink added the documentation Improvements or additions to documentation label Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants