summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/gitbook-core/src/models/Page.js20
-rw-r--r--packages/gitbook/src/api/decodePage.js2
-rw-r--r--packages/gitbook/src/api/encodePage.js5
3 files changed, 17 insertions, 10 deletions
diff --git a/packages/gitbook-core/src/models/Page.js b/packages/gitbook-core/src/models/Page.js
index 838191e..e3c4a96 100644
--- a/packages/gitbook-core/src/models/Page.js
+++ b/packages/gitbook-core/src/models/Page.js
@@ -1,20 +1,22 @@
-const { Record } = require('immutable');
+const { Record, Map, fromJS } = require('immutable');
const DEFAULTS = {
- title: '',
- content: '',
- dir: 'ltr',
- depth: 1,
- level: '',
- previous: null,
- next: null
+ title: '',
+ content: '',
+ dir: 'ltr',
+ depth: 1,
+ level: '',
+ previous: null,
+ next: null,
+ attributes: Map()
};
class Page extends Record(DEFAULTS) {
static create(state) {
return state instanceof Page ?
state : new Page({
- ...state
+ ...state,
+ attributes: fromJS(state.attributes)
});
}
}
diff --git a/packages/gitbook/src/api/decodePage.js b/packages/gitbook/src/api/decodePage.js
index 395c8ff..16e5115 100644
--- a/packages/gitbook/src/api/decodePage.js
+++ b/packages/gitbook/src/api/decodePage.js
@@ -19,7 +19,7 @@ function decodePage(output, page, result) {
}
// Update page attributes
- const newAttributes = Immutable.fromJS(page.attributes);
+ const newAttributes = Immutable.fromJS(result.attributes);
page = page.set('attributes', newAttributes);
// GitBook 3
diff --git a/packages/gitbook/src/api/encodePage.js b/packages/gitbook/src/api/encodePage.js
index 48119f7..7d563cd 100644
--- a/packages/gitbook/src/api/encodePage.js
+++ b/packages/gitbook/src/api/encodePage.js
@@ -23,6 +23,11 @@ function encodePage(output, page) {
result.path = file.getPath();
result.rawPath = fs.resolve(result.path);
+ result.setAttribute = (key, value) => {
+ result.attributes[key] = value;
+ return result;
+ };
+
deprecate.field(output, 'page.progress', result, 'progress', function() {
return encodeProgress(output, page);
}, '"page.progress" property is deprecated');