Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hugojosefson/merge-html
CLI and module for merging two or more .html files together.
https://github.com/hugojosefson/merge-html
cli combine esmodule html merge module node
Last synced: 29 days ago
JSON representation
CLI and module for merging two or more .html files together.
- Host: GitHub
- URL: https://github.com/hugojosefson/merge-html
- Owner: hugojosefson
- License: mit
- Created: 2020-07-12T13:02:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T11:17:44.000Z (almost 2 years ago)
- Last Synced: 2024-11-22T00:39:10.537Z (about 1 month ago)
- Topics: cli, combine, esmodule, html, merge, module, node
- Language: JavaScript
- Homepage:
- Size: 1.62 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @hugojosefson/merge-html
[![Build Status](https://travis-ci.org/hugojosefson/merge-html.svg?branch=master)](https://travis-ci.org/hugojosefson/merge-html)
[![npm page](https://img.shields.io/npm/v/@hugojosefson/merge-html.svg)](https://npmjs.com/package/@hugojosefson/merge-html)
[![License MIT](https://img.shields.io/npm/l/@hugojosefson/merge-html.svg)](https://tldrlegal.com/license/mit-license)
[![SemVer 2.0.0](https://img.shields.io/badge/SemVer-2.0.0-lightgrey.svg)](https://semver.org/spec/v2.0.0.html)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)## Introduction
CLI and module for merging two or more `.html` files together.
## Prerequisite
Node.js, `v13.7.0` or higher, ideally at least `v14.0.0`.
Recommended to install latest via [nvm](https://github.com/nvm-sh/nvm#readme):
```bash
nvm install stable
```## Usage
```bash
npx --package @hugojosefson/merge-html \
merge-html input1.html input2.html [...inputN.html] \
> output.html
```Will merge all the input html files, and redirect the output to `output.html`.
### Minification
By default, the output HTML is minified using
[html-minifier-terser](https://www.npmjs.com/package/html-minifier-terser) with
[DEFAULT_MINIFY_OPTIONS](#default_minify_options).You may change it by setting the `MERGE_HTML_MINIFY` environment variable to a
boolean, or to a valid JSON object with configuration options. For example:```bash
MERGE_HTML_MINIFY=false \
npx --package @hugojosefson/merge-html \
merge-html input1.html input2.html > \
non-minified.html
```...or...
```bash
MERGE_HTML_MINIFY='{"decodeEntities": true, "keepClosingSlash": true, "maxLineLength": 80}' \
npx --package @hugojosefson/merge-html \
merge-html input1.html input2.html > \
special-minified.html
```## Programmatic access
You can also add the module to your project, `import` it, and use its default
exported function programmatically.```bash
yarn add @hugojosefson/merge-html
``````js
import merge from '@hugojosefson/merge-html'const html1 = `
Example
Hello
`const html2 = `
Example
World
`console.log(merge([html1, html2]))
```The above example would output:
Example
Hello
World
... which when pretty-printed is:
```html
Example
Hello
World
```
### API
#### merge
[src/merge.mjs:15-20](https://github.com/hugojosefson/merge-html/blob/ed7f703815e3ea0706a6da8e351882740c216325/src/merge.mjs#L15-L20 'Source code on GitHub')
Merges two or more HTML strings together.
##### Parameters
- `htmls`
**[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
Array of HTML documents, each as a string.
- `minifyOptions`
**([boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
\|
[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))**
Can be `true`, `false` or an object with options for
[html-minifier-terser](https://www.npmjs.com/package/html-minifier-terser).
(optional, default `DEFAULT_MINIFY_OPTIONS`)Returns
**[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
The resulting HTML document.#### DEFAULT_MINIFY_OPTIONS
[src/fn/minify.mjs:17-20](https://github.com/hugojosefson/merge-html/blob/ed7f703815e3ea0706a6da8e351882740c216325/src/fn/minify.mjs#L17-L20 'Source code on GitHub')
Default `minifyOptions` for `merge()`.