You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-14Lines changed: 25 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,23 +29,23 @@ npm i -D posthtml-hash
29
29
30
30
### Input
31
31
32
-
By default, the plugin will attempt to hash file names that contain `[hash]`. As a qualifier, only nodes with a `href`or `src` attribute are considered.
32
+
By default, the plugin will attempt to hash file names that contain `[hash]`. As an additional qualifier, only nodes containing `href`, `src`, or `content` attributes are eligible.
33
33
34
34
```html
35
35
<html>
36
36
<head>
37
-
<!-- not hashed -->
38
-
<linkrel="stylesheet"href="reset.css" />
39
-
40
37
<!-- hashed -->
41
38
<linkrel="stylesheet"href="style.[hash].css" />
39
+
40
+
<!-- not hashed -->
41
+
<linkrel="stylesheet"href="reset.css" />
42
42
</head>
43
43
<body>
44
-
<!-- not hashed -->
45
-
<scriptsrc="analytics.js"></script>
46
-
47
44
<!-- hashed -->
48
45
<scriptsrc="src.[hash].js"></script>
46
+
47
+
<!-- not hashed -->
48
+
<scriptsrc="analytics.js"></script>
49
49
</body>
50
50
</html>
51
51
```
@@ -85,7 +85,7 @@ For convenience, you can add the post-build script to your package.json. The `po
85
85
86
86
Customize the hash length by specifying an integer after the `hash:{NUMBER}`. The default hash length is `20`.
87
87
88
-
**Note**: This only works for a pattern that uses square brackets and a colon separator. Use the `hashLength` option for other use cases.
88
+
**Note**: This only works for a pattern that uses square brackets and a colon separator. Use the `hashLength` option for different patterns.
89
89
90
90
```html
91
91
<scriptsrc="src.[hash].js"></script>
@@ -102,19 +102,28 @@ This plugin assumes that the file to process is in the same directory as the Pos
102
102
```js
103
103
hash({
104
104
/**
105
-
* Relative path to processed HTML file
105
+
* Relative path to the HTML file being processed
106
+
* @default""
106
107
*/
107
-
path:"public",// default: ""
108
+
path:"public",
108
109
109
110
/**
110
111
* File name pattern (regular expression) to match
112
+
* @defaultnew RegExp(/\[hash.*]/g)
111
113
*/
112
-
pattern:newRegExp(/\custom-file-pattern/),// default: new RegExp(/\[hash.*]/g)
114
+
pattern:newRegExp(/custom-file-pattern/),
113
115
114
116
/**
115
-
* Custom hash length
117
+
* Hash length
118
+
* @default20
116
119
*/
117
-
hashLength:8, // default: 20
120
+
hashLength:8,
121
+
122
+
/**
123
+
* Transform the href/src/content attribute value to a relative file path
> Basic usage of the [posthtml-hash](../..) plugin.
4
+
5
+
The assets in the [original/](original) folder contains unprocessed assets for reference; they are not directly manipulated in this example. The corresponding output is the [processed/](processed) folder.
6
+
7
+
## Use case
8
+
9
+
This example illustrates hashing images that retain a remote origin URL. A common use case is [Open Graph tags](https://ogp.me/), where the meta `og:image` value must include a remote origin (i.e. "https://example.com").
10
+
11
+
The sample images are from [placeholder.com](https://placeholder.com/).
12
+
13
+
## Script
14
+
15
+
The [script.js](script.js) file contains the script that runs posthtml.
0 commit comments