Class: Jekyll::JekyllSitemap
- Inherits:
-
Generator
- Object
- Generator
- Jekyll::JekyllSitemap
- Defined in:
- lib/jekyll-sitemap.rb
Instance Method Summary collapse
-
#destination_path ⇒ Object
Destination for sitemap.xml file within the site source directory.
-
#generate(site) ⇒ Object
Main plugin action, called by Jekyll-core.
-
#html_files ⇒ Object
Array of all non-jekyll site files with an HTML extension.
- #sitemap_content ⇒ Object
-
#sitemap_exists? ⇒ Boolean
Checks if a sitemap already exists in the site source.
-
#source_path ⇒ Object
Path to sitemap.xml template file.
-
#write ⇒ Object
copy sitemap template from source to destination.
Instance Method Details
#destination_path ⇒ Object
Destination for sitemap.xml file within the site source directory
30 31 32 |
# File 'lib/jekyll-sitemap.rb', line 30 def destination_path File. "sitemap.xml", @site.dest end |
#generate(site) ⇒ Object
Main plugin action, called by Jekyll-core
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jekyll-sitemap.rb', line 8 def generate(site) @site = site @site.config["time"] = Time.new @site.config["html_files"] = html_files.map(&:to_liquid) unless sitemap_exists? write @site.keep_files ||= [] @site.keep_files << "sitemap.xml" end end |
#html_files ⇒ Object
Array of all non-jekyll site files with an HTML extension
20 21 22 |
# File 'lib/jekyll-sitemap.rb', line 20 def html_files @site.static_files.select { |file| File.extname(file.relative_path) == ".html" } end |
#sitemap_content ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/jekyll-sitemap.rb', line 40 def sitemap_content site_map = Page.new(@site, File.dirname(__FILE__), "", "sitemap.xml") site_map.content = File.read(source_path) site_map.data["layout"] = nil site_map.render(Hash.new, @site.site_payload) site_map.output end |
#sitemap_exists? ⇒ Boolean
Checks if a sitemap already exists in the site source
49 50 51 |
# File 'lib/jekyll-sitemap.rb', line 49 def sitemap_exists? File.exists? File. "sitemap.xml", @site.source end |
#source_path ⇒ Object
Path to sitemap.xml template file
25 26 27 |
# File 'lib/jekyll-sitemap.rb', line 25 def source_path File. "sitemap.xml", File.dirname(__FILE__) end |
#write ⇒ Object
copy sitemap template from source to destination
35 36 37 38 |
# File 'lib/jekyll-sitemap.rb', line 35 def write FileUtils.mkdir_p File.dirname(destination_path) File.open(destination_path, 'w') { |f| f.write(sitemap_content) } end |