Skip to content

Commit

Permalink
Prevent plugins from modifying the page config
Browse files Browse the repository at this point in the history
  • Loading branch information
jamos-tay committed Mar 18, 2019
1 parent 7c8dfbb commit f919f03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ function Page(pageConfig) {
this.layoutsAssetPath = pageConfig.layoutsAssetPath;
this.rootPath = pageConfig.rootPath;
this.enableSearch = pageConfig.enableSearch;
this.pageConfig = pageConfig;
this.plugins = pageConfig.plugins;
this.pluginsContext = pageConfig.pluginsContext;
this.searchable = pageConfig.searchable;
Expand Down Expand Up @@ -803,11 +802,13 @@ Page.prototype.generate = function (builtFiles) {
*/
Page.prototype.preRender = function (content) {
let preRenderedContent = content;
const pageConfig = {
};
Object.entries(this.plugins).forEach(([pluginName, plugin]) => {
if (plugin.preRender) {
preRenderedContent
= plugin.preRender(preRenderedContent, this.pluginsContext[pluginName] || {},
this.frontMatter, this.pageConfig);
this.frontMatter, pageConfig);
}
});
return preRenderedContent;
Expand All @@ -818,11 +819,14 @@ Page.prototype.preRender = function (content) {
*/
Page.prototype.postRender = function (content) {
let postRenderedContent = content;
const pageConfig = {
headingIndexingLevel: this.headingIndexingLevel,
};
Object.entries(this.plugins).forEach(([pluginName, plugin]) => {
if (plugin.postRender) {
postRenderedContent
= plugin.postRender(postRenderedContent, this.pluginsContext[pluginName] || {},
this.frontMatter, this.pageConfig);
this.frontMatter, pageConfig);
}
});
return postRenderedContent;
Expand Down
3 changes: 1 addition & 2 deletions src/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,7 @@ function findDefaultPlugins() {
return walkSync(globPath, {
directories: false,
globs: [`${MARKBIND_PLUGIN_PREFIX}*.js`],
})
.map(file => path.parse(file).name);
}).map(file => path.parse(file).name);
}

/**
Expand Down

0 comments on commit f919f03

Please sign in to comment.