【问题标题】:Jekyll Github pages how to hide a postJekyll Github 页面如何隐藏帖子
【发布时间】:2014-07-19 01:27:04
【问题描述】:

我正在为我的网站使用带有 Github 页面的 jekyll。 我试图让一些帖子在家里看不到,但它们可以从另一个帖子链接。 在 frontmatter 中,我尝试添加一个可见的字段,如下所示:

---
layout: post
title: 
excerpt: 
visible:1
---

然后在 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>

这个想法是,当我在可见字段中设置 0 时,帖子将在主页中不可见。不幸的是,这不起作用,您有什么提示吗?谢谢

【问题讨论】:

  • 正如 shackett 在下面指出的,您可以通过将 hidden: true 添加到您的 YAML frontmatter 来隐藏主页和分页中的帖子。这些帖子仍然可以访问,只是不会显示在您的主页上。

标签: html post github jekyll github-pages


【解决方案1】:

这对我有用:

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

See [About]({{ site.baseurl }}/about)

【讨论】:

  • published 设置为false 不仅会隐藏帖子,还会使其不可用(即从网站中排除)
  • 没有 OP 要求的,但我发现它很有用。
  • @zany Apparently 你可以通过运行jekyll server --unpublished在本地预览帖子
【解决方案2】:

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

【讨论】:

  • 这个功能很棒,因为它允许您从页面中隐藏帖子,除了那些有链接的人。注意:如果您使用 Github Pages,技术人员可以轻松地将其从您的存储库中删除,因此您不应该隐藏您不希望其他人看到的内容。
【解决方案3】:

尝试将您的前端内容从 visible:1 更改为 visible: 1

我刚刚尝试在我的机器上重现你的示例,我发现 Jekyll 似乎对前面的空白很挑剔。

使用visible: 1,您的示例对我有用。

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

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

...但它仍然完成构建并且生成的站点工作,除了帖子不可见。

【讨论】:

【解决方案4】:

您需要修改_layout/home.html 文件(在您的情况下,它可能是index.html 文件)。

尝试使用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 -%}

然后,隐藏hide: true 的帖子。例如:

published: true
title: Some title
layout: post
hide: true

【讨论】:

    猜你喜欢
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 2016-11-17
    • 2017-11-12
    相关资源
    最近更新 更多