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 sitemap.xsl if exists #143

Merged
merged 2 commits into from
Dec 4, 2016
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions lib/jekyll/jekyll-sitemap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class JekyllSitemap < Jekyll::Generator
# Main plugin action, called by Jekyll-core
def generate(site)
@site = site
@site.pages << sitemap unless sitemap_exists?
@site.pages << sitemap unless file_exists?("sitemap.xml")
end

private
Expand Down Expand Up @@ -46,15 +46,16 @@ def sitemap
site_map.content = File.read(source_path).gsub(MINIFY_REGEX, "")
site_map.data["layout"] = nil
site_map.data["static_files"] = static_files.map(&:to_liquid)
site_map.data["xsl"] = file_exists?("sitemap.xsl")
site_map
end

# Checks if a sitemap already exists in the site source
def sitemap_exists?
# Checks if a file already exists in the site source
def file_exists?(file_path)
if @site.respond_to?(:in_source_dir)
File.exist? @site.in_source_dir("sitemap.xml")
File.exist? @site.in_source_dir(file_path)
else
File.exist? Jekyll.sanitized_path(@site.source, "sitemap.xml")
File.exist? Jekyll.sanitized_path(@site.source, file_path)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/sitemap.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
{% if page.xsl %}
<?xml-stylesheet type="text/xsl" href="{{ "/sitemap.xsl" | absolute_url }}"?>
{% endif %}
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for post in site.posts %}{% unless post.sitemap == false %}
<url>
Expand Down