class BridgetownSitemap::Builder
Constants
- INCLUDED_EXTENSIONS
Public Instance Methods
build()
click to toggle source
# File lib/bridgetown-sitemap/builder.rb, line 9 def build hook :site, :pre_render, priority: :low do |site| unless site.uses_resource? Bridgetown.logger.error "\n\nbridgetown-sitemap only supports the resource content engine" Bridgetown.logger.info "Add `content_engine: 'resource'` to your bridgetown.config.yml\n\n" raise UnsupportedContentEngine end @site = site @site.generated_pages << sitemap unless file_exists?("sitemap.xml") @site.generated_pages << robots unless file_exists?("robots.txt") end end
Private Instance Methods
destination_path(file)
click to toggle source
# File lib/bridgetown-sitemap/builder.rb, line 42 def destination_path(file) @site.in_dest_dir(file) end
file_exists?(file_path)
click to toggle source
Checks if a file already exists in the site source
# File lib/bridgetown-sitemap/builder.rb, line 65 def file_exists?(file_path) pages_and_files.any? { |p| p.relative_path == "/#{file_path}" } end
pages_and_files()
click to toggle source
# File lib/bridgetown-sitemap/builder.rb, line 69 def pages_and_files @pages_and_files ||= @site.collections.pages.resources + @site.static_files end
robots()
click to toggle source
# File lib/bridgetown-sitemap/builder.rb, line 56 def robots robots = Bridgetown::GeneratedPage.new(@site, @site.source, "/", "robots.liquid", from_plugin: true) robots.content = File.read(source_path(robots.name)) robots.data.layout = "none" robots.data.permalink = "/robots.txt" robots end
sitemap()
click to toggle source
# File lib/bridgetown-sitemap/builder.rb, line 46 def sitemap site_map = Bridgetown::GeneratedPage.new(@site, @site.source, "/", "sitemap.erb", from_plugin: true) site_map.content = File.read(source_path(site_map.name)) site_map.data.permalink = "/sitemap.xml" site_map.data.layout = "none" site_map.data.static_files = static_files site_map.data.xsl = file_exists?("sitemap.xsl") site_map end
source_path(file)
click to toggle source
# File lib/bridgetown-sitemap/builder.rb, line 38 def source_path(file) File.expand_path "../#{file}", __dir__ end
static_files()
click to toggle source
Array of all non-bridgetown site files with an HTML extension
# File lib/bridgetown-sitemap/builder.rb, line 34 def static_files @site.static_files.select { |file| INCLUDED_EXTENSIONS.include? file.extname } end