Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Compability and Fixes for Middleman 4 & 5 #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/middleman-sitemap/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class Sitemap < ::Middleman::Extension
option :gzip, true, 'Whether or not to GZIP the resulting file'
option :hostname, "http://www.example.com", "The hostname for your website"

include Padrino::Helpers

def initialize(app, options_hash={}, &block)
# Call super to build options from the options_hash
super
Expand Down Expand Up @@ -31,7 +33,7 @@ def generate_sitemap
if options.gzip
sitemaps.each do |sitemap|
gzip_file(sitemap)
@builder.say_status :create, "#{sitemap}.gz" if @builder
@builder.thor.say_status :create, "#{sitemap}.gz" if @builder
end
end
end
Expand All @@ -43,12 +45,12 @@ def build_sitemap_index(number_of_sitemaps)
template = Tilt::ERBTemplate.new(File.expand_path(File.join("#{File.dirname(__FILE__)}", "../../templates/sitemapindex.xml.erb")))
sitemap = template.render(self)

outfile = File.join(app.build_dir, "sitemap.xml")
outfile = File.join(app.config.build_dir, "sitemap.xml")
File.open(outfile, 'w') {|f| f.write(sitemap) }

@builder.say_status :create, "#{app.build_dir}/sitemap.xml"
@builder.thor.say_status :create, "#{app.config.build_dir}/sitemap.xml"

return "#{app.build_dir}/sitemap.xml"
return "#{app.config.build_dir}/sitemap.xml"
end

def build_sitemap(name, pages)
Expand All @@ -58,12 +60,12 @@ def build_sitemap(name, pages)
template = Tilt::ERBTemplate.new(templates_path, 0, :trim => '>')
sitemap = template.render(self)

outfile = File.join(app.build_dir, name)
outfile = File.join(app.config.build_dir, name)
File.open(outfile, 'w') {|f| f.write(sitemap) }

@builder.say_status :create, "#{app.build_dir}/#{name}"
@builder.thor.say_status :create, "#{app.config.build_dir}/#{name}"

return "#{app.build_dir}/#{name}"
return "#{app.config.build_dir}/#{name}"
end

def build_multiple_sitemaps(pages)
Expand Down Expand Up @@ -91,14 +93,14 @@ def gzip_file(sitemap)

# Returns a URL with proper HTML entities
def encode(path)
str = path.split("/").map { |f| app.escape_html(f) }.join("/")
str = path.split("/").map { |f| h(f) }.join('/')
return str
end

private

def get_pages
app.sitemap.resources.find_all { |p| p.ext == ".html" && !p.data.ignore }
app.sitemap.resources.to_a.find_all { |p| p.ext == ".html" && !p.data.ignore }
end

end