1.5.0 • Published 9 years ago
simple-html-index v1.5.0
simple-html-index
A tiny through stream that returns a bare-bones HTML5 template with an optional
<link> and <title> in the head and <script> entry-point in the body.
Example
In html.js
var html = require('simple-html-index')
html({ title: 'hello', entry: 'bundle.js' })
.pipe(process.stdout)Now run node html.js > index.html and you would end up with a file that looks like this: (after formatting)
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello</title>
<meta charset="utf-8">
</head>
<body>
<script src="bundle.js"></script>
</body>
</html>Usage
stream = html([opt])
Returns a read stream that writes a bare-bones HTML template, with the following optional features:
titlewhether to include a<title>elemententryif specified, will add a<script src={{entry}}>elementcssif specified will add a<link rel="stylesheet" href={{css}}>elementfaviconiftruethefavicon.icorequest will be suppressedlangthe value of thelangattribute in the root<html>element, default'en'baseif specified will add a<base href={{base}}>element
Additional properties
Combine simple-html-index with
hyperstream to add additional
properties to html. An example how to add an extra <script> tag to the body
tag:
const hyperstream = require('hyperstream')
const html = require('simple-html-index')
const htmls = html({ entry: 'static/bundle.js' })
const hs = hyperstream({
body: { _appendHtml: "<script>console.log('extra tags!')</script>" }
})
htmls.pipe(hs).pipe(process.stdout)License
MIT, see LICENSE.md for details.
