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

tags and categories are case sensitive #3875

Open
RobotWuYun opened this issue Nov 19, 2019 · 10 comments
Open

tags and categories are case sensitive #3875

RobotWuYun opened this issue Nov 19, 2019 · 10 comments

Comments

@RobotWuYun
Copy link

@RobotWuYun RobotWuYun commented Nov 19, 2019

when I push my blog to github,and open the blog,I find some articles are not as a true number is the page number,and the tag is not like it as tags page
for example:
tags.jpg
articles for tags page.jpg

and

this is my give a method to the problem
the article path

@curbengh

This comment has been minimized.

Copy link
Contributor

@curbengh curbengh commented Nov 27, 2019

return slugize(name, {transform: ctx.config.filename_case});

The slugize() is configured using config.filename_case which defaults to 0, so it shouldn't convert case (meaning it's case sensitive by default).


To clarify, you would like to merge Java and java into one? In your blog, do Java and java have different link?

当你的博客既有大写,如:Java,又有小写,如java,这是Hexo就傻了,他根据标签同时建立了Java和java两个标签

If you prefer the tag to be case insensitive,

_config.yml
filename_case: 1

That should convert all tags to lowercase.

@RobotWuYun

This comment has been minimized.

Copy link
Author

@RobotWuYun RobotWuYun commented Nov 27, 2019

thinks~

@dailyrandomphoto

This comment has been minimized.

Copy link
Contributor

@dailyrandomphoto dailyrandomphoto commented Nov 28, 2019

I have this problem many times too.
Sometimes, I can't remember the case of each tag name used previously. Java? java? or JAVA?
I have to search the tag name to clarify.

hexo list tag

If we use both Java and java, we will have problems as @RobotWuYun met.
Since the file system can't create both /Java/ and /java/ directories, one of them will not accessible.

Exactly we want just one tag, but not both Java and java, and want to write tag name case insensitive.

To solve this problem, I wrote a plugin.
https://github.com/dailyrandomphoto/hexo-easy-tags-plugin

@dailyrandomphoto

This comment has been minimized.

Copy link
Contributor

@dailyrandomphoto dailyrandomphoto commented Nov 28, 2019

@RobotWuYun
You should modify url in _config.yml.

# _config.yml

- url: http://yoursite.com
+ url: https://robotwuyun.github.io

2019112801

@curbengh

This comment has been minimized.

Copy link
Contributor

@curbengh curbengh commented Nov 28, 2019

Since the file system can't create both /Java/ and /java/ directories, one of them will not accessible.

It's possible in case-sensitive file systems.

To solve this problem, I wrote a plugin.
https://github.com/dailyrandomphoto/hexo-easy-tags-plugin

Is the plugin still required if filename_case: 1 is set?

@dailyrandomphoto

This comment has been minimized.

Copy link
Contributor

@dailyrandomphoto dailyrandomphoto commented Nov 29, 2019

Yes, because filename_case: 1 can't solve this problem.

Without this plugin

  • filename_case: 0
    post-a.md
tags:
  - JAVA

=> tag name: JAVA, slug: /JAVA/

post-b.md

tags:
  - java

=> tag name: java, slug: /java/

Only one of /JAVA/ and /java/ will be created on case-insensitive file systems. (Mac, Windows).

  • filename_case: 1
    post-a.md
tags:
  - JAVA

=> tag name: JAVA, slug: /java/

post-b.md

tags:
  - java

=> tag name: java, slug: /java/

Only one of post-a.md and post-b.md will be created under /java/, because JAVA and java are two different tags.

With this plugin

  • filename_case: 0
    post-a.md
tags:
  - JAVA

post-b.md

tags:
  - java

=> Automaticaly corrects java to JAVA, or corrects JAVA to java
tag name: JAVA, slug: /JAVA/

  • filename_case: 1
    post-a.md
tags:
  - JAVA

post-b.md

tags:
  - java

=> Automaticaly corrects java to JAVA, or corrects JAVA to java
tag name: JAVA, slug: /java/

@RobotWuYun

This comment has been minimized.

Copy link
Author

@RobotWuYun RobotWuYun commented Nov 29, 2019

@dailyrandomphoto Thinks for your advice~

@curbengh curbengh changed the title tags and categories are not case sensitive tags and categories are case sensitive Dec 7, 2019
@curbengh

This comment has been minimized.

Copy link
Contributor

@curbengh curbengh commented Dec 7, 2019

@dailyrandomphoto
To clarify, currently filename_case: only applies to post/page filename, but not tag/category?

Looks like tag/category doesn't pass filename_case: option into slugize(). I'll have a check.


filename_case: does get passed to slugize() in tag model.

return slugize(name, {transform: ctx.config.filename_case});

it('slug - filename_case: 1', () => {
hexo.config.filename_case = 1;
return Tag.insert({
name: 'WahAHa'
}).then(data => {
data.slug.should.eql('wahaha');


so the issue is not due to slugize(), but the tag name itself is not transformed.

Drafted a fix #3912.

@curbengh curbengh mentioned this issue Dec 7, 2019
2 of 2 tasks complete
@dailyrandomphoto

This comment has been minimized.

Copy link
Contributor

@dailyrandomphoto dailyrandomphoto commented Dec 9, 2019

IMHO, tag name and category name should not be transformed. (#3912)

  1. Users want to see the tag name and category name the same as what he wrote, just like the title.
  2. For example C/C++ is converted to c-c. Of course this is not what users want.

This issue is due to the user wrote two tag names Java and java in another post.
Therefore, the user does not get the desired result. (The reason is described above #3875 (comment))

You can try to add two posts like these:

  • post1.md
title: About Java
tag:
  - Java
  • post2.md
title: Another post about java
tag:
  - java

and check the /tags/java/ URL.
You will see only one post, whatever filename_case: 0 or filename_case: 1.

@curbengh

This comment has been minimized.

Copy link
Contributor

@curbengh curbengh commented Dec 9, 2019

So, #3912 is not the correct approach.

Another approach I can think of is transform the case (if filename_case: is enabled) when saving to the database (so that they share similar ID), while still retaining the original case. Not sure if this is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.