Jekyll Github页面如何隐藏帖子

kil*_*ian 13 html post github jekyll github-pages

我在我的网站上使用jekyll和Github页面.我试图在家中看不到一些帖子,但可以从另一个帖子链接.在frontmatter中,我尝试添加一个可见的字段:

---
layout: post
title: 
excerpt: 
visible:1
---
Run Code Online (Sandbox Code Playgroud)

然后在index.html文件中我做了一个if检查:

<div class="posts">
  {% for post in paginator.posts %}
  {% if post.visible== 1  %}

  <div class="post">
    <h1>
      <a href="{{ post.url }}">
        {{ post.title }}
      </a>
    </h1>

    <span class="post-date">{{ post.date | date_to_string }}</span>
        <a class="subtitle" href="{{ post.url }}">
           {{ post.excerpt }}
        </a>
      </a>
  </div>
  {% endif %}
  {% endfor %}
</div>
Run Code Online (Sandbox Code Playgroud)

我的想法是,当我在可见字段中设置0时,帖子将不会在家中显示.不幸的是,这不起作用,你有任何提示吗?谢谢

Hen*_*wan 23

这对我有用:

---
layout: post
title: About Lumen
published: false
---

See [About]({{ site.baseurl }}/about)
Run Code Online (Sandbox Code Playgroud)

  • 将`published`设置为`false`不仅会隐藏帖子,还会使其不可用(即它被排除在网站之外) (10认同)
  • 没有 OP 要求的内容,但我发现它很有用。 (4认同)
  • @zany [显然](http://www.fizerkhan.com/blog/posts/Working-with-upcoming-posts-in-Jekyll.html) 你可以通过运行 ```jekyll server --unpublished 在本地预览帖子```` (2认同)

Chr*_*cht 5

尝试将前面的事情visible:1改为visible: 1.

我只是想在我的机器上重现你的例子,我发现Jekyll似乎对前面的空白很挑剔.

有了visible: 1,你的例子适合我.

使用时visible:1,Jekyll在构建站点时输出以下错误消息:

YAML异常读取C:/foo/bar.md :():在第5行第1列扫描简单键时找不到预期的':'

...但它仍然完成构建并且生成的网站有效,除了帖子不可见.

  • 这不是Jekyll挑剔而是YAML的特异性,请参阅https://en.wikipedia.org/wiki/YAML#Associative_arrays("键与冒号+空格的值分开.") (6认同)

小智 5

如果要从分页中排除帖子/页面,可以将其添加hidden: true到YAML主题中。https://github.com/jekyll/jekyll-paginate/issues/6