Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e0b2e9
commit 4ffc2e9
Showing
7 changed files
with
95 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/node_modules | ||
/dist | ||
/dist | ||
/Sherlock Holmes Selected Stories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const fs = require("fs-extra"); | ||
|
||
const copyAssets = (outputFolder, assetsInputFolder) => { | ||
const assetsFolder = `${outputFolder}/assets`; | ||
|
||
//create assets folder | ||
fs.mkdirSync(assetsFolder, { recursive: true }); | ||
|
||
//copy static file into assets folder | ||
try { | ||
fs.copySync(assetsInputFolder, assetsFolder); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
|
||
module.exports = copyAssets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const path = require("path"); | ||
const createHtml = require("create-html"); | ||
|
||
const generateHTML = (inputFile, stylesheet, data, assets) => { | ||
const doubleNewLines = data.match(/^.+(\r?\n\r?\n)\r?\n/); | ||
const title = doubleNewLines ? doubleNewLines[0] : ""; | ||
var content = | ||
`<h1>${title.trim()}</h1>\n\n` + | ||
data | ||
.slice(title.length) | ||
.split(/(\r?\n)+3/) | ||
.map((para) => `<p>${para.replace(/\r?\n/, " ")}</p>`) | ||
.join("\n"); | ||
|
||
if (assets) { | ||
const imgRegex = /\<img src="(.*?)"(.*?)\>/gim; | ||
const imgTags = content.match(imgRegex); | ||
imgTags.forEach((tag) => { | ||
assets.forEach((asset) => { | ||
const src = /src="(.*?)"/gim; | ||
if (tag.includes(asset)) { | ||
const updatedTag = tag.replace(src, `src="assets/${asset}"`); | ||
content = content.replace(tag, updatedTag); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
const html = createHtml({ | ||
title: title != "" ? title.trim() : path.basename(inputFile, ".txt"), | ||
css: stylesheet, | ||
lang: "en", | ||
head: `<meta name="viewport" content="width=device-width, initial-scale=1"/>`, | ||
body: content, | ||
}); | ||
return html; | ||
}; | ||
|
||
module.exports = generateHTML; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters