summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/generate/template.js7
-rw-r--r--lib/utils/links.js8
-rw-r--r--theme/templates/includes/book/summary.html15
3 files changed, 24 insertions, 6 deletions
diff --git a/lib/generate/template.js b/lib/generate/template.js
index a4ac4fd..9b85228 100644
--- a/lib/generate/template.js
+++ b/lib/generate/template.js
@@ -2,6 +2,7 @@ var path = require("path");
var swig = require('swig');
var hljs = require('highlight.js');
+var links = require('../utils/').links;
var pkg = require('../../package.json');
swig.setDefaults({
@@ -24,7 +25,6 @@ swig.setFilter('mdLink', function(link) {
return link;
});
-
// Swig filter: highlight coloration
swig.setFilter('code', function(code, lang) {
try {
@@ -44,4 +44,9 @@ swig.setFilter('pathJoin', function(base, _path) {
return path.join(base, _path);
});
+// Is a link an absolute link
+swig.setFilter('isExternalLink', function(link) {
+ return links.isExternal(link);
+});
+
module.exports = swig;
diff --git a/lib/utils/links.js b/lib/utils/links.js
index c965dd9..6606bbf 100644
--- a/lib/utils/links.js
+++ b/lib/utils/links.js
@@ -1,6 +1,11 @@
var url = require('url');
var path = require('path');
+// Is the link an external link
+var isExternal = function(href) {
+ return Boolean(url.parse(href).protocol);
+};
+
// Return true if the link is relative
var isRelative = function(href) {
var parsed = url.parse(href);
@@ -41,6 +46,7 @@ var join = function() {
module.exports = {
isRelative: isRelative,
+ isExternal: isExternal,
toAbsolute: toAbsolute,
join: join
-}; \ No newline at end of file
+};
diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html
index 697cce8..76ee192 100644
--- a/theme/templates/includes/book/summary.html
+++ b/theme/templates/includes/book/summary.html
@@ -1,10 +1,17 @@
{% macro articles(_articles) %}
{% for item in _articles %}
- <li class="chapter {% if item._path == _input %}active{% endif %}" data-level="{{ item.level }}" {% if item.path %}data-path="{{ item.path|mdLink }}"{% endif %}>
+ {% set externalLink = item.path|isExternalLink %}
+ <li class="chapter {% if item._path == _input %}active{% endif %}" data-level="{{ item.level }}" {% if item.path && !externalLink %}data-path="{{ item.path|mdLink }}"{% endif %}>
{% if item.path %}
- <a href="{{ basePath }}/{{ item.path|mdLink }}">
- <i class="fa fa-check"></i> <b>{{ item.level }}.</b> {{ item.title }}
- </a>
+ {% if !externalLink %}
+ <a href="{{ basePath }}/{{ item.path|mdLink }}">
+ <i class="fa fa-check"></i> <b>{{ item.level }}.</b> {{ item.title }}
+ </a>
+ {% else %}
+ <a target="_blank" href="{{ item.path }}">
+ <i class="fa fa-check"></i> <b>{{ item.level }}.</b> {{ item.title }}
+ </a>
+ {% endif %}
{% else %}
<span><b>{{ item.level }}.</b> {{ item.title }}</span>
{% endif %}