Merge pull request #29 from jlong/edge

removed sitemap_generator in favor of generate_sitemap plugin
This commit is contained in:
Brandon Mathis 2011-06-14 05:05:21 -07:00
commit fea1cc49d9
2 changed files with 30 additions and 164 deletions

View File

@ -1,133 +0,0 @@
# Jekyll sitemap page generator.
# http://recursive-design.com/projects/jekyll-plugins/
#
# Version: 0.1.3 (201101061053)
#
# Copyright (c) 2010 Dave Perrett, http://recursive-design.com/
# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
#
# A generator that creates a sitemap.xml page for jekyll sites, suitable for submission to
# google etc.
#
# To use it, simply drop this script into the _plugins directory of your Jekyll site.
#
# When you compile your jekyll site, this plugin will loop through the list of pages in your
# site, and generate an entry in sitemap.xml for each one.
require 'pathname'
module Jekyll
# Monkey-patch an accessor for a page's containing folder, since
# we need it to generate the sitemap.
class Page
def subfolder
@dir
end
end
# Sub-class Jekyll::StaticFile to allow recovery from unimportant exception
# when writing the sitemap file.
class StaticSitemapFile < StaticFile
def write(dest)
super(dest) rescue ArgumentError
true
end
end
# Generates a sitemap.xml file containing URLs of all pages and posts.
class SitemapGenerator < Generator
safe true
priority :low
# Domain that you are generating the sitemap for - update this to match your site.
# Generates the sitemap.xml file.
#
# +site+ is the global Site object.
def generate(site)
# Create the destination folder if necessary.
site_folder = site.config['destination']
unless File.directory?(site_folder)
p = Pathname.new(site_folder)
p.mkdir
end
# Write the contents of sitemap.xml.
File.open(File.join(site_folder, 'sitemap.xml'), 'w') do |f|
f.write(generate_header())
f.write(generate_content(site))
f.write(generate_footer())
f.close
end
# Add a static file entry for the zip file, otherwise Site::cleanup will remove it.
site.static_files << Jekyll::StaticSitemapFile.new(site, site.dest, '/', 'sitemap.xml')
end
private
# Returns the XML header.
def generate_header
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"
end
# Returns a string containing the the XML entries.
#
# +site+ is the global Site object.
def generate_content(site)
result = ''
base_url = site.config['url']
# First, try to find any stand-alone pages.
site.pages.each{ |page|
path = page.subfolder + '/' + page.name
mod_date = File.mtime(site.source + path)
# Remove the trailing 'index.html' if there is one, and just output the folder name.
if path=~/index.html$/
path = path[0..-11]
end
unless path =~/error/
result += entry(base_url, path, mod_date)
end
}
# Next, find all the posts.
posts = site.site_payload['site']['posts']
for post in posts do
result += entry(base_url, post.id, post.date)
end
result
end
# Returns the XML footer.
def generate_footer
"\n</urlset>"
end
# Creates an XML entry from the given path and date.
#
# +path+ is the URL path to the page.
# +date+ is the date the file was modified (in the case of regular pages), or published (for blog posts).
def entry(base_url, path, date)
# Force extensions to .html from markdown, textile.
path = path.gsub(/\.(markdown|textile)$/i, '.html')
"
<url>
<loc>#{base_url}#{path}</loc>
<lastmod>#{date.strftime("%Y-%m-%d")}</lastmod>
</url>"
end
end
end

View File

@ -2,45 +2,44 @@
# traversing all of the available posts and pages.
#
# How To Use:
# 1.) Copy source file into your _plugins folder within your Jekyll project.
# 2.) Change MY_URL to reflect your domain name.
# 3.) Change SITEMAP_FILE_NAME if you want your sitemap to be called something
# other than sitemap.xml.
# 4.) Change the PAGES_INCLUDE_POSTS list to include any pages that are looping
# through your posts (e.g. "index.html", "archive.html", etc.). This will
# ensure that right after you make a new post, the last modified date will
# be updated to reflect the new post.
# 5.) Run Jekyll: jekyll --server to re-generate your site.
# 6.) A sitemap.xml should be included in your _site folder.
# 1) Copy source file into your _plugins folder within your Jekyll project.
# 2) Change modify the url variable in _config.yml to reflect your domain name.
# 3) Run Jekyll: jekyll --server to re-generate your site.
#
# Customizations:
# 1.) If there are any files you don't want included in the sitemap, add them
# to the EXCLUDED_FILES list. The name should match the name of the source
# file.
# 2.) If you want to include the optional changefreq and priority attributes,
# simply include custom variables in the YAML Front Matter of that file.
# The names of these custom variables are defined below in the
# CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME and PRIORITY_CUSTOM_VARIABLE_NAME
# constants.
# Variables:
# * Change SITEMAP_FILE_NAME if you want your sitemap to be called something
# other than sitemap.xml.
# * Change the PAGES_INCLUDE_POSTS list to include any pages that are looping
# through your posts (e.g. "index.html", "archive.html", etc.). This will
# ensure that right after you make a new post, the last modified date will
# be updated to reflect the new post.
# * A sitemap.xml should be included in your _site folder.
# * If there are any files you don't want included in the sitemap, add them
# to the EXCLUDED_FILES list. The name should match the name of the source
# file.
# * If you want to include the optional changefreq and priority attributes,
# simply include custom variables in the YAML Front Matter of that file.
# The names of these custom variables are defined below in the
# CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME and PRIORITY_CUSTOM_VARIABLE_NAME
# constants.
#
# Notes:
# 1.) The last modified date is determined by the latest from the following:
# system modified date of the page or post, system modified date of
# included layout, system modified date of included layout within that
# layout, ...
# * The last modified date is determined by the latest from the following:
# system modified date of the page or post, system modified date of
# included layout, system modified date of included layout within that
# layout, ...
#
# Author: Michael Levin
# Site: http://www.kinnetica.com
# Distributed Under A Creative Commons License
# - http://creativecommons.org/licenses/by/3.0/
#
# Modified for Octopress by John W. Long
#
require 'rexml/document'
module Jekyll
# Change MY_URL to reflect the site you are using
MY_URL = "http://www.mysite.com"
# Change SITEMAP_FILE_NAME if you would like your sitemap file
# to be called something else
SITEMAP_FILE_NAME = "sitemap.xml"
@ -66,7 +65,7 @@ module Jekyll
end
def location_on_server
"#{MY_URL}#{url}"
"#{site.config['url']}#{url}"
end
end
@ -78,7 +77,7 @@ module Jekyll
end
def location_on_server
location = "#{MY_URL}#{@dir}#{url}"
location = "#{site.config['url']}#{@dir}#{url}"
location.gsub(/index.html$/, "")
end
end