From e1d54a117d50f0354fc270ef73abbfe26a8f05ef Mon Sep 17 00:00:00 2001 From: phBalance Date: Tue, 8 Oct 2019 16:35:07 -0600 Subject: [PATCH] Create subtending directories. NOTE: This won't work for things like https://example.com/tools if other urls to render have URLs like https://example.com/tools/bob.html --- ssr.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ssr.js b/ssr.js index e8bade3..ddd1bf8 100755 --- a/ssr.js +++ b/ssr.js @@ -1,6 +1,7 @@ 'use strict' const fs = require("fs"); +const path = require("path"); const util = require("util"); const url = require("url"); const puppeteer = require("puppeteer"); @@ -126,6 +127,14 @@ async function ssr(opts) { const writeOptions = {encoding: "utf8", mode: cmdline.mode, flag: "w"}; const fileBase = opts.copyToDir + (fetchUrl.pathname === "/" ? "/index" : fetchUrl.pathname) + cmdline.fileExt; console.debug(`saving files with base: ${fileBase}`); + + const dirname = path.dirname(fileBase); + if(!fs.existsSync(dirname)) { + console.debug(`creating directory path ${dirname}`); + + fs.mkdirSync(dirname, {recursive: true, mode: "755"}); + } + try { await writeFilePromisified(fileBase, html, writeOptions); await writeFilePromisified(fileBase + ".gz", gzippedHtml, writeOptions);