insert-html-into-template
v2.1.0
Published
"description": "A Node.js package to generate an HTML file with inserted content from text files.",
Downloads
3
Readme
Generate HTML Package
This is a Node.js package that generates an HTML file by inserting content from multiple text files into an HTML template. User must specify:
- content folder path
- template folder path
- output file path
- (optional) replacement string
The program will recursively scan for files in the content folder path provided
Installation
To use this package, you need to have Node.js and npm (Node Package Manager) installed on your computer. You can install the package globally or use it within a project.
Global Installation
npm install -g generate-html-package
Local Installation
npm i generate-html-package
Usage
1. To insert all files one after another as one block:
To generate an HTML file with inserted content, use the package as follows:
generate-html-package <contentFolderPath> <templateFilePath> <outputFilePath> <replacementString>
Script will recursively check content folder.
Replace <contentFolderPath>, <templateFilePath>, <outputFilePath>, and <replacementString> with the appropriate paths for your project.
For example:
template.html
<!--template-all.html-->
<html><body>
<!--INSERT_HTML_INTO_TEMPLATE-->
</body></html>
generate-html-package ./content ./template-all.html ./output.html '<!--insert_html_into_template-->'
Please note, order of content files is not guaranteed.
2. To convert files to tags and insert them throughout template:
As an alternative, you can have each file treated as its own html tag:
touch html-tag1 html-tag2 html-tag3
touch side/side1.html
cat html1 > html-tag1
cat html2 > html-tag2
cat html3 > html-tag3
cat side1 > side1.html
<!--template-each.html-->
<html>
<body>
<h1>hello</h1>
<!--side1-->
<!--html-tag1-->
<!--html-tag2-->
<!--html-tag3-->
<!--html-tag1-->
<h1>world</h1>
</body>
</html>
To make this work, simply do not specify a replacement string when calling the package
generate-html-package ./content ./template-each.html ./output.html
Example
Suppose you have content files located in the content folder and a template file named template.html. You can use the package to generate an output HTML file as follows:
generate-html-package ./content ./template-all.html ./output.html
Author
Joseph Skaf
License
This project is licensed under the MIT License.