summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md2
-rw-r--r--packages/gitbook/src/api/decodePage.js34
-rw-r--r--packages/gitbook/src/api/encodeGlobal.js16
-rw-r--r--packages/gitbook/src/json/encodePage.js9
4 files changed, 35 insertions, 26 deletions
diff --git a/CHANGES.md b/CHANGES.md
index a3f4466..b41d2f0 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -10,6 +10,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- *Website Feature:* new default plugin `copy-code` to copy code blocks content in one click
- *Website Feature:* new default plugin `heading-anchors` to have clickable headings
- *Website Feature:* `fontsettings` is now only controlling the font size, and can work on multiple themes
+- *Plugin API*: hook `page` can no longer modify the content, only the page's attributes
+- *Plugin API*: plugins can no longer export resources, instead use the `_assets` folder
## 3.2.0
- Switch markdown parser from `kramed` to `markup-it`
diff --git a/packages/gitbook/src/api/decodePage.js b/packages/gitbook/src/api/decodePage.js
index 4fd78af..395c8ff 100644
--- a/packages/gitbook/src/api/decodePage.js
+++ b/packages/gitbook/src/api/decodePage.js
@@ -1,14 +1,14 @@
-const deprecate = require('./deprecate');
+const Immutable = require('immutable');
/**
- Decode changes from a JS API to a page object.
- Only the content can be edited by plugin's hooks.
-
- @param {Output} output
- @param {Page} page: page instance to edit
- @param {Object} result: result from API
- @return {Page}
-*/
+ * Decode changes from a JS API to a page object.
+ * Only the content can be edited by plugin's hooks.
+ *
+ * @param {Output} output
+ * @param {Page} page: page instance to edit
+ * @param {Object} result: result from API
+ * @return {Page}
+ */
function decodePage(output, page, result) {
const originalContent = page.getContent();
@@ -18,7 +18,9 @@ function decodePage(output, page, result) {
return page;
}
- deprecate.disable('page.sections');
+ // Update page attributes
+ const newAttributes = Immutable.fromJS(page.attributes);
+ page = page.set('attributes', newAttributes);
// GitBook 3
// Use returned page.content if different from original content
@@ -26,18 +28,6 @@ function decodePage(output, page, result) {
page = page.set('content', result.content);
}
- // GitBook 2 compatibility
- // Finally, use page.sections
- else if (result.sections) {
- page = page.set('content',
- result.sections.map(function(section) {
- return section.content;
- }).join('\n')
- );
- }
-
- deprecate.enable('page.sections');
-
return page;
}
diff --git a/packages/gitbook/src/api/encodeGlobal.js b/packages/gitbook/src/api/encodeGlobal.js
index 18ebdf0..89db629 100644
--- a/packages/gitbook/src/api/encodeGlobal.js
+++ b/packages/gitbook/src/api/encodeGlobal.js
@@ -36,6 +36,22 @@ function encodeGlobal(output) {
summary: encodeSummary(output, book.getSummary()),
/**
+ * Return absolute path to the root folder of the book
+ * @return {String}
+ */
+ root() {
+ return book.getRoot();
+ },
+
+ /**
+ * Return absolute path to the root folder of the book (for content)
+ * @return {String}
+ */
+ contentRoot() {
+ return book.getContentRoot();
+ },
+
+ /**
* Check if the book is a multilingual book.
* @return {Boolean}
*/
diff --git a/packages/gitbook/src/json/encodePage.js b/packages/gitbook/src/json/encodePage.js
index 6610308..0671721 100644
--- a/packages/gitbook/src/json/encodePage.js
+++ b/packages/gitbook/src/json/encodePage.js
@@ -13,7 +13,11 @@ function encodePage(page, summary, urls) {
const attributes = page.getAttributes();
const article = summary.getByPath(file.getPath());
- const result = attributes.toJS();
+ const result = {
+ content: page.getContent(),
+ dir: page.getDir(),
+ attributes: attributes.toJS()
+ };
if (article) {
result.title = article.getTitle();
@@ -31,9 +35,6 @@ function encodePage(page, summary, urls) {
}
}
- result.content = page.getContent();
- result.dir = page.getDir();
-
return result;
}