在 Jekyll 中隐藏一些帖子,但允许它们的内容包含在其他地方

Hide some posts in Jekyll, but allow their content to be included elsewhere

我正在使用 Jekyll 生成静态网站。我目前使用一些简单的流式语法在他们自己的页面上按类别显示 post:

{%- for post in site.categories.whatever -%}
    {{ post.content }}
{%- endfor -%}

但是,post 仍然是独立生成的(根据 Jekyll 默认值 /category/year/month/day/title.html),我不需要。

如何防止每个 post 生成自己独立的 HTML 页面,同时仍然能够遍历 site.categories 并将它们包含在具有多个 post 的页面中]s?不幸的是,设置 published: false 阻止了 post 被添加到 site.categories,这打破了上面的 for 循环。 permalink: none也没有明显的效果。排除页面(通过 _config.yml 中的 exclude: [xyzzy, plugh, ...])也是一样的。 previous Whosebug answer 建议将永久链接设置为现有页面,但在 Jekyll 3.6.2 中,这只会覆盖该页面。

我目前的技巧是将该类别的永久链接设置为 /.trash,这在上传已发布的网站时很容易被忽略,但似乎应该有更好的方法。

似乎只需将永久链接设置为空字符串(大部分)就可以了!有

defaults:
  - scope:
        path:       category/_posts
    values:
        permalink:  ''

在您的 _config.yml 中,这些帖子中的 none 将具有生成的页面。

不幸的是,这些页面仍然包含在 site.documents 和类似的页面中,但至少它抑制了输出。我遗憾地认为不可能从 site.documents 中排除这些,但在 Liquid 中很容易避免它们。