Jekyll post not generated

前端 未结 9 1019
星月不相逢
星月不相逢 2020-12-04 14:53

I am trying to add a new post to my Jekyll site, but I cannot see it on the generated pages when I run jekyll serve.

What are some common reasons for a

相关标签:
9条回答
  • 2020-12-04 15:44

    I have written Rspec tests for my blog that express these rules:

    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
    

    This may be of use to others as I was losing a lot of time due to typos in the date etc.

    These tests along with the rest of the Rspec config can be seen in context here.

    0 讨论(0)
  • 2020-12-04 15:44

    Just to add one more reason, when you move an article from _drafts to _post, you sometimes need to delete the _site for the article to be regenerated.

    In my case it often happens that _site will not be entirely deleted before re-generation so the new article won't appear.

    Anyway rm -rf _site and bundle exec jekyll serve works :)

    0 讨论(0)
  • 2020-12-04 15:47

    If you are unable to track the file in --verbose and if the file is silently ignored then try removing collections_dir in the config.yml file. That solved the issue for me.

    0 讨论(0)
提交回复
热议问题