在Github Pages上构建时无效的日期 [英] Invalid date while building on Github Pages

查看:65
本文介绍了在Github Pages上构建时无效的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将更新推送到我的Github Pages站点,但构建失败.不过在本地构建起来还不错.

I pushed an update to my Github Pages site and it fails the build. Locally it builds just fine though.

回购: https://github.com/valeIT/valeIT.github.io/

页面构建失败,并出现以下错误:

The page build failed with the following error:

值"nil"已传递到与日期相关的预期有效的过滤器 日期以/_layouts/post.html或其布局之一显示.欲了解更多 信息,请参阅 https://help.github .com/articles/page-build-failed-date-is-not-a-valid-datetime/.

The value 'nil' was passed to a date-related filter that expects valid dates in /_layouts/post.html or one of its layouts. For more information, see https://help.github.com/articles/page-build-failed-date-is-not-a-valid-datetime/.

有关对Jekyll进行故障排除的信息,请参见:

For information on troubleshooting Jekyll see:

https://help.github.com/articles/troubleshooting-jekyll-builds

我看了看"/_layouts/post.html",但是我对Liquid的了解是非常基础的,看不到任何错误.

I took a look at "/_layouts/post.html", but my knowledge of Liquid is pretty basic and couldn't see anything wrong in it.

post.html的内容:

Content of post.html:

