jekyll-archives icon indicating copy to clipboard operation
jekyll-archives copied to clipboard

Remove dashes from archive tags

Open gemfarmer opened this issue 8 years ago • 4 comments

This PR fixes a problem that was causing some tag archives to be non-existent.

What this fixes

Basically, it creates a custom post_attr_hash method that removes dashes from a tag before assigning its value to the hash that site.tags returns. This way there is only one reference that is a valid url when it has dashes and there is no tag conflict.

This is related to https://github.com/jekyll/jekyll-archives/pull/24

Why?

On our site, some dash-delimited tag archives were were inaccessible because they closely resembled tags without dashes in them. For instance, the user-centered design tag was being confused with the user centered design tag. If there was one post with each of the above tags, visiting /tags/user-centered-design/ would bring up the post that was first in the list of site.posts instead of posts associated with both tags.

gemfarmer avatar Nov 09 '16 21:11 gemfarmer

/cc @jekyll/archives

parkr avatar Nov 09 '16 22:11 parkr

I'll have time to review and address the build failures next week.

gemfarmer avatar Nov 10 '16 16:11 gemfarmer

This is an interesting one! 😜 The main issue is: in general, should we merge tags that are actually different, but produce the same slug through Utils.slugify? This would have ramifications also for case sensitivity (#24).

If we want to merge tags (i.e. have /user-centered-design list posts from both tags), we can just call Utils.slugify on each tag (so basically the same as you have done, but using slugify instead of just the gsub for the dash).

If we don't want to merge tags, I'm not sure if all-out removing dashes is the way to go... I can imagine cases where the dash would make a difference in terms of meaning (also, removing the dash in this way would change how it's displayed via {{ page.title }}). In this case, we can write our own slugify function to preserve case and/or spaces (or just not slug at all).

Thoughts, comments, discussion appreciated!

alfredxing avatar Jan 24 '17 22:01 alfredxing

@alfredxing, I don't think I did a great job explaining the issue that we were having, so let me clarify.

Certain tags that differed only by if/when they were dash delimited, user-centered design vs user centered design, for instance, were being merged in certain instances by jekyll archives, and kept as distinct tags in others.

Instances where they were merged:

  • The tag-specific page that jekyll-archives creates. If there was a set of 28 posts with user-centered design and set with 1 post with user centered design, the /tags/user-centered-design/ url would only have one set of tags. :/

Instances where they were made distinct:

  • The generated list of tags that jekyll-archives creates

Dash delimiting all the tags isn't an ideal reasons you stated above:

I'm not sure if all-out removing dashes is the way to go... I can imagine cases where the dash would make a difference in terms of meaning (also, removing the dash in this way would change how it's displayed via {{ page.title }})

But, this seemed to be the only way I could quickly ensure that the tags weren't inconsistently merged. I'm guessing a better approach would be to make sure that any dash delimited tag is a distinct tag in site.tags!

FWIW we have since avoided this entirely simply by making sure that our tags don't overlap. If fixing this bug is a major hassle, maybe we could add documentation encouraging people to be stricter with their configuration. We are using a gem to manage Jekyll front matter that has helped a lot with this.

gemfarmer avatar Mar 31 '17 19:03 gemfarmer