# encoding: utf-8 require 'fileutils' require 'xml-sitemap' require 'easy_html_generator/generator/base' # this generator combines files in the dist folder class EasyHtmlGenerator::Generator::Service::Sitemap < EasyHtmlGenerator::Generator::Base def generate!(config) files = Dir[config.selector] files.map! do |file| file.sub(@project.dist_path, '').sub(@project.name, '') end generate_sitemap(files, config) end def generate_sitemap(files, config) map = XmlSitemap::Map.new(config.domain) do |m| files.each do |file| next if blacklisted?(file, config) m.add file, updated: Date.today, period: :daily end end map.render_to(config.target) end def blacklisted?(file, config) return false if config.blacklist.nil? config.blacklist.any? { |entry| file.include?(entry) } end end