Sha256: 1af87819aaa33e2093e51f8d2c1c067cc14f93067f8c52804021e8016d27db6a
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require 'fileutils' module Jekyll class JekyllSitemap < Jekyll::Generator safe true # Main plugin action, called by Jekyll-core 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 # Array of all non-jekyll site files with an HTML extension def html_files @site.static_files.select { |file| File.extname(file.relative_path) == ".html" } end # Path to sitemap.xml template file def source_path File.expand_path "sitemap.xml", File.dirname(__FILE__) end # Destination for sitemap.xml file within the site source directory def destination_path File.expand_path "sitemap.xml", @site.dest end # copy sitemap template from source to destination def write FileUtils.mkdir_p File.dirname(destination_path) File.open(destination_path, 'w') { |f| f.write(sitemap_content) } end def sitemap_content site_map = Page.new(@site, File.dirname(__FILE__), "", "sitemap.xml") site_map.content = File.read(source_path) site_map.render(@site.layouts, @site.site_payload) site_map.output end # Checks if a sitemap already exists in the site source def sitemap_exists? File.exists? File.expand_path "sitemap.xml", @site.source end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jekyll-sitemap-0.4.0 | lib/jekyll-sitemap.rb |