mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Fix context for templating and page
This commit is contained in:
@@ -175,18 +175,6 @@ Output.prototype.onResolveTemplate = function(from, to) {
|
||||
|
||||
// ---- Utilities ----
|
||||
|
||||
// Return the complete templating context for a page
|
||||
Output.prototype.getPageContext = function(page) {
|
||||
return _.extend(
|
||||
page.getContext(),
|
||||
gitbook.getContext(),
|
||||
this.book.getContext(),
|
||||
this.book.summary.getContext(),
|
||||
this.book.glossary.getContext(),
|
||||
this.book.config.getContext()
|
||||
);
|
||||
};
|
||||
|
||||
// Resolve a file path in the context of a specific page
|
||||
// Result is an "absolute path relative to the output folder"
|
||||
Output.prototype.resolveForPage = function(page, href) {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ JSONOutput.prototype.onPage = function(page) {
|
||||
|
||||
// Write as json
|
||||
.then(function() {
|
||||
var json = that.getPageContext(page);
|
||||
var json = page.getContext();
|
||||
|
||||
// Delete some private properties
|
||||
delete json.config;
|
||||
|
||||
@@ -138,7 +138,7 @@ WebsiteOutput.prototype.onPage = function(page) {
|
||||
|
||||
// Render the page template with the same context as the json output
|
||||
.then(function() {
|
||||
return that.render('page', that.getPageContext(page));
|
||||
return that.render('page', page.getContext());
|
||||
})
|
||||
|
||||
// Write the HTML file
|
||||
|
||||
+22
-14
@@ -6,6 +6,7 @@ var error = require('../utils/error');
|
||||
var pathUtil = require('../utils/path');
|
||||
var location = require('../utils/location');
|
||||
var parsers = require('../parsers');
|
||||
var gitbook = require('../gitbook');
|
||||
var HTMLPipeline = require('./html');
|
||||
|
||||
/*
|
||||
@@ -109,21 +110,28 @@ Page.prototype.getContext = function() {
|
||||
if (dir == 'neutral') dir = null;
|
||||
}
|
||||
|
||||
return {
|
||||
file: {
|
||||
path: this.path,
|
||||
mtime: this.mtime,
|
||||
type: this.type
|
||||
return _.extend(
|
||||
{
|
||||
file: {
|
||||
path: this.path,
|
||||
mtime: this.mtime,
|
||||
type: this.type
|
||||
},
|
||||
page: {
|
||||
title: article? article.title : null,
|
||||
next: next? next.getContext() : null,
|
||||
previous: prev? prev.getContext() : null,
|
||||
level: article? article.level : null,
|
||||
content: this.content,
|
||||
dir: dir
|
||||
}
|
||||
},
|
||||
page: {
|
||||
title: article? article.title : null,
|
||||
next: next? next.getContext() : null,
|
||||
previous: prev? prev.getContext() : null,
|
||||
level: article? article.level : null,
|
||||
content: this.content,
|
||||
dir: dir
|
||||
}
|
||||
};
|
||||
gitbook.getContext(),
|
||||
this.book.getContext(),
|
||||
this.book.summary.getContext(),
|
||||
this.book.glossary.getContext(),
|
||||
this.book.config.getContext()
|
||||
);
|
||||
};
|
||||
|
||||
// Parse the page and return its content
|
||||
|
||||
Reference in New Issue
Block a user