首页 文章

杰基尔的帖子没有生成

提问于
浏览
71

我正在尝试向我的Jekyll网站添加一个新帖子,但是当我运行 jekyll serve 时,我无法在生成的页面上看到它 .

没有生成Jekyll帖子的常见原因是什么?

6 回答

  • 172
    • The post is not placed in the _posts directory.

    • The post has incorrect title.帖子应命名为 YEAR-MONTH-DAY-title.MARKUP (注意 MARKUP 扩展名,通常为 .md.markdown

    • The post's date is in the future. 您可以通过在 _config.yml (documentation)中设置 future: true 来使帖子可见

    • The post has published: false in its front matter.将其设置为 true .

    • Headers 包含:字符 . 将其替换为&#58 . 适用于jekyll 3.8.3 (可能还有其他'recent'版本) .

  • 2

    您可以使用 jekyll build --verbose 详细查看构建过程 .

    例如输出:

    Logging at level: debug
    Configuration file: /home/fangxing/fffx.github.io/_config.yml
      Logging at level: debug
             Requiring: jekyll-archives
             Requiring: jekyll-livereload
             Requiring: kramdown
                Source: /home/fangxing/fffx.github.io
           Destination: /home/fangxing/fffx.github.io/_site
     Incremental build: enabled
          Generating... 
           EntryFilter: excluded /Gemfile
           EntryFilter: excluded /Gemfile.lock
               Reading: _posts/2018-01-14-new-post.md
               Reading: _posts/2014-01-01-example-content.md
               Reading: _posts/2014-01-02-introducing-lanyon.md
               Reading: _posts/2017-11-21-welcome-to-jekyll.markdown
               Reading: _posts/2018-01-14-boot-android-on-charge.md
               Reading: _posts/2013-12-31-whats-jekyll.md
              Skipping: _posts/2018-01-14-boot-android-on-charge.md has a future date
            Generating: Jekyll::Archives::Archives finished in 0.000122873 seconds.
            Generating: JekyllFeed::Generator finished in 0.000468846 seconds.
            ...
    

    从日志我发现jeklly跳过 2018-01-14-boot-android-on-charge.md 因为它有一个未来的日期 .

  • 11

    或者它也可以是浏览器缓存,如果您不在_site文件夹中,而是直接在博客的主页上显示帖子列表 .

  • 2

    我已经为我的博客写了表达这些规则的Rspec测试:

    require 'spec_helper'
    require 'yaml'
    
    # Documented at https://jekyllrb.com/news/2017/03/02/jekyll-3-4-1-released/
    post_regex = %r!^(?:.+/)*(\d{2,4}-\d{1,2}-\d{1,2})-(.*)(\.[^.]+)$!
    
    def date_in_front_matter(date)
      return date if date.is_a?(Date)
      return date.to_date if date.is_a?(Time)
      return Date.parse(date) if date.is_a?(String)
    end
    
    describe 'posts' do
      Dir.glob("_posts/*md").each do |file|
        basename = File.basename(file)
    
        context basename do
          front_matter = YAML.load(File.read(file).split(/---/)[1])
    
          it 'filename must match documented post regex' do
            expect(basename).to match post_regex
          end
    
          it 'date in file name same day as date in front matter' do
            date_in_file_name = Date.parse(post_regex.match(basename).captures[0])
            expect(date_in_front_matter(front_matter['date'])).to eq date_in_file_name
          end
    
          it 'title in front matter should not contain a colon' do
            expect(front_matter['title']).to_not match /:/
          end
    
          it 'front matter should not have published: false' do
            expect(front_matter['published']).to_not be false
          end
        end
      end
    end
    

    这可能对其他人有用,因为我因为日期中的拼写错误而失去了很多时间 .

    这些测试以及Rspec配置的其余部分可以在上下文here中看到 .

  • 0

    一个可能的原因是前面指定的 date 不包含时区偏移,在这种情况下,它默认为UTC,而不是您可能期望的本地计算机的时区 . 我浪费了一个小时,直到UTC "caught up"与我当前的当地时区BST .

    我还没有找到明确的答案,但我认为前面的日期必须以UTC给出时区偏移量(如果省略则默认为零) .

    所以 date: 2018-05-03 12:34:27 is in UTC 无论你在世界的哪个地方,都与 _config.yml 中的 timezone 设置无关 .

    所以要小心指定这样的日期时间:

    date: 2018-05-03 12:34:27 +0100
    
  • 1

    我的帖子也没出现错误,在我的名字中我使用了一个点,例如 2017-10-18-test.2.md .
    这是不被接受的,你必须使用 2017-10-18-test2.md .

相关问题