Skip to content

Commit d4d8938

Browse files
committed
docs(readme): update description
1 parent e0d060e commit d4d8938

1 file changed

Lines changed: 18 additions & 36 deletions

File tree

README.md

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
# posthtml-hash <img align="right" width="220" height="200" title="PostHTML logo" src="http://posthtml.github.io/posthtml/logo.svg">
22

33
[![NPM][npm]][npm-url]
4-
[![Deps][deps]][deps-url]
54
[![Build][build]][build-badge]
65
[![Coverage][codecov-shield]][codecov]
76

8-
`posthtml-hash` is a [PostHTML](https://github.com/posthtml/posthtml) plugin for hashing static assets. This plugin uses [hasha](https://www.npmjs.com/package/hasha) to generate unique hashes.
7+
`posthtml-hash` is a [PostHTML](https://github.com/posthtml/posthtml) plugin for hashing static CSS/JS assets to enable caching. [hasha](https://www.npmjs.com/package/hasha) is used to generate hashes.
98

10-
Currently, this plugin supports CSS and JS files.
11-
12-
**Before:**
13-
14-
```html
15-
<html>
16-
<head>
17-
<link rel="stylesheet" href="stylesheet.css" />
18-
</head>
19-
<body>
20-
<script src="main.js"></script>
21-
</body>
22-
</html>
23-
```
24-
25-
**After:**
26-
27-
```html
9+
```diff
2810
<html>
2911
<head>
30-
<link rel="stylesheet" href="stylesheet.9a6cf95c41e87b9dc102.css" />
12+
- <link rel="stylesheet" href="stylesheet.css" />
13+
+ <link rel="stylesheet" href="stylesheet.9a6cf95c41e87b9dc102.css" />
3114
</head>
3215
<body>
33-
<script src="main.b0dcc67ffc1fd562f212.js"></script>
16+
- <script src="main.js"></script>
17+
+ <script src="main.b0dcc67ffc1fd562f212.js"></script>
3418
</body>
3519
</html>
3620
```
@@ -46,46 +30,46 @@ npm i posthtml-hash
4630
## Usage
4731

4832
```js
49-
const fs = require('fs');
50-
const posthtml = require('posthtml');
51-
const { hash } = require('posthtml-hash');
33+
const fs = require("fs");
34+
const posthtml = require("posthtml");
35+
const { hash } = require("posthtml-hash");
5236

53-
const html = fs.readFileSync('./index.html');
37+
const html = fs.readFileSync("./index.html");
5438

5539
posthtml()
5640
.use(hash())
5741
.process(html)
58-
.then(result => fs.writeFileSync('./index.html', result.html));
42+
.then((result) => fs.writeFileSync("./index.html", result.html));
5943
```
6044

6145
## Options
6246

6347
This plugin assumes that the file to process is in the same directory as the posthtml script. If not, specify the relative path to the html file in `options.path`:
6448

6549
```js
66-
const fs = require('fs');
67-
const posthtml = require('posthtml');
68-
const { hash } = require('posthtml-hash');
50+
const fs = require("fs");
51+
const posthtml = require("posthtml");
52+
const { hash } = require("posthtml-hash");
6953

70-
const html = fs.readFileSync('./public/index.html');
54+
const html = fs.readFileSync("./public/index.html");
7155

7256
posthtml()
7357
.use(
7458
hash({
7559
/**
7660
* Relative path to processed HTML file
7761
*/
78-
path: 'public',
62+
path: "public",
7963

8064
/**
8165
* Length of hash
8266
* Default is 20
8367
*/
84-
hashLength: 10
68+
hashLength: 10,
8569
})
8670
)
8771
.process(html)
88-
.then(result => fs.writeFileSync('./index.html', result.html));
72+
.then((result) => fs.writeFileSync("./index.html", result.html));
8973
```
9074

9175
## [Examples](examples)
@@ -102,8 +86,6 @@ See the [PostHTML Guidelines](https://github.com/posthtml/posthtml/tree/master/d
10286

10387
[npm]: https://img.shields.io/npm/v/posthtml-hash.svg?color=blue
10488
[npm-url]: https://npmjs.com/package/posthtml-hash
105-
[deps]: https://david-dm.org/posthtml/posthtml-hash.svg
106-
[deps-url]: https://david-dm.org/posthtml/posthtml-hash
10789
[build]: https://travis-ci.com/posthtml/posthtml-hash.svg?branch=master
10890
[build-badge]: https://travis-ci.com/posthtml/posthtml-hash
10991
[codecov]: https://codecov.io/gh/posthtml/posthtml-hash

0 commit comments

Comments
 (0)