summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--lib/generate/index.js30
-rw-r--r--lib/generate/site/index.js1
-rw-r--r--lib/parse/lex.js4
-rw-r--r--lib/parse/page.js5
-rw-r--r--theme/templates/includes/book/summary.html11
6 files changed, 46 insertions, 10 deletions
diff --git a/README.md b/README.md
index 8c15303..f7cecc5 100644
--- a/README.md
+++ b/README.md
@@ -92,6 +92,11 @@ Here are the options that can be stored in this file:
"issues": null,
"contribute": null,
+ // Custom links at top of sidebar
+ "custom": {
+ "Custom link name": "https://customlink.com"
+ },
+
// Sharing links
"sharing": {
"google": null,
diff --git a/lib/generate/index.js b/lib/generate/index.js
index 444f75f..53de646 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -271,13 +271,31 @@ var generateBook = function(options) {
// Get summary
.then(function() {
- return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
- .then(function(_summary) {
- options.summary = parse.summary(_summary);
+ var summary = {
+ path: path.join(options.input, "SUMMARY.md")
+ };
- // Parse navigation
- options.navigation = parse.navigation(options.summary);
- });
+ var _callHook = function(name) {
+ return generator.callHook(name, summary)
+ .then(function(_summary) {
+ summary = _summary;
+ return summary;
+ });
+ };
+
+ return fs.readFile(summary.path, "utf-8")
+ .then(function(_content) {
+ summary.content = _content;
+ return _callHook("summary:before");
+ })
+ .then(function() {
+ summary.content = parse.summary(summary.content);
+ return _callHook("summary:after");
+ })
+ .then(function() {
+ options.summary = summary.content;
+ options.navigation = parse.navigation(options.summary);
+ })
})
// Skip processing some files
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index b59c01c..dcc48d7 100644
--- a/lib/generate/site/index.js
+++ b/lib/generate/site/index.js
@@ -102,6 +102,7 @@ Generator.prototype.convertFile = function(content, _input) {
var page = {
path: _input,
+ rawPath: input, // path to raw md file
content: content,
progress: parse.progress(this.options.navigation, _input)
};
diff --git a/lib/parse/lex.js b/lib/parse/lex.js
index 17eab69..852d4e0 100644
--- a/lib/parse/lex.js
+++ b/lib/parse/lex.js
@@ -118,6 +118,10 @@ function lexPage(src) {
return sections;
}, [])
+ .map(function(section) {
+ section.links = nodes.links;
+ return section;
+ })
.value();
}
diff --git a/lib/parse/page.js b/lib/parse/page.js
index d714a15..b459798 100644
--- a/lib/parse/page.js
+++ b/lib/parse/page.js
@@ -13,10 +13,9 @@ var lnormalize = require('../utils/lang').normalize;
// Render a section using our custom renderer
function render(section, _options) {
// Copy section
+ var links = section.links || {};
section = _.toArray(section);
-
- // marked's Render expects this, we don't use it yet
- section.links = {};
+ section.links = links;
// Build options using defaults and our custom renderer
var options = _.extend({}, marked.defaults, {
diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html
index 2f9dc3f..8014d7e 100644
--- a/theme/templates/includes/book/summary.html
+++ b/theme/templates/includes/book/summary.html
@@ -1,7 +1,7 @@
{% macro articles(_articles) %}
{% for item in _articles %}
{% 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 %}>
+ <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 %}
{% if !externalLink %}
<a href="{{ basePath }}/{{ item.path|mdLink }}">
@@ -59,6 +59,15 @@
</li>
{% endif %}
+ {% if options.links.custom %}
+ {% for link in options.links.custom %}
+ {% set _divider = true %}
+ <li>
+ <a href="{{ options.links.custom[loop.key] }}" target="blank" class="custom-link">{{ loop.key }}</a>
+ </li>
+ {% endfor %}
+ {% endif %}
+
{% if _divider %}
<li class="divider"></li>
{% endif %}