summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYehonal <yehonal.azeroth@gmail.com>2020-01-12 18:24:18 +0100
committerYehonal <yehonal.azeroth@gmail.com>2020-01-12 18:24:18 +0100
commit69655922dc8fada82e347b4598c53b784e370e20 (patch)
tree5a59dbfe3f81c20fc5392007c4ed3b0c459d0447
parent31bc964779174e72d9f616707f1d1d8c97723570 (diff)
downloadwiki-69655922dc8fada82e347b4598c53b784e370e20.tar.gz
wiki-69655922dc8fada82e347b4598c53b784e370e20.tar.bz2
wiki-69655922dc8fada82e347b4598c53b784e370e20.zip
improved red-link check
-rw-r--r--_includes/git-wiki/sections/head/scripts.html2
-rw-r--r--_includes/git-wiki/sections/tail/tail.html8
-rw-r--r--assets/js/checkLinks.js (renamed from assets/js/red-links.js)22
-rw-r--r--wiki/main_page.md2
4 files changed, 26 insertions, 8 deletions
diff --git a/_includes/git-wiki/sections/head/scripts.html b/_includes/git-wiki/sections/head/scripts.html
index 9cf23f3..9497626 100644
--- a/_includes/git-wiki/sections/head/scripts.html
+++ b/_includes/git-wiki/sections/head/scripts.html
@@ -4,7 +4,7 @@
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
-<script src="{{ '/assets/js/red-links.js' | relative_url }}"></script>
+<script src="{{ '/assets/js/checkLinks.js' | relative_url }}"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
diff --git a/_includes/git-wiki/sections/tail/tail.html b/_includes/git-wiki/sections/tail/tail.html
index 8aa8139..f5944c9 100644
--- a/_includes/git-wiki/sections/tail/tail.html
+++ b/_includes/git-wiki/sections/tail/tail.html
@@ -18,9 +18,15 @@
</script>
{% endif %}
+{% assign items = site.html_pages %}
+{% for page in items %}
+{% assign url = page.url | relative_url %}
+{% assign urls = urls | append: url | append: "," %}
+{% endfor %}
+
<script type="text/javascript">
$(document).ready(function () {
- $(document.body).redLinks();
+ $(document.body).checkLinks("{{ urls }}".split(","));
});
</script>
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;
diff --git a/wiki/main_page.md b/wiki/main_page.md
index a1716a5..62ec0b5 100644
--- a/wiki/main_page.md
+++ b/wiki/main_page.md
@@ -4,4 +4,4 @@ redirect_from: "/"
This is a sample of main page. You can edit it to start your wiki.
-For documentation, installation guide and demo of [git-wiki-theme](git-wiki-theme.md) visit this [link](http://drassil.github.io/git-wiki/)
+For documentation, installation guide and demo of [git-wiki-theme](git-wiki-theme) visit this [link](http://drassil.github.io/git-wiki/)