Class: Jekyll::PostReader

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/readers/post_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ PostReader

Returns a new instance of PostReader.



6
7
8
# File 'lib/jekyll/readers/post_reader.rb', line 6

def initialize(site)
  @site = site
end

Instance Attribute Details

#siteObject (readonly)

Returns the value of attribute site.



5
6
7
# File 'lib/jekyll/readers/post_reader.rb', line 5

def site
  @site
end

#unfiltered_contentObject (readonly)

Returns the value of attribute unfiltered_content.



5
6
7
# File 'lib/jekyll/readers/post_reader.rb', line 5

def unfiltered_content
  @unfiltered_content
end

Instance Method Details

#read_content(dir, magic_dir, matcher) ⇒ Object

Read all the content files from <source>/<dir>/magic_dir

and return them with the type klass.

dir - The String relative path of the directory to read. magic_dir - The String relative directory to <dir>,

looks for content here.

klass - The return type of the content.

Returns klass type of content files



61
62
63
64
65
66
67
68
69
70
# File 'lib/jekyll/readers/post_reader.rb', line 61

def read_content(dir, magic_dir, matcher)
  @site.reader.get_entries(dir, magic_dir).map do |entry|
    next unless entry =~ matcher
    path = @site.in_source_dir(File.join(dir, magic_dir, entry))
    Document.new(path, {
      :site       => @site,
      :collection => @site.posts,
    })
  end.reject(&:nil?)
end

#read_drafts(dir) ⇒ Object

Read all the files in <source>/<dir>/_drafts and create a new Document object with each one.

dir - The String relative path of the directory to read.

Returns nothing.



16
17
18
# File 'lib/jekyll/readers/post_reader.rb', line 16

def read_drafts(dir)
  read_publishable(dir, "_drafts", Document::DATELESS_FILENAME_MATCHER)
end

#read_posts(dir) ⇒ Object

Read all the files in <source>/<dir>/_posts and create a new Document object with each one.

dir - The String relative path of the directory to read.

Returns nothing.



26
27
28
# File 'lib/jekyll/readers/post_reader.rb', line 26

def read_posts(dir)
  read_publishable(dir, "_posts", Document::DATE_FILENAME_MATCHER)
end

#read_publishable(dir, magic_dir, matcher) ⇒ Object

Read all the files in <source>/<dir>/<magic_dir> and create a new Document object with each one insofar as it matches the regexp matcher.

dir - The String relative path of the directory to read.

Returns nothing.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll/readers/post_reader.rb', line 36

def read_publishable(dir, magic_dir, matcher)
  read_content(dir, magic_dir, matcher).tap { |docs| docs.each(&:read) }
    .select do |doc|
      if doc.content.valid_encoding?
        site.publisher.publish?(doc).tap do |will_publish|
          if !will_publish && site.publisher.hidden_in_the_future?(doc)
            Jekyll.logger.debug "Skipping:", "#{doc.relative_path} has a future date"
          end
        end
      else
        Jekyll.logger.debug "Skipping:", "#{doc.relative_path} is not valid UTF-8"
        false
      end
    end
end