Git Product home page Git Product logo

simple-html-index's Introduction

simple-html-index

stable

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

NPM

stream = html([opt])

Returns a read stream that writes a bare-bones HTML template, with the following optional features:

  • title whether to include a <title> element
  • entry if specified, will add a <script src={{entry}}> element
  • css if specified will add a <link rel="stylesheet" href={{css}}> element
  • favicon if true the favicon.ico request will be suppressed
  • lang the value of the lang attribute in the root <html> element, default 'en'
  • base if 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.

simple-html-index's People

Contributors

emilbayes avatar mantoni avatar mattdesl avatar tgfjt avatar yoshuawuyts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

simple-html-index's Issues

Adding <base href="/">

Would you consider adding <base href="/"> (or a configurable base href) to make the budo built-in default work with pushstate?

This would fix mattdesl/budo#159.

Thank you.

allow adding more custom meta tags

Actually something like

(opts.custom ? opts.custom : ''),

right after L11.

I like and understand the idea behind this simple index, but need some meta tags like canonical and viewport for example.

CLI interface

Do you think it's consistent with the goal of this module to provide a CLI? There's indexhtmlify that wraps a script in html, but perhaps it's not inconceivable to just generate a html file, full stop. Presumably with command line flags via minimist, which would be pretty simple to implement. I'm glad to submit a PR but thought it worthwhile to test the water before bothering ๐Ÿ˜„

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.