Jekyll 中的类别和标签有什么区别?

发布于 2024-12-23 07:52:49 字数 82 浏览 2 评论 0原文

它们的元素都可以通过for..in来访问,并且添加类别和标签的方式是相同的。那么,Jekyll 中的类别和标签有什么区别呢?

Both of their elements can be accessed by for..in, and the way of adding categories and tags are the same. So, what's the difference between categories and tags in Jekyll?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沒落の蓅哖 2024-12-30 07:52:49

在我看来,唯一重要的区别是类别可以在帖子 url 中使用 - 默认情况下,“啤酒”和“食品”类别内的帖子将具有以下网址:

/food/beer/2008/09/09/foo-bar.html

而不是这个:

/2008/09/09/foo-bar.html

查看帖子测试以了解详细信息

标签对网址没有影响,至少根据给他们测试

It seems to me that the only important difference is that categories can be used in the post url - a post inside the "beer" and "food" categories, by default, will have this url:

/food/beer/2008/09/09/foo-bar.html

Instead of this one:

/2008/09/09/foo-bar.html

See the post tests for details

Tags have no influence in the urls, at least according to their tests.

蓝眼泪 2024-12-30 07:52:49

来自文档

  • 不要将帖子放在文件夹中,您可以指定帖子所属的一个或多个类别。当网站生成时,帖子将表现得就像正常设置了这些类别一样。类别(复数键)可以指定为 YAML 列表或空格分隔的字符串。

  • 与类别类似,可以向帖子添加一个或多个标签。与类别一样,标签可以指定为 YAML 列表或空格分隔的字符串。

这仅仅表明了相似之处;它并没有真正解释类别和标签之间的差异。 此视频教程建议:

两者之间的唯一区别是类别可以反映在您帖子的永久链接中。

它继续解释说

它们本质上也可以是分层的,但这意味着,例如,如果你想出了一个食物类别,你可以想出一个纸杯蛋糕类别,这是食物的一个子类别。另一方面,标签是扁平的。它们本质上是无等级的

它们本质上

Jekyll 确实没有任何自动方法来根据这些标签和类别生成存档页面或内容页面。

对此类事情的支持将在您正在使用的主题中实现,或者您可以自己实现。

From the documentation:

  • Instead of placing posts inside of folders, you can specify one or more categories that the post belongs to. When the site is generated the post will act as though it had been set with these categories normally. Categories (plural key) can be specified as a YAML list or a space-separated string.

  • Similar to categories, one or multiple tags can be added to a post. Also like categories, tags can be specified as a YAML list or a space-separated string.

That only suggests similarities; it doesn't really explain the differences between categories and tags. This video tutorial suggests that:

the only difference between the two of them is that categories can be reflected in the permalinks of your posts.

It goes on to explain that

they can also be hierarchical in nature, but that means, for example, if you came up with a category of food you could come up with a category of cupcakes, which is sort of a subcategory to food. Tags, on the other hand, are flat. They're non-hierarchical in nature

and that

Jekyll really doesn't have any automated means of generating archive pages or content pages based off of those tags and categories.

Support for that kind of thing would be implemented in the theme you're using or you could do it yourself.

当梦初醒 2024-12-30 07:52:49

v4.2 文档有更新的答案。

类别和标签之间的显着区别在于,帖子的类别可以合并到为帖子生成的 URL 中,而标签则不能。

因此,根据前面的内容是否有 category: classic hollywoodcategories: classic hollywood,上面的示例帖子的 URL 将为 movies /horror/classic%20hollywood/2019/05/21/bride-of-chucky.html 或分别为movies/horror/classic/hollywood/2019/05/21/bride-of-chucky.html

类别和标签均可用于 Liquid 模板,并且可以迭代。

类别和标签都可以在帖子的前言中定义。类别也可以通过帖子的文件路径来定义:

_post 之上的任何目录都将作为类别读入。例如,如果帖子位于路径 movies/horror/_posts/2019-05-21-bride-of-chucky.markdown,则 movieshorror 自动注册为该帖子的类别。

当帖子还具有定义类别的标题时,它们只会添加到现有列表中(如果尚未存在)。

The v4.2 documentation has an updated answer.

The hallmark difference between categories and tags is that categories of a post may be incorporated into the generated URL for the post, while tags cannot be.

Therefore, depending on whether front matter has category: classic hollywood, or categories: classic hollywood, the example post above would have the URL as either movies/horror/classic%20hollywood/2019/05/21/bride-of-chucky.html or movies/horror/classic/hollywood/2019/05/21/bride-of-chucky.html respectively.

Both categories and tags are made available to Liquid templates and can be iterated over.

Both categories and tags can be defined in a post's front matter. Categories can also be defined by a post’s file path:

Any directory above _post will be read-in as a category. For example, if a post is at path movies/horror/_posts/2019-05-21-bride-of-chucky.markdown, then movies and horror are automatically registered as categories for that post.

When the post also has front matter defining categories, they just get added to the existing list if not present already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文