Part of ACREP-32.
authorMike Taylor <mike@indexdata.com>
Fri, 26 Jun 2015 17:25:56 +0000 (18:25 +0100)
committerMike Taylor <mike@indexdata.com>
Fri, 26 Jun 2015 17:25:56 +0000 (18:25 +0100)
Provide new Handlebars helper mkws-best-url, which returns the first
item in a list that matches a regular-expression suggesting that it's
a URL (basically anything that starts with http://, https:// or //).

Also provide mkws-other-urls (not yet tested), which returns all the
other URLs in the list except the first.

src/mkws-handlebars.js

index 2aaba2c..3e8ee6d 100644 (file)
@@ -81,6 +81,31 @@ Handlebars.registerHelper('mkws-first', function(items, options) {
 });
 
 
+var _urlRegexp = /^(https?:)?\/\//;
+Handlebars.registerHelper('mkws-best-url', function(items) {
+  for (var i in items) {
+    var item = items[i]
+    if (item.match(_urlRegexp)) {
+      mkws.warn("'" + item + "' *is* a URL");
+      return item;
+    }
+    mkws.warn("'" + item + "' is not a URL");
+  }
+  return "";
+});
+Handlebars.registerHelper('mkws-other-urls', function(items) {
+  var res = [];
+  for (var i in items) {
+    var item = items[i]
+    if (item.match(_urlRegexp)) {
+      res.push(item);
+    }
+  }
+  return res;
+});
+
+
+
 Handlebars.registerHelper('mkws-commaList', function(items, options) {
   var out = "";