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

Case sensitivity causes confusing archive generation #43

Open
gboone opened this issue Jun 11, 2015 · 7 comments
Open

Case sensitivity causes confusing archive generation #43

gboone opened this issue Jun 11, 2015 · 7 comments

Comments

@gboone
Copy link

gboone commented Jun 11, 2015

The problem: You have both tags "USA" and "usa" and the following jekyll-archives configuration:

jekyll-archives:
  enabled:
    - 'tags'
  layout: tag_index
  permalinks:
    tag: '/tags/:name/'

USA has 4 posts
usa has 1 post

The result:
On the page generated at /tags/usa will include only the 4 posts tagged in caps.

Interim solution:
Users should build a habit of consistent capitalization when tagging.

@parkr
Copy link
Member

parkr commented Nov 24, 2015

@alfredxing, have a minute?

@alfredxing
Copy link
Member

I've been super busy this term so I've barely been able to keep up!
Just added this to my to-do list so I remember.

Reminds me of a previous discussion about whether tags should be case-sensitive or not. What are your thoughts on that?

We can either make tags case-insensitive, or make the generated URLs case-sensitive...

@gboone
Copy link
Author

gboone commented Nov 30, 2015

I'd vote making tags case-insensitive so, in the example above, USA and usa are treated as the same tag with the same url tags/usa/.

@hazzik
Copy link
Contributor

hazzik commented Dec 17, 2015

The real problem, that one of the tag pages will be missed.

@hazzik
Copy link
Contributor

hazzik commented Dec 17, 2015

Same as #24

@ghost
Copy link

ghost commented May 12, 2016

A fix for this is here: fc8af85e/lib/jekyll-archives.rb and fc8af85e/lib/jekyll-archives/archive.rb and an alternate fix is in #82.

Tags and category hashes are sorted by default as a, A so uppercased tags/cats have priority over lowercase. (So they end up overwriting the lowercase versions) Suppose we have 4 posts with 4 different versions of a tag:

- The Tag
- The tag
- the Tag
- the tag

Here's the default output of @site.post_attr_hash('tags')

{"The tag"=>[#<Jekyll::Document _posts/2016-05-09-The-tag.md collection=posts>], "The Tag"=>[#<Jekyll::Document _posts/2016-05-12-the-tag.md collection=posts>, #<Jekyll::Document _posts/2016-05-10-The-Tag.md collection=posts>], "the Tag"=>[#<Jekyll::Document _posts/2016-05-11-the-Tag.md collection=posts>]}

As you can see Jekyll sorts The Tag and the tag into a single array, but puts The tag and the Tag into separate arrays, for a total of three arrays.

However, jekyll-archive doesn't take the sort into account when it uses this hash to build archive pages. Only a single array will be used for the archive page, and the other arrays will be completely dropped. This creates missing posts on archive pages.

So I'm using a method for case-insensitive tag and categories. I borrowed it from the date def block. This code yields the following hash for the previous 4 versions of the tag:

{"The Tag"=>[#<Jekyll::Document _posts/2016-05-12-the-tag.md collection=posts>, #<Jekyll::Document _posts/2016-05-11-the-Tag.md collection=posts>, #<Jekyll::Document _posts/2016-05-10-The-Tag.md collection=posts>, #<Jekyll::Document _posts/2016-05-09-The-tag.md collection=posts>]}

So it works nicely to create case-insensitive tag & category archive page generation.

The generated page titles default to downcased, but you can alter that to uppercase, or capitalized using some lines in _config.yml.

@wsdjeg
Copy link

wsdjeg commented Oct 23, 2019

@alfredxing no please do not make tag case insensitive, it is same as url, by default USA and usa is not a same tag. sometimes we usually use uppercase for long tag abbreviations。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants