From 9331743590a392a88b254911e871bbd6f8619be0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Sko=C5=99epa?= <jakub@skorepa.info>
Date: Tue, 29 Mar 2016 00:58:42 +0200
Subject: [PATCH] Fix few links

and add few command line options

use ./index.js --help to learn more
---
 sitegin/config.js                       |  6 ++++--
 sitegin/markdown.js                     | 16 ++++++++++++++++
 theme/templates/partials/base.html.nunj |  2 +-
 upload                                  |  2 +-
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/sitegin/config.js b/sitegin/config.js
index ebc1e18a..9b749c17 100644
--- a/sitegin/config.js
+++ b/sitegin/config.js
@@ -9,13 +9,15 @@ var cli = require('cli');
 var options = cli.parse({
  noserver: ['n', 'Dont run server'],
  port: ['p', 'Port on which server should run', 'number', 1337],
- uiport: [null, 'BrowserSync UI port', 'number', 'port+1']
+ uiport: [null, 'BrowserSync UI port', 'number', 'port+1'],
+ httpsonly: [null, 'Converts all http://ok1kvk.cz links to https'],
+ httponly: [null, 'Converts all https://ok1kvk.cz links to http']
 });
 
 module.exports = function() {
   var builddir = 'build';
   if(!options.noserver) builddir = 'build-debug';
-  
+
   if(options.uiport == 'port+1') {
     options.uiport = options.port+1;
   }
diff --git a/sitegin/markdown.js b/sitegin/markdown.js
index 11c1e199..041d39d6 100644
--- a/sitegin/markdown.js
+++ b/sitegin/markdown.js
@@ -30,6 +30,8 @@ renderer.paragraph = function(text) {
   else return '<p>'+text+'</p>\n';
 }
 
+renderer._link = renderer.link;
+
 marked.setOptions({
   renderer: renderer,
   gfm: true,
@@ -42,6 +44,20 @@ marked.setOptions({
 });
 
 module.exports = function(obj) {
+  var options = obj.config.options;
+  renderer.link = function(href, title, text) {
+    if(options.httponly) {
+      if(href.match(/^https:\/\/ok1kvk.cz/))
+        href = href.replace('https://', 'http://');
+    }
+    if(options.httpsonly) {
+      if(href.match(/^http:\/\/ok1kvk.cz/))
+        href = href.replace('http://', 'https://');
+    }
+
+    return renderer._link(href,title,text);
+  };
+
   obj.pages.forEach(function(article) {
     renderer.image = function(href, title, text) {
       href = href.split(path.sep).join('/');
diff --git a/theme/templates/partials/base.html.nunj b/theme/templates/partials/base.html.nunj
index e11671b3..1c4a45c9 100644
--- a/theme/templates/partials/base.html.nunj
+++ b/theme/templates/partials/base.html.nunj
@@ -148,7 +148,7 @@
     <footer class="page-footer blue">
         <div class="container s6">
           <a class="orange-text text-lighten-3" target="_blank" href="https://git.ok1kvk.cz/">Gitlab</a> |
-          <a class="orange-text text-lighten-3" target="_blank" href="https://forum.ok1kvk.cz/">FĂłrum</a> |
+          <a class="orange-text text-lighten-3" target="_blank" href="http://forum.ok1kvk.cz/">FĂłrum</a> |
           <a class="orange-text text-lighten-3" href="/clanek/webkamera/">Webkamera</a> |
           <a class="orange-text text-lighten-3" href="/clanek/jak-nahlasit-chybu/">Jak nahlásit chybu</a>
           {% block footerlink %}
diff --git a/upload b/upload
index c047766b..2e15a9df 100755
--- a/upload
+++ b/upload
@@ -12,4 +12,4 @@ echo "Site compiled"
 chmod a+X build -R
 
 echo "Uploading to nove.ok1kvk.cz"
-lftp -c "set ftp:ssl-allow no; open --user ok1kvk.cz-nove --env-password ftp://ok1kvk.cz/; mirror -c --verbose=9 -e -R -L ./build /"
+lftp -c "set ftp:ssl-allow no; open --user ok1kvk.cz-www-nove --env-password ftp://ok1kvk.cz/; mirror -c --verbose=9 -e -R -L ./build /"
-- 
GitLab