Skip to content

Commit

Permalink
Create subtending directories. NOTE: This won't work for things like
Browse files Browse the repository at this point in the history
  https://example.com/tools if other urls to render have URLs
  like https://example.com/tools/bob.html
  • Loading branch information
phBalance committed Oct 8, 2019
1 parent 83079b3 commit e1d54a1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ssr.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e1d54a1

Please sign in to comment.