https://github.com/posthtml/posthtml-cache
Add a nanoid to links in you tags
https://github.com/posthtml/posthtml-cache
cache html link nanoid posthtml posthtml-cache
Last synced: 10 months ago
JSON representation
Add a nanoid to links in you tags
- Host: GitHub
- URL: https://github.com/posthtml/posthtml-cache
- Owner: posthtml
- License: mit
- Created: 2017-12-08T14:15:09.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T02:30:19.000Z (almost 3 years ago)
- Last Synced: 2025-04-11T20:52:18.871Z (10 months ago)
- Topics: cache, html, link, nanoid, posthtml, posthtml-cache
- Language: JavaScript
- Homepage:
- Size: 2.75 MB
- Stars: 11
- Watchers: 2
- Forks: 5
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
# posthtml-cache
> A posthtml plugin for add nanoid to style & script links and you tags...
[](https://travis-ci.org/posthtml/posthtml-cache)[]()[](https://www.npmjs.com/package/posthtml-cache)[](https://david-dm.org/posthtml/posthtml-cache)[](https://github.com/sindresorhus/xo)[](https://coveralls.io/r/posthtml/posthtml-cache)
## Why?
## Install
```bash
npm i -S posthtml posthtml-cache
```
> **Note:** This project is compatible with node v10+
## Usage
```js
import {readFileSync, writeFileSync} from 'fs';
import posthtml from 'posthtml';
import posthtmlCache from 'posthtml-cache';
const html = readFileSync('input.html', 'utf8');
posthtml()
.use(posthtmlCache(/* options */))
.process(html)
.then(result => {
writeFileSync('output.html', result.html);
});
```
## Example
input.html
```html
```
output.html
```html
```
> *will be added nanoid to all the file link*
## Options
### `tags`
Type: `Array`
Default: `['script', 'link']`
Description: *You can also expand the list by adding the tags you need...*
### `attributes`
Type: `Array`
Default: `['src', 'href']`
Description: *You can also expand the list by adding the attributes you need...*
### `exclude`
Type: `Array`
Default: `[]`
Description: *You can also exclude the list by adding the tags you need...*
### `onlyInternal`
Type: `Array`
Default: `[]`
Description: *If you have external URL-s, some won't work if you add nanoid to them. If this list is empty, all external links are modified. Otherwise, only the URL-s starting with items in the array (case insensitive) will be modified. E.g. `['https://github.com/']` will add nanoid to all local links and only to `https://github.com/*`. It won't add nanoid to e.g. `http://github.com` or `https://fonts.google.com`. For simplicity, a link is considered external if it starts with a protocol (see [is-absolute-url](https://www.npmjs.com/package/is-absolute-url)) or with double slash `//`.*