X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/4a1132c49fad62f3bbe895df112e16c9d0b0a41c..aa06b950eaa6bbdd20813ac08d4383219a09ab97:/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn diff --git a/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn b/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn index a11c807e8..e0bf4acf0 100644 --- a/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn +++ b/doc/tips/JavaScript_to_add_index.html_to_file:_links.mdwn @@ -1,3 +1,5 @@ +[[!meta date="2007-09-10 04:32:55 +0000"]] + The source file `foo/bar.mdwn` or `foo/bar.html` generates the page `foo/bar/index.html`, but the links to the page appear as "`foo/bar/`". This is fine (and recommended) for pages @@ -36,4 +38,28 @@ This can be placed in `page.tmpl`: ... -This script has not been extensively tested. \ No newline at end of file +This script has not been extensively tested. + +--- + +A version that handles anchors: + + + function fixLinks() { + var scheme = location.protocol; + if (scheme != "file:") return; + var links = document.getElementsByTagName("a"); + for (var i = links.length; --i >= 0; ) { + var link = links[i]; + var href = link.href; + var anchor = ""; + var anchorIndex = href.indexOf("#"); + if (anchorIndex != -1) { + anchor = href.substring(anchorIndex); + href = href.substring(0, anchorIndex); + }; + var hlen = href.length; + if (hlen > 0 && link.protocol==scheme && href.charAt(hlen-1) == "/") + links[i].href = href + "index.html" + anchor; + } + }