【问题标题】:Jekyll post not generatedJekyll 帖子未生成
【发布时间】:2015-08-17 22:55:32
【问题描述】:

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

Jekyll 帖子无法生成的常见原因有哪些?

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    如果您无法跟踪 --verbose 中的文件,并且该文件被静默忽略,请尝试删除 config.yml 文件中的 collections_dir。这为我解决了这个问题。

    【讨论】:

      【解决方案2】:

      如果您检查了前面的问题,一切看起来都很好,甚至jekyll build --verbose 也没有透露任何内容(在我的情况下,它只是表现得好像文件根本不存在,甚至没有将其列为排除),检查文件的编码。显然,它需要是UTF-8,没有签名。它是UTF-8 BOM(或一些文本编辑器称之为UTF-8 with Signature),然后它将被默默地忽略。更糟糕的是,一些编辑器会将这两种类型都显示为 UTF-8,从而更难发现差异。

      【讨论】:

        【解决方案3】:

        再补充一个原因,当您将文章从_drafts 移动到_post 时,有时需要删除_site 才能重新生成文章。

        就我而言,经常发生_site在重新生成之前不会被完全删除,因此新文章不会出现。

        无论如何rm -rf _sitebundle exec jekyll serve 工作:)

        【讨论】:

          【解决方案4】:

          【讨论】:

          • _config,yml 中的: 之后使用future:true 没有任何空格会导致错误:配置文件:(无效)。 future: true 大部分被使用。
          • 另一个可能的原因是忘记在文件名中添加.markdown 扩展名。我知道这一点,因为我因此浪费了 5 分钟的生命。
          • 非常感谢!刚刚搜索了 30 分钟,为什么我的帖子没有出现,直到我明白有一个日期过滤器......(在 15 分钟内它会“神奇地”工作......)。添加了未来选项,一切都按预期工作。我认为 true 应该是默认值。
          • 我错过了什么。我在这里的帖子标题中有一个冒号,可以吗? raw.githubusercontent.com/alexharv074/alexharv074.github.io/… 这里看起来还可以吗? alexharv074.github.io
          • @AlexHarvey 感谢您的评论!这似乎不再是问题了。我更新了我的答案。
          【解决方案5】:

          我已经为我的博客编写了表达这些规则的 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
          

          这可能对其他人有用,因为我因日期错误等而浪费了很多时间。

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

          【讨论】:

            【解决方案6】:

            您可以使用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,因为它有一个未来的日期。

            【讨论】:

              【解决方案7】:

              一个可能的原因是前面指定的date 不包含时区偏移量,在这种情况下它默认为UTC,而不是您可能期望的本地机器的时区。我为此浪费了一个小时,直到 UTC “赶上”我当前的本地时区 BST。

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

              所以date: 2018-05-03 12:34:27 是UTC,不管你在世界的哪个地方,也不管_config.yml 中的timezone 设置。

              因此请小心指定日期时间,如下所示:

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

              【讨论】:

              • date: 2018-05-03 12:34:27 +01:30 格式似乎也有效。注意额外的冒号。
              • 浪费了 10 分钟才意识到这是问题所在。谢谢!
              【解决方案8】:

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

              【讨论】:

                【解决方案9】:

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

                【讨论】:

                  猜你喜欢
                  • 2012-06-13
                  • 1970-01-01
                  • 1970-01-01
                  • 2017-02-25
                  • 2013-10-21
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2018-09-07
                  相关资源
                  最近更新 更多