2 * "Go" function for static HTML dump
4 function goToStatic(depth) {
5 var url = getStaticURL(document.getElementById("searchInput").value, depth);
9 alert("Invalid title");
14 * Determine relative path for a given non-canonical title
16 function getStaticURL(text, depth) {
17 var pdbk = getPDBK(text);
22 var path = getHashedDirectory(pdbk, depth) + "/" + getFriendlyName(pdbk) + ".html";
23 if (!/(index\.html|\/)$/.exec(location)) {
24 for (i = 0; i < depth; i++) {
32 function getPDBK(text) {
33 // Spaces to underscores
34 text = text.replace(/ /g, "_");
36 // Trim leading and trailing space
37 text = text.replace(/^_+/g, "");
38 text = text.replace(/_+$/g, "");
40 // Capitalise first letter
44 function getHashedDirectory(pdbk, depth) {
45 // Find the first colon if there is one, use characters after it
46 var dbk = pdbk.replace(/^[^:]*:_*(.*)$/, "$1");
49 for (i=0; i < depth; i++) {
53 if (i >= dbk.length) {
57 cc = dbk.charCodeAt(i);
59 if (cc >= 128 || /[a-zA-Z0-9!#$%&()+,[\]^_`{}-]/.exec(c)) {
60 dir += c.toLowerCase();
62 dir += binl2hex([cc]).substr(0,2).toUpperCase();
70 return s.charAt(0).toUpperCase() + s.substring(1, s.length);
73 function getFriendlyName(name) {
74 // Replace illegal characters for Windows paths with underscores
75 var friendlyName = name.replace(/[\/\\*?"<>|~]/g, "_");
77 // Work out lower case form. We assume we're on a system with case-insensitive
78 // filenames, so unless the case is of a special form, we have to disambiguate
79 var lowerCase = ucfirst(name.toLowerCase());
81 // Make it mostly unique
82 if (lowerCase != friendlyName) {
83 friendlyName += "_" + hex_md5(_to_utf8(name)).substring(0, 4);
85 // Handle colon specially by replacing it with tilde
86 // Thus we reduce the number of paths with hashes appended
87 friendlyName = friendlyName.replace(":", "~");