[tags plugin] [mod] sort by date and display date #5913
balansczerni
started this conversation in
Show and tell
Replies: 1 comment
-
Thanks for sharing! ❤️ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What
A simple solution to sort links under tags + (probably not the best) solution to add date next to links.
In my case, I needed to place links in the following order:
Related
tags_pages_compare
Why
For people who don't know how to program at all (like me) and would spend too much time figuring out how to define custom comparison function (also like me).
I'm pasting my step-by-step solution in case it's useful to someone. 🥸
I'm a rookie and there's probably a smarter way to do this.
Code
Structure
Make a file for the sorting function - it may be named differently and be somewhere else, but it will change the path you enter in
mkdocs.yml
.Sorting by date
tagsort.py
Fallback to "9999-99-99" is "a hack" to to display pages without a date at the top/bottom (depending on the value of the
tags_compare_reverse
option - when sorting a list that contains empty values, the sorted() function treats empty values as "smaller" than non-empty values. This means that empty values will be placed at the beginning of the sorted list).mkdocs.yml
Adding date to links
Roaming around with build-in plugins requires following the instructions from Theme development or directly editing the files in your python environment or .overrides 🤪 (this requires addtional attention when upgrading to newer versions).
In that case, you might also love this git
ci.yml
fragment:plugins/tags/plugin.py
In order to display the Polish date (in my case) after each link under the tag, we need to import Babel.
Now we replace the section that renders the link to the page with:
You can mess with Babel with help of:
I probably wouldn't post such simple things if it wasn't for the fact that 1) sometimes there are questions from equally inexperienced people here, 2) such a little digging helps me learn how everything works and maybe it will also help someone in the future.
Kisses!
Beta Was this translation helpful? Give feedback.
All reactions