mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 20:20:35 +00:00
Fix update of page attributes in hook "page"
This commit is contained in:
@@ -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)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user