From 8192f980f2e40141abbf0d329144d5e0e7c48cf8 Mon Sep 17 00:00:00 2001 From: wxwxwxwx9 <37920115+wxwxwxwx9@users.noreply.github.com> Date: Fri, 7 May 2021 17:03:38 +0800 Subject: [PATCH 01/16] Implement hoist scripts for page and layout to the bottom --- packages/core/src/Layout/Layout.js | 3 +++ packages/core/src/Page/index.js | 8 ++++++++ packages/core/src/Page/page.njk | 2 ++ packages/core/src/html/NodeProcessor.js | 4 +++- .../src/html/scriptAndStyleTagProcessor.js | 20 +++++++++++-------- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/core/src/Layout/Layout.js b/packages/core/src/Layout/Layout.js index 1946860ce7..d2ddc8acf7 100644 --- a/packages/core/src/Layout/Layout.js +++ b/packages/core/src/Layout/Layout.js @@ -21,6 +21,7 @@ class Layout { this.headTop = []; this.headBottom = []; this.scriptBottom = []; + this.layoutUserScripts = []; this.generatePromise = undefined; } @@ -40,6 +41,7 @@ class Layout { const fileConfig = { ...this.config, headerIdMap: {}, + layoutUserScripts: this.layoutUserScripts, }; pageSources = new PageSources(); this.layoutPageBodyVariable = `{{${uuidv4()}-${uuidv4()}}}`; @@ -100,6 +102,7 @@ class Layout { headTop: this.headTop, headBottom: this.headBottom, scriptBottom: this.scriptBottom, + layoutUserScripts: this.layoutUserScripts, }; } } diff --git a/packages/core/src/Page/index.js b/packages/core/src/Page/index.js index da942f3acb..38cdc05a30 100644 --- a/packages/core/src/Page/index.js +++ b/packages/core/src/Page/index.js @@ -56,6 +56,11 @@ class Page { * @type {Object>} */ this.asset = _.cloneDeep(this.pageConfig.asset); + /** + * To collect all the user provided scripts + * @type {Array} + */ + this.userScripts = []; /** * The pure frontMatter of the page as collected in {@link collectFrontMatter}. * https://markbind.org/userGuide/tweakingThePageStructure.html#front-matter @@ -131,6 +136,8 @@ class Page { asset, baseUrl: this.pageConfig.baseUrl, content, + userScripts: this.userScripts.join('\n'), + layoutUserScripts: this.asset.layoutUserScripts.join('\n'), hasPageNav, dev: this.pageConfig.dev, faviconUrl: this.pageConfig.faviconUrl, @@ -451,6 +458,7 @@ class Page { ignore: this.pageConfig.ignore, addressablePagesSource: this.pageConfig.addressablePagesSource, intrasiteLinkValidation: this.pageConfig.intrasiteLinkValidation, + userScripts: this.userScripts, }; const { variableProcessor, layoutManager, pluginManager } = this.pageConfig; diff --git a/packages/core/src/Page/page.njk b/packages/core/src/Page/page.njk index 5d99b2df9a..f3c354ecd2 100644 --- a/packages/core/src/Page/page.njk +++ b/packages/core/src/Page/page.njk @@ -41,6 +41,8 @@ {{ content }} +{{ userScripts }} +{{ layoutUserScripts }} + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + - + + @@ -31,10 +31,10 @@ - - + + + + + - + + @@ -31,10 +31,10 @@ - - + + + + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + - + + @@ -31,10 +31,10 @@ - - + + + + + - + + @@ -31,10 +31,10 @@ - - + + + + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + + + @@ -28,7 +28,7 @@ - + +

There should be no text between this and the next <hr> tag in the browser, since it is a <style> tag.

-

There should be text between this and the next <hr> tag, since it is a special tag. All text should appear in the browser window as a single line, @@ -102,6 +91,18 @@