lektor / lektor-tags

For each tag on your site, build a list of pages with that tag. This can be used for standard tag-based blog navigation.
MIT License
27 stars 6 forks source link

Describe the order tags are sorted in and add tests #11

Closed nixjdm closed 5 years ago

nixjdm commented 6 years ago

Tags are always deduplicated, and alphabetically ordered.

This is not true. They are at least not sorted.

RussellJQA commented 6 years ago

Hi @nixjdm. I think you'd opened this issue as a result of my mentioning that the lektor-tags README.md says "Tags are always deduplicated, and alphabetically ordered". I'd asked how to sort them in my templates\macros\blog.html, and you helpfully told me I could just do the sort like this: {% for t in post.tags | sort %}

I just came across a reason, though, why we might not want tags automatically sorted by lektor-tags. I've been adding some meta tags to my web site (under development) recently. One of them is:

For a blog post tagged via lektor-tags, the tags are just the right thing to use for the keywords list. But according to both https://www.metatags.org/meta_name_keywords and https://www.metatagseo.com/, this meta tag should ideally list keywords in descending order of importance.

Currently: {% for t in post.tags %} orders a blog post's tags in the order they were entered in the post's contents.lr.

That allow a user to choose what order he wants them displayed in blog posts, a blog index page, and/or a 'keywords' meta tag. He can either default to the order the tags were entered in, or sort them.

I now think this current implemtation is the desired behavior.

So, rather than changing lektor-tags to sort the tags, I'd recommend instead removing ", and alphabetically ordered" from the lektor-tags README.me.

And, perhaps, (for newbies like me) underneath the README.md's suggestion to use "{% for t in this.tags -%}" in templates\blog-post.html, mention the option to sort it with "{% for t in this.tags | sort %}". {I used post.tags, instead of this.tags, since I did this in templates\macros\blog.html, rather than templates\blog-post.html.}

Thanks.

nixjdm commented 6 years ago

Thanks @RussellJQA, that makes sense. I rewrote the title of this issue, and I'll close this after rewriting the readme some. Thank you for presenting an argument for keeping the tag sorting the way it is. I didn't realize it's order was consistently the order in which they were created. That's something we could add a test for too, since we're looking at it as a feature now.

RussellJQA commented 6 years ago

You're welcome @nixjdm. Thanks for all of your hard work maintaining Lektor.

nixjdm commented 5 years ago

I changed the Readme by specifying the current order and how to manipulate it with Jinja here https://github.com/nixjdm/lektor-tags/commit/5a7d36dd927c2529678d9105cac5d70e9948d841. I'll make a separate ticket for general testing.