-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forked Nanoc::Helpers::XMLSitemap to fix the public paths for static …
…items. See issue #50
- Loading branch information
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Nanoc::Helpers | ||
# @see http://nanoc.ws/doc/reference/helpers/#xmlsitemap | ||
module XMLSitemap | ||
include LifePreserver::LinkTo | ||
|
||
# @option params [Array] :items | ||
# @option params [Proc] :rep_select | ||
# | ||
# @return [String] | ||
def xml_sitemap(params = {}) | ||
require 'builder' | ||
|
||
# Extract parameters | ||
items = params.fetch(:items) { @items.reject { |i| i[:is_hidden] } } | ||
select_proc = params.fetch(:rep_select, nil) | ||
|
||
# Create builder | ||
buffer = '' | ||
xml = Builder::XmlMarkup.new(target: buffer, indent: 2) | ||
|
||
# Check for required attributes | ||
if @config[:base_url].nil? | ||
raise 'The Nanoc::Helpers::XMLSitemap helper requires the site configuration to specify the base URL for the site.' | ||
end | ||
|
||
# Build sitemap | ||
xml.instruct! | ||
xml.urlset(xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9') do | ||
# Add item | ||
items.sort_by(&:identifier).each do |item| | ||
reps = item.reps.reject { |r| r.raw_path.nil? } | ||
reps.reject! { |r| !select_proc[r] } if select_proc | ||
reps.sort_by { |r| r.name.to_s }.each do |rep| | ||
xml.url do | ||
xml.loc path_to(rep, global: true) | ||
xml.lastmod item[:mtime].__nanoc_to_iso8601_date unless item[:mtime].nil? | ||
xml.changefreq item[:changefreq] unless item[:changefreq].nil? | ||
xml.priority item[:priority] unless item[:priority].nil? | ||
end | ||
end | ||
end | ||
end | ||
|
||
# Return sitemap | ||
buffer | ||
end | ||
end | ||
end |