解析 Jekyll 的类别
我已经创建了一个基于 Jekyll 引擎的简单博客,但我还需要一个函数才能使事情真正完成。
在 Jekyll 中,帖子的父目录隐式是“标签”或“类别”。因此,如果我要在目录结构下创建帖子,
/computers/scm/git
它最终会有 3 个标签(计算机、scm、git)。
在我的博客中,我创建了几个页面:
/computers/index.html
/computers/scm/index.html
/computers/scm/git/index.html
并且这些页面明确列出了各自类别中的帖子,这样/computers/index.html 显示 /computers、/computers/sc 和 /computers/scm/git 中每个帖子的链接...以及类似的内容。不幸的是,Jekyll 中的类别不是复合的,因此“/computers/scm/index.html”会迭代与“/sandwiches/scm/index.html”相同的帖子集……
现在,我想自动生成一个站点地图列出了所有类别,提供了我创建的所有页面的链接。 Jekyll 包含一个构造“site.categories”,我可以对其进行迭代,它非常适合所有顶级类别。问题是,当“scm”出现时,没有“/scm/index.html” - 它需要是“/computers/scm/index.html”。
我不确定我是否可以修复此行为 - 我可以编写什么类型的扩展来获取分层类别并自动生成列表页面的站点地图?
在我最疯狂的梦想中,我希望能够将帖子标记为 /a/b/c 并将其与标签 /a、/a/b 和 /a/b/c 关联,然后能够生成页面迭代这些帖子集。我需要网站的组织从一般到具体。
我需要尝试不同的静态生成引擎吗?
I have created a simple blog based on the Jekyll engine but I need one more function to make the thing really complete.
In Jekyll, parent directories of posts are implicitly 'labels' or 'categories'. So, if I were to create a post under the directory structure
/computers/scm/git
it would end up having 3 labels (computers, scm, git)
In my blog, I have created a few pages:
/computers/index.html
/computers/scm/index.html
/computers/scm/git/index.html
and these pages explicitly list posts in their respective categories such that /computers/index.html displays links to every post in /computers, /computers/sc and /computers/scm/git ... and likewise on down the road. Unfortunately, categories are not compound in Jekyll and so, "/computers/scm/index.html" iterates over the same set of posts as "/sandwiches/scm/index.html" …
Now, I'd like to automatically generate a sitemap listing all the categories, providing links to all of the pages I've created. Jekyll includes a construct "site.categories" that I can iterate over which works just great for all the top level categories. The problem is that when "scm" comes up, there is no "/scm/index.html" - it needs to be "/computers/scm/index.html".
I'm not sure I can fix this behavior - what type of extensions can I write to get both hierarchical categories and automatically generate a site map to my listing pages?
In my wildest dreams, I'd like to be able to tag a post as /a/b/c and have it associated with labels /a, /a/b and /a/b/c and then be able to generate pages that iterate over exactly these sets of posts. I need the site's organization to drill down from general to specific.
Do I need to try a different static generation engine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要使用 Jekyll 的插件。对于我的博客中的类别支持,我使用这个之一。
如果您是 Github Pages 用户,您必须注意,出于安全原因,GP 不支持插件。为了避免这种情况,您可以使用这篇博客文章中的想法。
作为替代方案,您可以使用基于 Jekyll 的 Octopress。
You need to use Jekyll's plugins. For categories support in my blog I use one of this.
If you are Github Pages user, you must note that GP does not support plugins because of security reasons. To avoid this, you may use ideas from this blog post.
As an alternative, you can use Octopress, which is Jekyll-based.