dracoblue.net

Generate Sitemap for jekyll-models

If you want to use a sitemap with jekyll, you need to use a plugin like recurser's generate_sitemap.rb.

This works well for static pages and for posts, but won't work out of the box, if you use jekyll-models.

Since I am creating the downloads area of dracoblue.net with jekyll-models, I want to have those downloads in the sitemap.xml, too.

This small patch against generate_sitemap.rb, adds the functionality to render all jekyll-models in the sitemap, too.

diff --git a/_plugins/generate_sitemap.rb b/_plugins/generate_sitemap.rb
index bb683b8..72dfd92 100644
--- a/_plugins/generate_sitemap.rb
+++ b/_plugins/generate_sitemap.rb
@@ -114,6 +114,16 @@ module Jekyll
         result += entry(url, post.date, get_attrs(post), site)
       end

+      for model_name in site.config['jekyll_models'] do
+        models = site.site_payload['site'][model_name]
+        for model in models do
+          url     = model['mdl_type'] + '/' + model['mdl_name']
+          url     = '/' + url unless url =~ /^\//
+          url     = url[0..-11] if url=~/\/index.html$/
+          result += entry(url, model['timestamp'], Hash.new, site)
+        end
+      end
+
       result
     end

To apply the patch: Create a test.patch file and run patch -p0 -i test.patch.

In jekyll by
@ 04 Dec 2013, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About