[英]Jekyll Github pages how to hide a post
I am using jekyll with Github pages for my website.我在我的网站上使用 jekyll 和 Github 页面。 I am trying to make some posts not visible in the home but they can be linked from another post.
我试图让一些帖子在家中不可见,但可以从另一个帖子链接。 In the frontmatter I tryed to add a field visible like this:
在 frontmatter 中,我尝试添加一个可见的字段,如下所示:
---
layout: post
title:
excerpt:
visible:1
---
And then in the index.html file I did a if check:然后在 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>
The idea is that when I set 0 in the visible field, the post won't be visible in the home.这个想法是,当我在可见字段中设置 0 时,帖子在家里将不可见。 Unfortanely this is not working, do you have any hints?
不幸的是,这不起作用,你有什么提示吗? Thanks
谢谢
This works for me: 这对我有用:
---
layout: post
title: About Lumen
published: false
---
See [About]({{ site.baseurl }}/about)
Try to change your front-matter from visible:1
to visible: 1
. 尝试将您的前题从
visible:1
更改为visible: 1
。
I just tried to reproduce your example on my machine, and I found that Jekyll seems to picky about the blanks in the front-matter. 我只是想在我的机器上重现您的示例,但我发现Jekyll似乎对前端的空白很挑剔。
With visible: 1
, your example works for me. visible: 1
,您的示例对我有用。
With visible:1
, Jekyll outputs the following error message while building the site: 使用
visible:1
,Jekyll在构建站点时输出以下错误消息:
YAML Exception reading C:/foo/bar.md: (): could not find expected ':' while scanning a simple key at line 5 column 1
YAML异常读取C:/foo/bar.md:():在第5行第1列扫描简单键时找不到预期的':'
...but it still finishes building and the generated site works, except that the post is not visible. ...但是它仍然可以完成构建并且生成的站点可以正常运行,但该帖子不可见。
If you want to exclude a post/page from pagination you can add hidden: true
to the YAML frontmatter. 如果要从分页中排除帖子/页面,可以在YAML前题中添加
hidden: true
。 https://github.com/jekyll/jekyll-paginate/issues/6 https://github.com/jekyll/jekyll-paginate/issues/6
You need to modify the _layout/home.html
file (In your case, it might be the index.html
file).您需要修改
_layout/home.html
文件(在您的情况下,它可能是index.html
文件)。
Try to use an if-endif
statement,like this:尝试使用
if-endif
语句,如下所示:
{%- for post in site.posts -%}
{% if post.hide == null or post.hide == false %}
<li>
{%- assign date_format = site.minima.date_format | default: "%b %-d, %Y" -%}
<span class="post-meta">{{ post.date | date: date_format }}</span>
<h3>
<a class="post-link" href="{{ post.url | relative_url }}">
{{ post.title | escape }}
</a>
</h3>
</li>
{% endif %}
{%- endfor -%}
Then, hiding a post by hide: true
.然后,通过
hide: true
隐藏帖子。 For example:例如:
published: true
title: Some title
layout: post
hide: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.