X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=demos%2Fscripts%2Fstrip-url.vys;fp=demos%2Fscripts%2Fstrip-url.vys;h=ddcaf5fac65a34c7c84c3300e808106fdf50425a;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/demos/scripts/strip-url.vys b/demos/scripts/strip-url.vys new file mode 100644 index 0000000..ddcaf5f --- /dev/null +++ b/demos/scripts/strip-url.vys @@ -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