Class: Jekyll::JekyllFeed

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll-feed.rb

Instance Method Summary collapse

Instance Method Details

#destination_pathObject

Destination for feed.xml file within the site source directory



50
51
52
53
54
55
56
# File 'lib/jekyll-feed.rb', line 50

def destination_path
  if @site.respond_to?(:in_dest_dir)
    @site.in_dest_dir("feed.xml")
  else
    Jekyll.sanitized_path(@site.dest, "feed.xml")
  end
end

#feed_contentObject



64
65
66
67
68
69
70
# File 'lib/jekyll-feed.rb', line 64

def feed_content
  site_map = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "feed.xml")
  site_map.content = File.read(source_path).gsub(/\s*\n\s*/, "\n").gsub(/\n{%/, "{%")
  site_map.data["layout"] = nil
  site_map.render(Hash.new, @site.site_payload)
  site_map.output
end

#feed_exists?Boolean

Checks if a feed already exists in the site source

Returns:

  • (Boolean)


73
74
75
76
77
78
79
# File 'lib/jekyll-feed.rb', line 73

def feed_exists?
  if @site.respond_to?(:in_source_dir)
    File.exists? @site.in_source_dir("feed.xml")
  else
    File.exists? Jekyll.sanitized_path(@site.source, "feed.xml")
  end
end

#generate(site) ⇒ Object

Main plugin action, called by Jekyll-core



34
35
36
37
38
39
40
41
42
# File 'lib/jekyll-feed.rb', line 34

def generate(site)
  @site = site
  @site.config["time"]         = Time.new
  unless feed_exists?
    write
    @site.keep_files ||= []
    @site.keep_files << "feed.xml"
  end
end

#source_pathObject

Path to feed.xml template file



45
46
47
# File 'lib/jekyll-feed.rb', line 45

def source_path
  File.expand_path "feed.xml", File.dirname(__FILE__)
end

#writeObject

copy feed template from source to destination



59
60
61
62
# File 'lib/jekyll-feed.rb', line 59

def write
  FileUtils.mkdir_p File.dirname(destination_path)
  File.open(destination_path, 'w') { |f| f.write(feed_content) }
end