Closed svandragt closed 5 years ago
This is the backtrace when visiting a tagpage: https://gist.github.com/03317edb0f905272a34c225a800a99e0
The problem here is that tags are not case sensitive. If you have a tag called Web, then the tagpage is /tag/Web. However the example template file lowercases the tag name in thje URL which then does not match the dictionary key causing KeyErrors.
Also tags can contain spaces, really it should be properly processed like a slug, then stored and retrieved that way.
@svandragt Just browsing the open issues here, discovered yours, now trying to understand the problem.
Tested the lower case vs. title case thing and I'm seeing that both show up on my tags page, but both lead to a lower case URL, thus only the post(s) tagged with the lower case tag get listed. Are you suggesting these should be two tags? (Wouldn't it make more sense to consolidate them all into one?)
Regarding tags with spaces: are you saying the spaces should get replaced with another character (like a dash or underscore) in the URL, but display normally (with spaces) in posts and on the tags overview page?
Ok, just discovered unmerged PR #3. (:
If your tag is "Apple News" I expected that to change to "apple-news" in the URL. Because I also had "Apple news" in my WordPress export I ended up with two tags because of the case sensitivity, and broken links.
@svandragt I've looked into this more and thought it over and have come to the conclusion that the part of your PR that is about the case of tags might not actually make full sense.
Reason being: people might well want to use tags that contain capital letters (maybe not even for the URLs, but within blog posts), and the variables you modified can actually be individually overridden in configs/tags.ini
(you'd use url_path
there to replace DEFAULT_URL_PATH_EXP
).
Lektor's utils.py
also contains a function called slugify
(used to turn the project name into a slug during quickstart, among other things), which I'm using now to concatenate and lowercase my tag names for my URLs within the code of the lektor-tags
plugin.
What I want to do though, and sadly haven't quite figured out yet, is to display my tags in posts exactly like they were spelled originally (which means I have to keep the tags as-is in templates, but "slugify" the URLs manually), but treat them as the same tag (lower case version) and list all posts containing it/them when looking up the tag page...
The traceback linked earlier is a duplicate of #2, and is fixed.
I agree that we should actually preserve case sensitivity, and not lowercase everything. Upper case letters and spaces are url safe. To change the url_path for tags, the default expression for that can be set in the config/tags.ini file. For example, you could use https://github.com/terminal-labs/lektor-slugify and have url_path = {{ this.parent.url_path }}tag/{{ tag|slug }}, which would alter the path the tag pages are produced at.
I've changed the README to remove the .lower()
that was in numerous places, since doing that in a typical setup would break links to tag pages where that tag has any uppercase letters. https://github.com/nixjdm/lektor-tags/commit/5a7d36dd927c2529678d9105cac5d70e9948d841
On Lektor 2.2 (desktop OSX download) with the setup from the README I can't get tag pages to work, they always display a 404. Not sure what further information you require.
I'm running a default quick start with blog. The macros/ blog_post.html contains after post.body (which renders the link /blog@tag/python in the output html):
Full templates/tags.html:
blog-post.ini has this added: