From f919f031fe49fea3fa3c9f23880efdd59d6f89d9 Mon Sep 17 00:00:00 2001 From: jamos-tay Date: Mon, 18 Mar 2019 19:52:22 +0800 Subject: [PATCH] Prevent plugins from modifying the page config --- src/Page.js | 10 +++++++--- src/Site.js | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Page.js b/src/Page.js index ce03391cdf..4e567098a0 100644 --- a/src/Page.js +++ b/src/Page.js @@ -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; @@ -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; @@ -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; diff --git a/src/Site.js b/src/Site.js index 79db576c86..bb22f9b4ed 100644 --- a/src/Site.js +++ b/src/Site.js @@ -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); } /**