mkdocs-git-revision-date-localized-plugin icon indicating copy to clipboard operation
mkdocs-git-revision-date-localized-plugin copied to clipboard

Feature Request: list last updated pages

Open simbo opened this issue 2 years ago • 3 comments

Hi, first of all, thank you very much for this plugin. It's working fine! :)

I am missing a feature which I would see in the scope of this plugin although opinions may differ here.

It would be cool to be able to insert a list of the recently updated and/or created pages to be displayed anywhere - preferably on the index page.

I guess it would do the job, if you could provide such a collection as template vars.

Thanks for your attention,

Simon

simbo avatar Aug 16 '22 14:08 simbo

first of all, thank you very much for this plugin. It's working fine! :)

Thanks!

A list of the last updated pages reminds of an RSS feed. Perhaps mkdocs-rss-plugin would fit your needs also?

Having a list of last updated pages for a given page requires first looping over all the pages. It will take a small performance hit, but I might need to do it anyway to solve #96 also.

Will keep this in mind and leave the issue open for when I do some development work on this plugin again. Not planning to work on this plugin anytime soon though.

timvink avatar Aug 16 '22 15:08 timvink

After getting into mkdocs template vars and some jinja filters I solved this using a template override of main.html.

I simply filter and sort the pages collection before iterating it to a list:

{% extends "base.html" %}
{% block site_nav %}
  {{ super() }}
  {% if page and page.file and page.file.src_path == "index.md" %}
    <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="navigation">
      <div class="md-sidebar__scrollwrap">
        <div class="md-sidebar__inner">
          <nav class="md-nav md-nav--secondary md-nav--integrated" aria-label="Recently updated" data-md-level="0">
            <div class="md-nav__title">Recently updated</div>
            <ul class="md-nav__list" data-md-scrollfix>
              {% for file in (
                  pages
                  | selectattr("page.meta.git_revision_date_localized_raw_iso_datetime")
                  | selectattr("page.meta.git_creation_date_localized_raw_iso_datetime")
                  | sort(attribute="page.title")
                  | sort(attribute="page.meta.git_creation_date_localized_raw_iso_datetime", reverse=true)
                  | sort(attribute="page.meta.git_revision_date_localized_raw_iso_datetime", reverse=true)
                )[:10]
              %}
                <li class="md-nav__item">
                  <a class="md-nav__link" href="{{ file.url }}" style="display:block">
                    {{ file.page.title }}
                    <br/>
                    <small>
                      <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-timeago">
                        <span class="timeago" datetime="{{ file.page.meta.git_revision_date_localized_raw_iso_datetime }}" locale="en"></span>
                      </span>
                    </small>
                  </a>
                </li>
              {% endfor %}
            </ul>
          </nav>
        </div>
      </div>
    </div>
  {% endif %}
{% endblock %}

simbo avatar Aug 16 '22 21:08 simbo

thanks was looking for something like this for my project

mace-w avatar Aug 17 '22 08:08 mace-w

@simbo thanks for sharing very useful! I want to display this information in a separate "Recently Updated" page (RECENT.md). For some reason this messes up the link and inserts "RECENT" into the path. Any suggestions on how to get around this? The below works fine if I use the index.md page.

{% block content %}
  {{ super() }}
  {% if page and page.file and page.file.src_path == "RECENT.md" %}
    <ul class="md-nav__list" data-md-scrollfix>
        {% for file in (
            pages
            | selectattr("page.meta.git_revision_date_localized_raw_iso_datetime")
            | selectattr("page.meta.git_creation_date_localized_raw_iso_datetime")
            | sort(attribute="page.title")
            | sort(attribute="page.meta.git_creation_date_localized_raw_iso_datetime", reverse=true)
            | sort(attribute="page.meta.git_revision_date_localized_raw_iso_datetime", reverse=true)
        )[:10]
        %}
        <li class="md-nav__item">
            <a class="md-nav__link" href="{{ file.url }}" style="display:block">
            {{ file.page.title }}
            <br/>
            <small>
                <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-timeago">
                <span class="timeago" datetime="{{ file.page.meta.git_revision_date_localized_raw_iso_datetime }}" locale="en"></span>
                </span>
            </small>
            </a>
        </li>
        {% endfor %}
    </ul>
  {% endif %}
{% endblock %}

SoumayaMauthoorMOJ avatar Oct 08 '22 23:10 SoumayaMauthoorMOJ

Thanks for the example @simbo . I've updated the docs with your example (of course I've credited you as well), hope you don't mind.

timvink avatar Oct 31 '22 13:10 timvink