diff options
| author | Yehonal <yehonal.azeroth@gmail.com> | 2020-01-12 18:24:18 +0100 |
|---|---|---|
| committer | Yehonal <yehonal.azeroth@gmail.com> | 2020-01-12 18:24:18 +0100 |
| commit | 69655922dc8fada82e347b4598c53b784e370e20 (patch) | |
| tree | 5a59dbfe3f81c20fc5392007c4ed3b0c459d0447 /assets | |
| parent | 31bc964779174e72d9f616707f1d1d8c97723570 (diff) | |
| download | wiki-69655922dc8fada82e347b4598c53b784e370e20.tar.gz wiki-69655922dc8fada82e347b4598c53b784e370e20.tar.bz2 wiki-69655922dc8fada82e347b4598c53b784e370e20.zip | |
improved red-link check
Diffstat (limited to 'assets')
| -rw-r--r-- | assets/js/checkLinks.js (renamed from assets/js/red-links.js) | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/assets/js/red-links.js b/assets/js/checkLinks.js index 8c1d719..bd41fb6 100644 --- a/assets/js/red-links.js +++ b/assets/js/checkLinks.js @@ -1,8 +1,7 @@ (function ($) { // // RED LINK FEATURE (Hacky) - // TODO: filter external links - $.fn.redLinks = function () { + $.fn.checkLinks = function (staticPages) { setTimeout( function () { $('a').each(function () { @@ -13,12 +12,25 @@ return; } - var ext = this.href.split('.').pop().split(/\#|\?/)[0]; + for (var k in staticPages) { + var page = staticPages[k]; + var link = document.createElement("a"); + link.href = page; - // [Performance tip] pessimistic condition based on the fact that + if (this.href === link.href) { + return; + } + } + + var ext = this.pathname.split('.').pop().split(/\#|\?/)[0]; + + // pessimistic condition based on the fact that // markdown files are automatically converted in html // if they are part of the wiki (the real check is right below) - if (ext.toLowerCase() == "md" || ext.toLowerCase() == "markdown") + var lExt = ext && ext.toLowerCase(); + var isRed = lExt == "md" || lExt == "markdown"; + + if (isRed) $(this).css('color', 'red'); var that = this; |
