]> git.sven.stormbind.net Git - sven/vym.git/blobdiff - demos/scripts/strip-url.vys
New upstream version 2.9.22
[sven/vym.git] / demos / scripts / strip-url.vys
diff --git a/demos/scripts/strip-url.vys b/demos/scripts/strip-url.vys
new file mode 100644 (file)
index 0000000..ddcaf5f
--- /dev/null
@@ -0,0 +1,50 @@
+// Strip URLs from confluence and generate readable heading
+// by removing path and replacing characters like  "+" 
+
+vym.clearConsole();
+m1 = vym.currentMap();
+
+org = m1.getURL();
+print ("Original:");
+print (org);
+
+s = org;
+
+// Chop trailing "/"
+if (s[s.length-1] == '/') {
+  s = s.slice(0, s.length - 1);
+}
+
+// Remove confluence parts
+if (s.indexOf("infohub") != -1) {
+  print("Found infohub page");
+  if (s.indexOf("spaceKey") != -1) {
+    s = s.replace(/^.*spaceKey=/g, "");
+    s = s.replace(/(&title=)/g, ": ");
+  } else
+  {
+    s = s.replace(/^.*display\//g, "");
+    s = s.replace(/\//g, ": ");
+  }
+} else // no infohub page
+{
+  // remove path
+  s = s.replace(/^.*\//g, "");
+}
+
+print (s);
+
+// Replace "+" and "-"
+s = s.replace(/\+/g, " ");
+s = s.replace(/%3A/g, "");
+print ("After replacing:");
+print (s);
+
+// Write new header
+m1.setHeadingPlainText(s);
+
+if ( org == s ) {
+  statusMessage ("Heading not changed.");
+} else {
+  statusMessage("Changed heading: " + org + " -> " + s);
+}
\ No newline at end of file