Class: Jekyll::JekyllSitemap

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

Instance Method Summary collapse

Instance Method Details

#destination_pathObject

Destination for sitemap.xml file within the site source directory



30
31
32
# File 'lib/jekyll-sitemap.rb', line 30

def destination_path
  File.expand_path "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_filesObject

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_contentObject



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

Returns:

  • (Boolean)


49
50
51
# File 'lib/jekyll-sitemap.rb', line 49

def sitemap_exists?
  File.exists? File.expand_path "sitemap.xml", @site.source
end

#source_pathObject

Path to sitemap.xml template file



25
26
27
# File 'lib/jekyll-sitemap.rb', line 25

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

#writeObject

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