From b3703f5f471f0d7528c42c87150f77a95a0f0140 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Sko=C5=99epa?= <jakub@skorepa.info>
Date: Sun, 3 Apr 2016 22:11:50 +0200
Subject: [PATCH] Generate sitemap.xml

---
 sitegin/pipeline.js |  1 +
 sitegin/sitegin.js  |  1 +
 sitegin/sitemap.js  | 20 ++++++++++++++++++++
 3 files changed, 22 insertions(+)
 create mode 100644 sitegin/sitemap.js

diff --git a/sitegin/pipeline.js b/sitegin/pipeline.js
index 5c5780d5..b1e249dc 100644
--- a/sitegin/pipeline.js
+++ b/sitegin/pipeline.js
@@ -10,6 +10,7 @@ module.exports = function(jobs) {
     'parseHugo',
     'gitInfo',
     'urls',
+    'sitemap',
     'markdown',
     'tags',
     'theme',
diff --git a/sitegin/sitegin.js b/sitegin/sitegin.js
index 8b7de6a1..be2db354 100644
--- a/sitegin/sitegin.js
+++ b/sitegin/sitegin.js
@@ -16,6 +16,7 @@ module.exports = function(config) {
     ['urls', './urls'],
     ['writeFiles', './writeFiles'],
     ['resetJobs', './resetJobs'],
+    ['sitemap', './sitemap'],
 
     ['pipeline','./pipeline']
   )
diff --git a/sitegin/sitemap.js b/sitegin/sitemap.js
new file mode 100644
index 00000000..af09456d
--- /dev/null
+++ b/sitegin/sitemap.js
@@ -0,0 +1,20 @@
+var fs = require('fs');
+module.exports = function(obj) {
+  return new Promise(function(resolve, reject) {
+    var file = '<?xml version="1.0" encoding="UTF-8"?>\n'+
+      '<urlset\n'+
+      'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"\n'+
+      'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n'+
+      'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n';
+    obj.pages.forEach(function(page) {
+      file += '<url>\n'+
+      '    <loc>https://ok1kvk.cz/'+page.file+'/</loc>\n'+
+      '    <lastmod>'+page.metadata.date.modification.toISOString()+'</lastmod>\n'+
+      '</url>\n'
+    })
+    file += '</urlset>';
+    fs.writeFile(obj.config.builddir+'/sitemap.xml',file,function(){
+      resolve(obj);
+    })
+  });
+}
-- 
GitLab