Skip to content

Commit 464a1ce

Browse files
committed
docs: add custom-hash to examples
1 parent 5f39ba0 commit 464a1ce

10 files changed

Lines changed: 278 additions & 0 deletions

File tree

examples/custom-hash/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules
2+
.DS_Store
3+
yarn-debug.log*
4+
yarn-error.log*

examples/custom-hash/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# examples/basic
2+
3+
> 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+
## Script
8+
9+
The [script.js](script.js) file contains the script that runs posthtml.
10+
11+
```js
12+
// script.js
13+
const fs = require("fs");
14+
const posthtml = require("posthtml");
15+
const { hash } = require("posthtml-hash");
16+
17+
const html = fs.readFileSync("./processed/index.html");
18+
19+
posthtml()
20+
.use(hash({ path: "processed", pattern: new RegExp(/custom-hash/) }))
21+
.process(html)
22+
.then((result) => fs.writeFileSync("./processed/index.html", result.html));
23+
```
24+
25+
## Running Locally
26+
27+
Clone the repo and install the dependencies:
28+
29+
```bash
30+
git clone git@github.com:posthtml/posthtml-hash.git
31+
cd posthtml-hash/examples/basic
32+
yarn install
33+
```
34+
35+
Run the script:
36+
37+
```bash
38+
yarn hash
39+
```
40+
41+
To restore the processed folder to its unprocessed state, run:
42+
43+
```bash
44+
yarn clean
45+
```

examples/custom-hash/clean.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const fs = require('fs-extra');
2+
3+
fs.removeSync('processed');
4+
fs.copySync('original', 'processed');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link
6+
rel="stylesheet"
7+
href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,600,600i,700,700i"
8+
/>
9+
</head>
10+
<body>
11+
<script src="main.custom-hash.js"></script>
12+
</body>
13+
</html>

