Allow external links in summary, fixes #300

This commit is contained in:
Aaron O'Mullan
2014-06-08 12:31:52 -07:00
parent 30c6d1c9de
commit b425db0979
3 changed files with 24 additions and 6 deletions
+6 -1
View File
@@ -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;
+7 -1
View File
@@ -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
};
};
+11 -4
View File
@@ -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 %}