Hexo: Support multiple non-hierarchical categories

Created on 19 Sep 2014  ·  15Comments  ·  Source: hexojs/hexo

feature-request

Most helpful comment

There is some progress here. I still need to clean it up, write some more tests, verify generators pick up the new categories, update docs, etc., but I'm excited.

The way it currently works is that, if the post defines categories the current way, they will be rendered the current way. i.e.,

categories:
- this
- is
- cool

would end up with the category this/is/cool. However, if any of the categories are a list themselves, it will create multiple categories. So, if it looks like...

categories:
- [ some, cool ]
- way

...it will end up with two categories - some/cool and way.

This way preserves the default, but allows the flexibility for defining different hierarchies without changing the front matter too much. It would impact importers, if (for example) they want to import from WordPress and preserve its category hierarchy.

_Feel free to provide feedback on this approach; simple is good, but unintended side effects are not._

All 15 comments

现在Hexo应该不支持多级目录吧?

支持多级目录,但是不支持一篇文章多个同级目录,比如:

- HTML
- CSS

就会生成 HTML>CSS 结构的目录,HTML变成了CSS的父级目录,而我原先使用WordPress写的文章很多文章使用了两个目录,结果我从WordPress导入的文章目录列表结果很乱。不知道怎么才能修正好,迟迟没有迁移呢。

@Alex1990 这种需求,还是推荐使用Tags。

@diaocow 正如楼上所说,多级目录可以通过

- HTML
- CSS

实现。

This is a feature request for a post having multiple categories.

@leesei the difference between categories and tags ?
I don't support the idea to add this featur, one way do one thing.
How about your idea?

@Xuanwo Categories can be both hierarchical and non-hierarchical. Tags are not hierarchical.

I was tagging it as a feature request. Not committing to add this feature to Hexo.
Maybe we could rename the label :wink: .

@leesei How about rename it as feature request ?

@leesei I take some time to think this feature request.
Now I support to add multilevel categories whitout same level categories. And I think this way can give categories and tags different meanings and work together well.

For people coming from WordPress this can cause a bit of a headache, since the WP migrator tries mapping back the multi-category selection present in WP to something, creating a completely new and unintentional category structure. An example:

In WP, there are three posts: one in the Personal category, one in the Travel category and the other one in both the Personal and Travel categories. (Those are same level categories.) As the result of the migration, you would end up with the following category structure:

  • Personal
  • Personal > Travel
  • Travel

Note the difference between Personal > Travel and Travel; the post originally with both categories is not going to be available under Travel.

I'm not saying that any way (WP vs. Hexo) is better than the other, but this can be definitely confusing. If someone just wants to convert his existing site to Hexo like I do, one might need to rework all blog posts to clean up the category structure.

(I'm also aware that this might be the WordPress migrator's responsibility to handle.)

I just got caught by this myself. It took me a little while to figure out that I hadn't done anything wrong.

How I expected it to work would be:

  • Category 1
  • Category 2
  • Category 3

    • Subcategory 3.1

produces::

  • Category 1
  • Category 2
  • Category 3 > Subcategory 3.1

Hierarchical categories should have been indented in my opinion. Categories with the same level of indentation should be at the same level.

I'm hoping to dig into this one at some point in the next month. It should be possible to provide a setting in the _config.yml file (maybe flat_categories: true, where false is the default). Ideally, then you could specify a category structure in your post...

categories:
- Category 3
  - Subcategory 3.1

_(I'm not sure if that's valid YAML, but I'll find out soon.)_

If anyone wants to point me to a spot in the code where this determination would be made, feel free. :)

There is some progress here. I still need to clean it up, write some more tests, verify generators pick up the new categories, update docs, etc., but I'm excited.

The way it currently works is that, if the post defines categories the current way, they will be rendered the current way. i.e.,

categories:
- this
- is
- cool

would end up with the category this/is/cool. However, if any of the categories are a list themselves, it will create multiple categories. So, if it looks like...

categories:
- [ some, cool ]
- way

...it will end up with two categories - some/cool and way.

This way preserves the default, but allows the flexibility for defining different hierarchies without changing the front matter too much. It would impact importers, if (for example) they want to import from WordPress and preserve its category hierarchy.

_Feel free to provide feedback on this approach; simple is good, but unintended side effects are not._

Now the feature supported by @danieljsummers . Close the issue.

I agree with this idea by @Xuanwo

the difference between categories and tags ?
I don't support the idea to add this featur, one way do one thing.

Category should be a tree like this, not tag.

Tag is better for non-hierarchical annotation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leoli-dev picture leoli-dev  ·  3Comments

jo4x962k7JL picture jo4x962k7JL  ·  3Comments

Helihua1992 picture Helihua1992  ·  3Comments

mashirozx picture mashirozx  ·  3Comments

hgDendi picture hgDendi  ·  3Comments