Detalhes do pacote

posthtml-noscript

metonym214MIT0.2.4

PostHTML plugin to insert noscript content

posthtml, posthtml plugin, noscript

readme (leia-me)

posthtml-noscript

NPM Deps Build Coverage

posthtml-noscript is a PostHTML plugin to insert noscript content.

Use Cases:

  • Display a "Enable JavaScript" message in a Single Page Application (SPA)
  • Specify resource link elements (e.g. stylesheets) to load if JavaScript is disabled

Before:

<body>
  <div id="root"></div>
</body>

After:

<body>
  <noscript>You need to enable JavaScript to run this app.</noscript>
  <div id="root"></div>
</body>

Install

yarn add -D posthtml-noscript
# OR
npm i posthtml-noscript

Usage

const fs = require('fs');
const posthtml = require('posthtml');
const { noscript } = require('posthtml-noscript');

const html = fs.readFileSync('./index.html');

posthtml()
  .use(noscript({ content: 'You need to enable JavaScript to run this app.' }))
  .process(html)
  .then(result => fs.writeFileSync('./after.html', result.html));

Options

By default, the plugin prepends noscript markup inside the body tag.

Optionally, specify "head" as the parent tag to insert noscript content inside the head tag.

Before:

In this example, custom fonts are loaded via Adobe Typekit using JavaScript. Without a resource link fallback, custom fonts can't be loaded.

<head>
  <script src="https://use.typekit.net/XYZ.js">
    try { Typekit.load({ async: true }); } catch(e) {}
  </script>
</head>

Config:

const fs = require('fs');
const posthtml = require('posthtml');
const { noscript } = require('posthtml-noscript');

const html = fs.readFileSync('./index.html');

posthtml()
  .use(
    noscript({
      content: '<link rel="stylesheet" href="fonts.css" />',
      parent: 'head'
    })
  )
  .process(html)
  .then(result => fs.writeFileSync('./after.html', result.html));

After:

If JavaScript is disabled, custom fonts can still be loaded.

<head>
  <noscript><link rel="stylesheet" href="fonts.css"/></noscript>
  <script src="https://use.typekit.net/XYZ.js">
    try { Typekit.load({ async: true }); } catch(e) {}
  </script>
</head>

Contributing

See the PostHTML Guidelines.

Changelog

License

MIT

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

0.2.4 - 2019-10-13

  • Upgrade posthtml version from 0.11.6 to 0.12.0

  • Upgrade development dependencies (pretty-quick, husky, typescript)

0.2.3 - 2019-09-20

  • Upgrade posthtml version from 0.11.4 to 0.11.6

  • Refactor typings

0.2.2 - 2019-08-17

  • Set default options parameter

0.2.1 - 2019-08-17

  • Update documentation

0.2.0 - 2019-08-17

  • Prepend noscript content instead of append

  • Accept parent tag option

0.1.1 - 2019-08-17

  • Validate plugin arguments

0.1.0 - 2019-08-16

  • Initial release