examples/custom-hash/original/main.custom-hash.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-hash/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "custom-hash",
3+
"version": "1.0.0",
4+
"main": "script.js",
5+
"private": true,
6+
"scripts": {
7+
"clean": "node clean.js",
8+
"hash": "node script.js"
9+
},
10+
"devDependencies": {
11+
"fs-extra": "^9.0.0",
12+
"posthtml": "^0.13.0",
13+
"posthtml-hash": "../../"
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,400i,600,600i,700,700i">
6+
</head>
7+
<body>
8+
<script src="main.b0dcc67ffc1fd562f212.js"></script>
9+
</body>
10+
</html>

examples/custom-hash/processed/main.b0dcc67ffc1fd562f212.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/custom-hash/script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require("fs");
2+
const posthtml = require("posthtml");
3+
const { hash } = require("posthtml-hash");
4+
5+
const html = fs.readFileSync("./processed/index.html");
6+
7+
posthtml()
8+
.use(hash({ path: "processed", pattern: new RegExp(/custom-hash/) }))
9+
.process(html)
10+
.then((result) => fs.writeFileSync("./processed/index.html", result.html));

examples/custom-hash/yarn.lock

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
at-least-node@^1.0.0:
6+
version "1.0.0"
7+
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
8+
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
9+
10+
dom-serializer@0:
11+
version "0.2.2"
12+
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.2.tgz#1afb81f533717175d478655debc5e332d9f9bb51"
13+
integrity sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==
14+
dependencies:
15+
domelementtype "^2.0.1"
16+
entities "^2.0.0"
17+
18+
domelementtype@1, domelementtype@^1.3.1:
19+
version "1.3.1"
20+
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.1.tgz#d048c44b37b0d10a7f2a3d5fee3f4333d790481f"
21+
integrity sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==
22+
23+
domelementtype@^2.0.1:
24+
version "2.0.1"
25+
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.0.1.tgz#1f8bdfe91f5a78063274e803b4bdcedf6e94f94d"
26+
integrity sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==
27+
28+
domhandler@^2.3.0:
29+
version "2.4.2"
30+
resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.4.2.tgz#8805097e933d65e85546f726d60f5eb88b44f803"
31+
integrity sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==
32+
dependencies:
33+
domelementtype "1"
34+
35+
domutils@^1.5.1:
36+
version "1.7.0"
37+
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a"
38+
integrity sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==
39+
dependencies:
40+
dom-serializer "0"
41+
domelementtype "1"
42+
43+
entities@^1.1.1:
44+
version "1.1.2"
45+
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
46+
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==
47+
48+
entities@^2.0.0:
49+
version "2.0.3"
50+
resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.3.tgz#5c487e5742ab93c15abb5da22759b8590ec03b7f"
51+
integrity sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ==
52+
53+
fs-extra@^9.0.0:
54+
version "9.0.1"
55+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
56+
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
57+
dependencies:
58+
at-least-node "^1.0.0"
59+
graceful-fs "^4.2.0"
60+
jsonfile "^6.0.1"
61+
universalify "^1.0.0"
62+
63+
graceful-fs@^4.1.6, graceful-fs@^4.2.0:
64+
version "4.2.4"
65+
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
66+
integrity sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==
67+
68+
hasha@^5.0.0:
69+
version "5.2.0"
70+
resolved "https://registry.yarnpkg.com/hasha/-/hasha-5.2.0.tgz#33094d1f69c40a4a6ac7be53d5fe3ff95a269e0c"
71+
integrity sha512-2W+jKdQbAdSIrggA8Q35Br8qKadTrqCTC8+XZvBWepKDK6m9XkX6Iz1a2yh2KP01kzAR/dpuMeUnocoLYDcskw==
72+
dependencies:
73+
is-stream "^2.0.0"
74+
type-fest "^0.8.0"
75+
76+
htmlparser2@^3.9.2:
77+
version "3.10.1"
78+
resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.10.1.tgz#bd679dc3f59897b6a34bb10749c855bb53a9392f"
79+
integrity sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==
80+
dependencies:
81+
domelementtype "^1.3.1"
82+
domhandler "^2.3.0"
83+
domutils "^1.5.1"
84+
entities "^1.1.1"
85+
inherits "^2.0.1"
86+
readable-stream "^3.1.1"
87+
88+
inherits@^2.0.1, inherits@^2.0.3:
89+
version "2.0.4"
90+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
91+
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
92+
93+
is-stream@^2.0.0:
94+
version "2.0.0"
95+
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3"
96+
integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw==
97+
98+
jsonfile@^6.0.1:
99+
version "6.0.1"
100+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179"
101+
integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==
102+
dependencies:
103+
universalify "^1.0.0"
104+
optionalDependencies:
105+
graceful-fs "^4.1.6"
106+
107+
posthtml-hash@../../:
108+
version "1.1.0"
109+
dependencies:
110+
hasha "^5.0.0"
111+
posthtml "^0.12.0"
112+
113+
posthtml-parser@^0.4.2:
114+
version "0.4.2"
115+
resolved "https://registry.yarnpkg.com/posthtml-parser/-/posthtml-parser-0.4.2.tgz#a132bbdf0cd4bc199d34f322f5c1599385d7c6c1"
116+
integrity sha512-BUIorsYJTvS9UhXxPTzupIztOMVNPa/HtAm9KHni9z6qEfiJ1bpOBL5DfUOL9XAc3XkLIEzBzpph+Zbm4AdRAg==
117+
dependencies:
118+
htmlparser2 "^3.9.2"
119+
120+
posthtml-render@^1.2.2:
121+
version "1.2.2"
122+
resolved "https://registry.yarnpkg.com/posthtml-render/-/posthtml-render-1.2.2.tgz#f554a19ed40d40e2bfc160826b0a91d4a23656cd"
123+
integrity sha512-MbIXTWwAfJ9qET6Zl29UNwJcDJEEz9Zkr5oDhiujitJa7YBJwEpbkX2cmuklCDxubTMoRWpid3q8DrSyGnUUzQ==
124+
125+
posthtml@^0.12.0:
126+
version "0.12.3"
127+
resolved "https://registry.yarnpkg.com/posthtml/-/posthtml-0.12.3.tgz#8fa5b903907e9c10ba5b883863cc550189a309d5"
128+
integrity sha512-Fbpi95+JJyR0tqU7pUy1zTSQFjAsluuwB9pJ1h0jtnGk7n/O2TBtP5nDl9rV0JVACjQ1Lm5wSp4ppChr8u3MhA==
129+
dependencies:
130+
posthtml-parser "^0.4.2"
131+
posthtml-render "^1.2.2"
132+
133+
posthtml@^0.13.0:
134+
version "0.13.1"
135+
resolved "https://registry.yarnpkg.com/posthtml/-/posthtml-0.13.1.tgz#3b85df6b0e084370a713302043c1c0f47cbaa5a8"
136+
integrity sha512-8aJZ63WYL9YsAZVcrIn6U0dSYbna7hcTceZjnbH7dilg01t4t3JDx0UovbhGFscFJg/++qhECCjGEQuJAqD7dA==
137+
dependencies:
138+
posthtml-parser "^0.4.2"
139+
posthtml-render "^1.2.2"
140+
141+
readable-stream@^3.1.1:
142+
version "3.6.0"
143+
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
144+
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
145+
dependencies:
146+
inherits "^2.0.3"
147+
string_decoder "^1.1.1"
148+
util-deprecate "^1.0.1"
149+
150+
safe-buffer@~5.2.0:
151+
version "5.2.1"
152+
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
153+
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
154+
155+
string_decoder@^1.1.1:
156+
version "1.3.0"
157+
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.3.0.tgz#42f114594a46cf1a8e30b0a84f56c78c3edac21e"
158+
integrity sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==
159+
dependencies:
160+
safe-buffer "~5.2.0"
161+
162+
type-fest@^0.8.0:
163+
version "0.8.1"
164+
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
165+
integrity sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==
166+
167+
universalify@^1.0.0:
168+
version "1.0.0"
169+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
170+
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
171+
172+
util-deprecate@^1.0.1:
173+
version "1.0.2"
174+
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
175+
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

0 commit comments

Comments
 (0)