removed sitemap_generator in favor of generate_sitemap plugin
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,133 +0,0 @@ |
| 1 |
-# Jekyll sitemap page generator. |
|
| 2 |
-# http://recursive-design.com/projects/jekyll-plugins/ |
|
| 3 |
-# |
|
| 4 |
-# Version: 0.1.3 (201101061053) |
|
| 5 |
-# |
|
| 6 |
-# Copyright (c) 2010 Dave Perrett, http://recursive-design.com/ |
|
| 7 |
-# Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) |
|
| 8 |
-# |
|
| 9 |
-# A generator that creates a sitemap.xml page for jekyll sites, suitable for submission to |
|
| 10 |
-# google etc. |
|
| 11 |
-# |
|
| 12 |
-# To use it, simply drop this script into the _plugins directory of your Jekyll site. |
|
| 13 |
-# |
|
| 14 |
-# When you compile your jekyll site, this plugin will loop through the list of pages in your |
|
| 15 |
-# site, and generate an entry in sitemap.xml for each one. |
|
| 16 |
- |
|
| 17 |
-require 'pathname' |
|
| 18 |
- |
|
| 19 |
-module Jekyll |
|
| 20 |
- |
|
| 21 |
- |
|
| 22 |
- # Monkey-patch an accessor for a page's containing folder, since |
|
| 23 |
- # we need it to generate the sitemap. |
|
| 24 |
- class Page |
|
| 25 |
- def subfolder |
|
| 26 |
- @dir |
|
| 27 |
- end |
|
| 28 |
- end |
|
| 29 |
- |
|
| 30 |
- |
|
| 31 |
- # Sub-class Jekyll::StaticFile to allow recovery from unimportant exception |
|
| 32 |
- # when writing the sitemap file. |
|
| 33 |
- class StaticSitemapFile < StaticFile |
|
| 34 |
- def write(dest) |
|
| 35 |
- super(dest) rescue ArgumentError |
|
| 36 |
- true |
|
| 37 |
- end |
|
| 38 |
- end |
|
| 39 |
- |
|
| 40 |
- |
|
| 41 |
- # Generates a sitemap.xml file containing URLs of all pages and posts. |
|
| 42 |
- class SitemapGenerator < Generator |
|
| 43 |
- safe true |
|
| 44 |
- priority :low |
|
| 45 |
- |
|
| 46 |
- # Domain that you are generating the sitemap for - update this to match your site. |
|
| 47 |
- |
|
| 48 |
- # Generates the sitemap.xml file. |
|
| 49 |
- # |
|
| 50 |
- # +site+ is the global Site object. |
|
| 51 |
- def generate(site) |
|
| 52 |
- # Create the destination folder if necessary. |
|
| 53 |
- site_folder = site.config['destination'] |
|
| 54 |
- unless File.directory?(site_folder) |
|
| 55 |
- p = Pathname.new(site_folder) |
|
| 56 |
- p.mkdir |
|
| 57 |
- end |
|
| 58 |
- |
|
| 59 |
- # Write the contents of sitemap.xml. |
|
| 60 |
- File.open(File.join(site_folder, 'sitemap.xml'), 'w') do |f| |
|
| 61 |
- f.write(generate_header()) |
|
| 62 |
- f.write(generate_content(site)) |
|
| 63 |
- f.write(generate_footer()) |
|
| 64 |
- f.close |
|
| 65 |
- end |
|
| 66 |
- |
|
| 67 |
- # Add a static file entry for the zip file, otherwise Site::cleanup will remove it. |
|
| 68 |
- site.static_files << Jekyll::StaticSitemapFile.new(site, site.dest, '/', 'sitemap.xml') |
|
| 69 |
- end |
|
| 70 |
- |
|
| 71 |
- private |
|
| 72 |
- |
|
| 73 |
- # Returns the XML header. |
|
| 74 |
- def generate_header |
|
| 75 |
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">" |
|
| 76 |
- end |
|
| 77 |
- |
|
| 78 |
- # Returns a string containing the the XML entries. |
|
| 79 |
- # |
|
| 80 |
- # +site+ is the global Site object. |
|
| 81 |
- def generate_content(site) |
|
| 82 |
- result = '' |
|
| 83 |
- |
|
| 84 |
- base_url = site.config['url'] |
|
| 85 |
- |
|
| 86 |
- # First, try to find any stand-alone pages. |
|
| 87 |
- site.pages.each{ |page|
|
|
| 88 |
- path = page.subfolder + '/' + page.name |
|
| 89 |
- mod_date = File.mtime(site.source + path) |
|
| 90 |
- |
|
| 91 |
- # Remove the trailing 'index.html' if there is one, and just output the folder name. |
|
| 92 |
- if path=~/index.html$/ |
|
| 93 |
- path = path[0..-11] |
|
| 94 |
- end |
|
| 95 |
- |
|
| 96 |
- unless path =~/error/ |
|
| 97 |
- result += entry(base_url, path, mod_date) |
|
| 98 |
- end |
|
| 99 |
- } |
|
| 100 |
- |
|
| 101 |
- # Next, find all the posts. |
|
| 102 |
- posts = site.site_payload['site']['posts'] |
|
| 103 |
- for post in posts do |
|
| 104 |
- result += entry(base_url, post.id, post.date) |
|
| 105 |
- end |
|
| 106 |
- |
|
| 107 |
- result |
|
| 108 |
- end |
|
| 109 |
- |
|
| 110 |
- # Returns the XML footer. |
|
| 111 |
- def generate_footer |
|
| 112 |
- "\n</urlset>" |
|
| 113 |
- end |
|
| 114 |
- |
|
| 115 |
- # Creates an XML entry from the given path and date. |
|
| 116 |
- # |
|
| 117 |
- # +path+ is the URL path to the page. |
|
| 118 |
- # +date+ is the date the file was modified (in the case of regular pages), or published (for blog posts). |
|
| 119 |
- def entry(base_url, path, date) |
|
| 120 |
- # Force extensions to .html from markdown, textile. |
|
| 121 |
- path = path.gsub(/\.(markdown|textile)$/i, '.html') |
|
| 122 |
- " |
|
| 123 |
- <url> |
|
| 124 |
- <loc>#{base_url}#{path}</loc>
|
|
| 125 |
- <lastmod>#{date.strftime("%Y-%m-%d")}</lastmod>
|
|
| 126 |
- </url>" |
|
| 127 |
- end |
|
| 128 |
- |
|
| 129 |
- end |
|
| 130 |
- |
|
| 131 |
-end |
|
| 132 |
- |
|
| 133 |
- |
| ... | ... |
@@ -1,46 +1,45 @@ |
| 1 | 1 |
# Sitemap.xml Generator is a Jekyll plugin that generates a sitemap.xml file by |
| 2 | 2 |
# traversing all of the available posts and pages. |
| 3 |
-# |
|
| 3 |
+# |
|
| 4 | 4 |
# How To Use: |
| 5 |
-# 1.) Copy source file into your _plugins folder within your Jekyll project. |
|
| 6 |
-# 2.) Change MY_URL to reflect your domain name. |
|
| 7 |
-# 3.) Change SITEMAP_FILE_NAME if you want your sitemap to be called something |
|
| 8 |
-# other than sitemap.xml. |
|
| 9 |
-# 4.) Change the PAGES_INCLUDE_POSTS list to include any pages that are looping |
|
| 10 |
-# through your posts (e.g. "index.html", "archive.html", etc.). This will |
|
| 11 |
-# ensure that right after you make a new post, the last modified date will |
|
| 12 |
-# be updated to reflect the new post. |
|
| 13 |
-# 5.) Run Jekyll: jekyll --server to re-generate your site. |
|
| 14 |
-# 6.) A sitemap.xml should be included in your _site folder. |
|
| 5 |
+# 1) Copy source file into your _plugins folder within your Jekyll project. |
|
| 6 |
+# 2) Change modify the url variable in _config.yml to reflect your domain name. |
|
| 7 |
+# 3) Run Jekyll: jekyll --server to re-generate your site. |
|
| 15 | 8 |
# |
| 16 |
-# Customizations: |
|
| 17 |
-# 1.) If there are any files you don't want included in the sitemap, add them |
|
| 18 |
-# to the EXCLUDED_FILES list. The name should match the name of the source |
|
| 19 |
-# file. |
|
| 20 |
-# 2.) If you want to include the optional changefreq and priority attributes, |
|
| 21 |
-# simply include custom variables in the YAML Front Matter of that file. |
|
| 22 |
-# The names of these custom variables are defined below in the |
|
| 23 |
-# CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME and PRIORITY_CUSTOM_VARIABLE_NAME |
|
| 24 |
-# constants. |
|
| 9 |
+# Variables: |
|
| 10 |
+# * Change SITEMAP_FILE_NAME if you want your sitemap to be called something |
|
| 11 |
+# other than sitemap.xml. |
|
| 12 |
+# * Change the PAGES_INCLUDE_POSTS list to include any pages that are looping |
|
| 13 |
+# through your posts (e.g. "index.html", "archive.html", etc.). This will |
|
| 14 |
+# ensure that right after you make a new post, the last modified date will |
|
| 15 |
+# be updated to reflect the new post. |
|
| 16 |
+# * A sitemap.xml should be included in your _site folder. |
|
| 17 |
+# * If there are any files you don't want included in the sitemap, add them |
|
| 18 |
+# to the EXCLUDED_FILES list. The name should match the name of the source |
|
| 19 |
+# file. |
|
| 20 |
+# * If you want to include the optional changefreq and priority attributes, |
|
| 21 |
+# simply include custom variables in the YAML Front Matter of that file. |
|
| 22 |
+# The names of these custom variables are defined below in the |
|
| 23 |
+# CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME and PRIORITY_CUSTOM_VARIABLE_NAME |
|
| 24 |
+# constants. |
|
| 25 | 25 |
# |
| 26 | 26 |
# Notes: |
| 27 |
-# 1.) The last modified date is determined by the latest from the following: |
|
| 28 |
-# system modified date of the page or post, system modified date of |
|
| 29 |
-# included layout, system modified date of included layout within that |
|
| 30 |
-# layout, ... |
|
| 31 |
-# |
|
| 27 |
+# * The last modified date is determined by the latest from the following: |
|
| 28 |
+# system modified date of the page or post, system modified date of |
|
| 29 |
+# included layout, system modified date of included layout within that |
|
| 30 |
+# layout, ... |
|
| 31 |
+# |
|
| 32 | 32 |
# Author: Michael Levin |
| 33 | 33 |
# Site: http://www.kinnetica.com |
| 34 | 34 |
# Distributed Under A Creative Commons License |
| 35 | 35 |
# - http://creativecommons.org/licenses/by/3.0/ |
| 36 |
- |
|
| 36 |
+# |
|
| 37 |
+# Modified for Octopress by John W. Long |
|
| 38 |
+# |
|
| 37 | 39 |
require 'rexml/document' |
| 38 | 40 |
|
| 39 | 41 |
module Jekyll |
| 40 | 42 |
|
| 41 |
- # Change MY_URL to reflect the site you are using |
|
| 42 |
- MY_URL = "http://www.mysite.com" |
|
| 43 |
- |
|
| 44 | 43 |
# Change SITEMAP_FILE_NAME if you would like your sitemap file |
| 45 | 44 |
# to be called something else |
| 46 | 45 |
SITEMAP_FILE_NAME = "sitemap.xml" |
| ... | ... |
@@ -66,7 +65,7 @@ module Jekyll |
| 66 | 66 |
end |
| 67 | 67 |
|
| 68 | 68 |
def location_on_server |
| 69 |
- "#{MY_URL}#{url}"
|
|
| 69 |
+ "#{site.config['url']}#{url}"
|
|
| 70 | 70 |
end |
| 71 | 71 |
end |
| 72 | 72 |
|
| ... | ... |
@@ -78,7 +77,7 @@ module Jekyll |
| 78 | 78 |
end |
| 79 | 79 |
|
| 80 | 80 |
def location_on_server |
| 81 |
- location = "#{MY_URL}#{@dir}#{url}"
|
|
| 81 |
+ location = "#{site.config['url']}#{@dir}#{url}"
|
|
| 82 | 82 |
location.gsub(/index.html$/, "") |
| 83 | 83 |
end |
| 84 | 84 |
end |