class Jekyll::JekyllSitemap

Constants

HTML_EXTENSIONS

Public Instance Methods

destination_path() click to toggle source

Destination for sitemap.xml file within the site source directory

# File lib/jekyll-sitemap.rb, line 43
def destination_path
  if @site.respond_to?(:in_dest_dir)
    @site.in_dest_dir("sitemap.xml")
  else
    Jekyll.sanitized_path(@site.dest, "sitemap.xml")
  end
end
generate(site) click to toggle source

Main plugin action, called by Jekyll-core

# File lib/jekyll-sitemap.rb, line 15
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() click to toggle source

Array of all non-jekyll site files with an HTML extension

# File lib/jekyll-sitemap.rb, line 33
def html_files
  @site.static_files.select { |file| HTML_EXTENSIONS.include? file.extname }
end
sitemap_content() click to toggle source
# File lib/jekyll-sitemap.rb, line 57
def sitemap_content
  site_map = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", "sitemap.xml")
  site_map.content = File.read(source_path)
  site_map.data["layout"] = nil
  site_map.render({}, @site.site_payload)
  site_map.output.gsub(/\s{2,}/, "\n")
end
sitemap_exists?() click to toggle source

Checks if a sitemap already exists in the site source

# File lib/jekyll-sitemap.rb, line 66
def sitemap_exists?
  if @site.respond_to?(:in_source_dir)
    File.exists? @site.in_source_dir("sitemap.xml")
  else
    File.exists? Jekyll.sanitized_path(@site.source, "sitemap.xml")
  end
end
source_path() click to toggle source

Path to sitemap.xml template file

# File lib/jekyll-sitemap.rb, line 38
def source_path
  File.expand_path "sitemap.xml", File.dirname(__FILE__)
end
write() click to toggle source

copy sitemap template from source to destination

# File lib/jekyll-sitemap.rb, line 52
def write
  FileUtils.mkdir_p File.dirname(destination_path)
  File.open(destination_path, 'w') { |f| f.write(sitemap_content) }
end