---
---
<!DOCTYPE html>
<html>
  {% include head.html %}
  <body itemscope itemtype="http://schema.org/Article">
    {% include header.html %}
    <main class="content" role="main">
      <article class="post">
        {% if page.image %}
        <div class="article-image">
          <div class="post-image-image" style="background-image: url({% if page.image %}{{ page.image }}{% endif %})">
            Article Image
          </div>
          <div class="post-image-image2" style="background-image: url({% if page.image2 %}{{ page.image2 }}{% endif %})">
            Article Image
          </div>
          <div class="post-meta">
            <h1 class="post-title">{{ page.title }}</h1>
            <div class="cf post-meta-text">
              <div class="author-image" style="background-image: url({{ site.author_image }})">Blog Logo</div>
              <h4 class="author-name" itemprop="author" itemscope itemtype="http://schema.org/Person">{{ site.author }}</h4>
              on
              <time datetime="{{ page.date | date: "%F %R" }}">{{ page.date | date_to_string }}</time>
              <!-- , tagged on {{#foreach tags}}<span class="post-tag-{{slug}}">{{#if @first}}{{else}}, {{/if}}<a href="/tag/{{slug}}">{{name}}</a></span>{{/foreach}} -->
               - {{ page.content | number_of_words }} Words - {{ content | reading_time_as_i }}.
            </div>
            <div style="text-align:center">
              <a href="#topofpage" class="topofpage"><i class="fa fa-angle-down"></i></a>
            </div>
          </div>
        </div>
        {% else %}
        <div class="noarticleimage">
          <div class="post-meta">
            <h1 class="post-title">{{ page.title }}</h1>
            <div class="cf post-meta-text">
              <div class="author-image" style="background-image: url({{ site.author_image }})">Blog Logo</div>
              <h4 class="author-name" itemprop="author" itemscope itemtype="http://schema.org/Person">{{ page.author }}</h4>
              on
              <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date_to_string }}</time>
              <!-- , tagged on {{#foreach tags}}<span class="post-tag-{{slug}}">{{#if @first}}{{else}}, {{/if}}<a href="/tag/{{slug}}">{{name}}</a></span>{{/foreach}} -->
            </div>
          </div>
        </div>
        <br>
        <br>
        <br>
        {% endif %}
        <section class="post-content">
          <div class="post-reading">
            <span class="post-reading-time"></span> read
          </div>
          <a name="topofpage"></a>
          {{content}}
        </section>
        <footer class="post-footer">
          <section class="share">
            {% for social in site.social %}
              {% if social.share_url != null %}
                <a class="icon-{{ social.icon }}" href="{{ social.share_url }}{{ social.share_title }}{{page.title | cgi_escape}}{{ social.share_link }}{{site.url}}{{page.id}}"
                  onclick="window.open(this.href, '{{ social.icon }}-share', 'width=550,height=255');return false;">
                <i class="fa fa-{{ social.icon }}"></i><span class="hidden">{{ social.icon }}</span>
                </a>
              {% endif %}
            {% endfor %}
          </section>
        </footer>
        <div class="bottom-teaser cf">
          <div class="isLeft">
            <h5 class="index-headline featured"><span>Written by</span></h5>
            <section class="author">
              <div class="author-image" style="background-image: url({{site.author_image}})">Blog Logo</div>
              <h4>{{ site.author }}</h4>
              <p class="bio">{{author.bio}}</p>
              <hr>
              <p class="published">Published <time datetime="{{ page.date | date: "%F %R" }}">{{ page.date | date_to_string }}</time></p>
            </section>
          </div>
          {{/post}}
          <div class="isRight">
            <h5 class="index-headline featured"><span>Supported by</span></h5>
            <footer class="site-footer">
               <section class="poweredby"><a href ="{{site.url}}/apps">Check Out My Apps</a></section>
              <a class="subscribe" href="{{ "/feed.xml" | prepend: site.baseurl }}"> <span class="tooltip"> <i class="fa fa-rss"></i> You should subscribe to my feed.</span></a>
              <div class="inner">
                <section class="copyright">All content copyright <a href="{{@blog.url}}/">{{site.author}}</a> &copy; {{ site.time | date: '%Y' }}<br>All rights reserved.</section>
              </div>
            </footer>
          </div>
        </div>
        {%if site.disqus %}
        <div id="disqus_thread"></div>
        <script type="text/javascript">
            /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
            var disqus_shortname = '{{site.disqus}}'; // required: replace example with your forum shortname
            /* * * DON'T EDIT BELOW THIS LINE * * */
            (function() {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
            })();
        </script>
        <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
        {% endif %}
      </article>
    </main>
    <div class="bottom-closer">
      <div class="background-closer-image" {%if site.cover %} style="background-image: url({{ site.cover }})"{% endif %}>
        Image
      </div>
      <div class="inner">
        <h1 class="blog-title">{{ site.title }}</h1>
        <h2 class="blog-description">{{ site.description }}</h2>
        <a href="/" class="btn">Back to Overview</a>
      </div>
    </div>
    {% include javascripts.html %}
  </body>
</html>

有什么主意吗?

推荐答案

失败是因为

值'nil'已传递到与日期相关的过滤器

The value 'nil' was passed to a date-related filter

这意味着在您的帖子布局中,您可能正在使用layout: post处理非帖子内容,例如,一个页面的前题中不包含date值(在---之间的内容顶部).

That means that in your posts layout, you are probably processing non-post content with layout: post, for example, a page that does not contain date value in their front-matter (the content between --- at the top).

然后,像<time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date_to_string }}</time>这样的代码将失败,因为您将''传递给date_to_string过滤器.

Then code like <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date_to_string }}</time> will fail because you are passing '' to date_to_string filter.

您有两个选择:

  • 标识具有错误的layout: post属性的页面并将其更改为layout: page
  • 使您的代码更安全,以便在将日期值发送到过滤器之前检查日期是否为非NIL,例如,使用上面的time标记,首先检查date包含日期:

  • identify the pages with the wrong layout: post attribute and change them to layout: page
  • make your code safer checking if date is non NIL before sending its value to a filter, for example, with the above time tag, check the date contains a date first:

 {% if page.date %}
 <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date_to_string }}</time>
 {% endif %}

此外,当jekyll在本地生成网站时,它会显示很多警告,例如:

Also, when jekyll generates the website locally, it shows a lot of warnings like:

Liquid Warning: Liquid syntax error (line 76): Unexpected character / in "{{/post}}" in /_layouts/post.html
Liquid Warning: Liquid syntax error (line 79): Unexpected character / in "{{!! After all the posts, we have the previous/next pagination links }}" in index.html

您应该删除斜线{{/posts}}{{posts}}以及液体标记内的其他符号,例如@#.

You should remove those slashes {{/posts}} to {{posts}}, and other symbols like @ and # inside liquid tags.

这篇关于在Github Pages上构建时无效的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