From 0c1a40cd0804c00d775d5ff1341dcf0f4ad42028 Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Mon, 15 Aug 2016 15:28:02 -0400 Subject: [PATCH] Add Option to add user scripts In `docpress.json` you can specify a `scripts` option: ```json { "scripts": [ "assets/piwik.js" ] } ``` The scripts must be in the `docs` folder to be picked up. Resolves https://github.com/docpress/docpress-core/issues/82 --- index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/index.js b/index.js index 1dfd438..3915949 100644 --- a/index.js +++ b/index.js @@ -117,6 +117,20 @@ function addJs (files, ms, done) { files['assets/script.js'] = { contents } this.scripts.push('assets/script.js?t=' + hash(files['assets/script.js'].contents)) + + // Add user's files + let scripts = ms.metadata() + + if (Array.isArray(scripts)) { + let userScripts = scripts.map((location) => { + let file = files[location] + if (!file.contents) return + let fileHash = hash(file.contents) + return `${location}?t=${fileHash}` + }).filter((url) => !!url) + this.scripts = this.scripts.concat(userScripts) + } + done() }