mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 02:23:30 +00:00
Adapt themes website templates
This commit is contained in:
@@ -2,7 +2,11 @@ var util = require("util");
|
||||
var path = require("path");
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
|
||||
var nunjucks = require("nunjucks");
|
||||
var ParentExtension = require("nunjucks-parent");
|
||||
var AutoEscapeExtension = require("nunjucks-autoescape");
|
||||
var FilterExtension = require("nunjucks-filter");
|
||||
|
||||
var fs = require("../utils/fs");
|
||||
var BaseGenerator = require("../generator");
|
||||
@@ -74,6 +78,11 @@ Generator.prototype.prepareTemplates = function() {
|
||||
}
|
||||
);
|
||||
|
||||
// Add extension
|
||||
this.env.addExtension('ParentExtension', new ParentExtension());
|
||||
this.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(this.env));
|
||||
this.env.addExtension('FilterExtension', new FilterExtension(this.env));
|
||||
|
||||
return Q();
|
||||
};
|
||||
|
||||
|
||||
+3
-1
@@ -1,7 +1,9 @@
|
||||
var _ = require("lodash");
|
||||
var Q = require("q");
|
||||
|
||||
var nunjucks = require("nunjucks");
|
||||
|
||||
|
||||
var TemplateEngine = function(book) {
|
||||
this.book = book;
|
||||
|
||||
@@ -22,7 +24,7 @@ TemplateEngine.prototype.renderFile = function(filename) {
|
||||
return that.book.statFile(filename)
|
||||
.then(function(stat) {
|
||||
var context = {
|
||||
// Variabels from book.json
|
||||
// Variables from book.json
|
||||
book: that.book.options.variables,
|
||||
|
||||
// infos about the file
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
"gitbook-markdown": "1.0.0",
|
||||
"gitbook-asciidoctor": "1.0.0",
|
||||
"nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747",
|
||||
"nunjucks-parent": "0.1.0",
|
||||
"unjucks-autoescape": "0.1.0",
|
||||
"nunjucks-filter": "0.1.0",
|
||||
"semver": "2.2.1",
|
||||
"npmi": "0.1.1",
|
||||
"cheerio": "0.18.0",
|
||||
|
||||
@@ -51,6 +51,7 @@ describe('Book generation', function () {
|
||||
|
||||
it('should correctly generate a book to website', function(done) {
|
||||
testGeneration(book1, "site", function(output) {
|
||||
console.log(fs.readdirSync(output));
|
||||
assert(fs.existsSync(path.join(output, "index.html")));
|
||||
}, done);
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<div class="page">
|
||||
<h1 class="book-chapter book-chapter-{{ progress.current.level|lvl }}">{{ progress.current.title }}</h1>
|
||||
{% for section in content %}
|
||||
<div class="{{ section.type }}" id="section-{{ section.id }}">
|
||||
<div class="{{ section.type }}" id="section-{{ section.id }}">
|
||||
{% if section.type == "normal" %}
|
||||
{% autoescape false %}{{ section.content }}{% endautoescape %}
|
||||
{% elif section.type == "exercise" %}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<li>
|
||||
{% if item.path %}
|
||||
{% if !externalLink %}
|
||||
<a href="{{ basePath }}/{{ item.path|mdLink }}">{{ item.title }}</a>
|
||||
<a href="{{ basePath }}/{{ item.path|contentLink }}">{{ item.title }}</a>
|
||||
{% else %}
|
||||
<a target="_blank" href="{{ item.path }}">{{ item.title }}</a>
|
||||
{% endif %}
|
||||
@@ -17,7 +17,7 @@
|
||||
{% endif %}
|
||||
{% if item.articles.length > 0 %}
|
||||
<ol>
|
||||
{{ articles(item.articles) }}
|
||||
{{ articles(item.articles) }}
|
||||
</ol>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<h4>Index</h4>
|
||||
<ul class="glossary-index">
|
||||
{% for file in item.files %}
|
||||
<li><a href="{{ basePath }}/{{ file.path|mdLink }}"><span class="level">{{ file.level }}.</span> {{ file.title }}</a></li>
|
||||
<li><a href="{{ basePath }}/{{ file.path|contentLink }}"><span class="level">{{ file.level }}.</span> {{ file.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<div class="header">
|
||||
<h2>Exercise</h2>
|
||||
</div>
|
||||
<div class="alert alert-success">
|
||||
<b>Correct!</b>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-danger error-message">
|
||||
<b>False!</b>
|
||||
</div>
|
||||
|
||||
<div class="message">
|
||||
{% autoescape false %}{{ section.content }}{% endautoescape %}
|
||||
</div>
|
||||
<div class="editor" style="height: {{ section.code.solution|lines*20 }}px">{{ section.code.base }}</div>
|
||||
|
||||
<pre class="hidden code-solution">{{ section.code.solution }}</pre>
|
||||
<pre class="hidden code-validation">{{ section.code.validation }}</pre>
|
||||
{% if section.code.context %}
|
||||
<pre class="hidden code-context">{{ section.code.context }}</pre>
|
||||
{% endif %}
|
||||
|
||||
<div class="buttons">
|
||||
<a href="#" class="button size-2 action-submit">Submit</a>
|
||||
<a href="#" class="button size-2 action-solution">Solution</a>
|
||||
</div>
|
||||
@@ -12,7 +12,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Actions Right -->
|
||||
{% if options.links.sharing.all !== false %}
|
||||
{% if options.links.sharing.all != false %}
|
||||
<div class="dropdown pull-right">
|
||||
<a href="#" class="btn toggle-dropdown" aria-label="Toggle share dropdown"><i class="fa fa-share-alt"></i>
|
||||
</a>
|
||||
@@ -32,16 +32,16 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if options.links.sharing.google !== false %}
|
||||
{% if options.links.sharing.google != false %}
|
||||
<a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Share on Google Plus"><i class="fa fa-google-plus"></i></a>
|
||||
{% endif %}
|
||||
{% if options.links.sharing.facebook !== false %}
|
||||
{% if options.links.sharing.facebook != false %}
|
||||
<a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Share on Facebook"><i class="fa fa-facebook"></i></a>
|
||||
{% endif %}
|
||||
{% if options.links.sharing.twitter !== false %}
|
||||
{% if options.links.sharing.twitter != false %}
|
||||
<a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Share on Twitter"><i class="fa fa-twitter"></i></a>
|
||||
{% endif %}
|
||||
{% if options.links.sharing.weibo === true %}
|
||||
{% if options.links.sharing.weibo == true %}
|
||||
<a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="weibo" aria-label="Share on Weibo"><i class="fa fa-weibo"></i></a>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<div class="header">
|
||||
<h2>Quiz</h2>
|
||||
</div>
|
||||
|
||||
<div class="message">
|
||||
{% autoescape false %}{{ section.content }}{% endautoescape %}
|
||||
</div>
|
||||
|
||||
|
||||
{% for quiz in section.quiz %}
|
||||
<div class="question">
|
||||
<div class="question-header">Question {{ loop.index }} of {{ section.quiz.length }}</div>
|
||||
|
||||
<div class="question-content">
|
||||
<div class="alert alert-success hidden">
|
||||
<b>Correct!</b>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-danger error-message hidden">
|
||||
<p><b>Not quite!</b></p>
|
||||
{% autoescape false %}{{ quiz.feedback }}{% endautoescape %}
|
||||
</div>
|
||||
|
||||
<div class="question-inner">
|
||||
{% autoescape false %}{{ quiz.base }}{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hidden question-answers">
|
||||
<div class="question-inner">
|
||||
{% autoescape false %}{{ quiz.solution }}{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="buttons">
|
||||
<a href="#" class="button size-2 action-submit">Submit</a>
|
||||
<a href="#" class="button size-2 action-solution">Solution</a>
|
||||
</div>
|
||||
@@ -1,12 +1,12 @@
|
||||
{% 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 and not externalLink %}data-path="{{ item.path|contentLink }}"{% endif %}>
|
||||
{% if item.path %}
|
||||
{% if !externalLink %}
|
||||
<a href="{{ basePath }}/{{ item.path|mdLink }}">
|
||||
{% if not externalLink %}
|
||||
<a href="{{ basePath }}/{{ item.path|contentLink }}">
|
||||
<i class="fa fa-check"></i>
|
||||
{% if item.level !== "0" %}
|
||||
{% if item.level != "0" %}
|
||||
<b>{{ item.level }}.</b>
|
||||
{% endif %}
|
||||
{{ item.title }}
|
||||
@@ -14,7 +14,7 @@
|
||||
{% else %}
|
||||
<a target="_blank" href="{{ item.path }}">
|
||||
<i class="fa fa-check"></i>
|
||||
{% if item.level !== "0" %}
|
||||
{% if item.level != "0" %}
|
||||
<b>{{ item.level }}.</b>
|
||||
{% endif %}
|
||||
{{ item.title }}
|
||||
@@ -25,7 +25,7 @@
|
||||
{% endif %}
|
||||
{% if item.articles.length > 0 %}
|
||||
<ul class="articles">
|
||||
{{ articles(item.articles) }}
|
||||
{{ articles(item.articles) }}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</li>
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
{{ articles(summary.chapters) }}
|
||||
|
||||
{% if options.links.gitbook !== false %}
|
||||
{% if options.links.gitbook != false %}
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">Published using GitBook</a>
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
{% extends "./layout.html" %}
|
||||
|
||||
{% block head %}
|
||||
{% parent %}
|
||||
{{ super() }}
|
||||
{% if progress.current.next and progress.current.next.path %}
|
||||
<link rel="next" href="{{ basePath }}/{{ progress.current.next.path|mdLink }}" />
|
||||
<link rel="next" href="{{ basePath }}/{{ progress.current.next.path|contentLink }}" />
|
||||
{% endif %}
|
||||
{% if progress.current.prev and progress.current.prev.path %}
|
||||
<link rel="prev" href="{{ basePath }}/{{ progress.current.prev.path|mdLink }}" />
|
||||
<link rel="prev" href="{{ basePath }}/{{ progress.current.prev.path|contentLink }}" />
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}{{ progress.current.title }} | {{ title }}{% endblock %}
|
||||
{% block description %}{% if progress.current.level == "0" %}{{ description }}{% endif %}{% endblock %}
|
||||
{% block description %}{% if progress.current.level == "0" %}{{ description }}{% endif %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="book" data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">
|
||||
<div class="book" data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">
|
||||
{% include "includes/summary.html" %}
|
||||
<div class="book-body">
|
||||
<div class="body-inner">
|
||||
@@ -23,13 +23,9 @@
|
||||
<div class="page-inner">
|
||||
{% block page_inner %}
|
||||
{% for section in content %}
|
||||
<section class="{{ section.type }}" id="section-{{ section.id }}">
|
||||
<section class="{{ section.type }}" id="section-{{ section.id }}">
|
||||
{% if section.type == "normal" %}
|
||||
{% autoescape false %}{{ section.content }}{% endautoescape %}
|
||||
{% elif section.type == "exercise" %}
|
||||
{% include "./includes/exercise.html" with {section: section} %}
|
||||
{% elif section.type == "quiz" %}
|
||||
{% include "./includes/quiz.html" with {section: section} %}
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endfor %}
|
||||
@@ -39,10 +35,10 @@
|
||||
</div>
|
||||
|
||||
{% if progress.current.prev and progress.current.prev.path %}
|
||||
<a href="{{ basePath }}/{{ progress.current.prev.path|mdLink }}" class="navigation navigation-prev {% if !progress.current.next or !progress.current.next.path %}navigation-unique{% endif %}" aria-label="Previous page: {{ progress.current.prev.title }}"><i class="fa fa-angle-left"></i></a>
|
||||
<a href="{{ basePath }}/{{ progress.current.prev.path|contentLink }}" class="navigation navigation-prev {% if not (progress.current.next and progress.current.next.path) %}navigation-unique{% endif %}" aria-label="Previous page: {{ progress.current.prev.title }}"><i class="fa fa-angle-left"></i></a>
|
||||
{% endif %}
|
||||
{% if progress.current.next and progress.current.next.path %}
|
||||
<a href="{{ basePath }}/{{ progress.current.next.path|mdLink }}" class="navigation navigation-next {% if !progress.current.prev or !progress.current.prev.path %}navigation-unique{% endif %}" aria-label="Next page: {{ progress.current.next.title }}"><i class="fa fa-angle-right"></i></a>
|
||||
<a href="{{ basePath }}/{{ progress.current.next.path|contentLink }}" class="navigation navigation-next {% if not (progress.current.prev or progress.current.prev.path) %}navigation-unique{% endif %}" aria-label="Next page: {{ progress.current.next.title }}"><i class="fa fa-angle-right"></i></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user