diff --git a/README.md b/README.md index 66c1f34..22a307a 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,9 @@ How To Use: 3. In your config file, change `sitemap: file:` if you want your sitemap to be called something other than sitemap.xml. 4. Change the `sitemap: exclude:` list to exclude any pages that you don't want in the sitemap. 5. Change the `sitemap: include_posts:` list to include any pages that are looping through your posts (e.g. "/index.html", "/notebook/index.md", etc.). This will ensure that right after you make a new post, the last modified date will be updated to reflect the new post. -6. Run Jekyll: `jekyll build` to re-generate your site. -7. A `sitemap.xml` should be included in your _site folder. +6. Set an optional sitemap: change_frequency_default: that will set the change frequency if you haven't specified one in your individual page. +7. Run Jekyll: `jekyll build` to re-generate your site. +8. A `sitemap.xml` should be included in your _site folder. Configuration defaults: diff --git a/sitemap_generator.rb b/sitemap_generator.rb index 3b1278f..6ed0c6c 100644 --- a/sitemap_generator.rb +++ b/sitemap_generator.rb @@ -73,6 +73,7 @@ def generate(site) @config['priority_name'] = sitemap_config['priority_name'] || PRIORITY_NAME @config['exclude'] = sitemap_config['exclude'] || EXCLUDE @config['include_posts'] = sitemap_config['include_posts'] || INCLUDE_POSTS + @config['change_frequency_default'] = sitemap_config['change_frequency_default'].downcase if sitemap_config['change_frequency_default'] sitemap = REXML::Document.new << REXML::XMLDecl.new("1.0", "UTF-8") @@ -126,7 +127,7 @@ def fill_posts(site, urlset) def fill_pages(site, urlset) site.pages.each do |page| if !excluded?(site, page.path_to_source) - if File.exists?(page.path) + if File.exists?(File.join(site.source, page.path)) url = fill_url(site, page) urlset.add_element(url) end @@ -149,9 +150,9 @@ def fill_url(site, page_or_post) - if (page_or_post.data[@config['change_frequency_name']]) + if (page_or_post.data[@config['change_frequency_name']] || @config['change_frequency_default']) change_frequency = - page_or_post.data[@config['change_frequency_name']].downcase + (page_or_post.data[@config['change_frequency_name']] || @config['change_frequency_default']).downcase if (valid_change_frequency?(change_frequency)) changefreq = REXML::Element.new "changefreq" @@ -192,7 +193,7 @@ def fill_location(site, page_or_post) # Returns lastmod REXML::Element or nil def fill_last_modified(site, page_or_post) lastmod = REXML::Element.new "lastmod" - date = File.mtime(page_or_post.path) + date = File.mtime(File.join(site.source, page_or_post.path)) latest_date = find_latest_date(date, site, page_or_post) if @last_modified_post_date == nil