Releases: posthtml/posthtml-hash
Releases · posthtml/posthtml-hash
v1.2.2
v1.2.1
Fixes
- use previously hashed file name if it exists
Unprocessed HTML:
<meta property="og:image" content="https://example.com/image.[hash].png" />
<meta property="twitter:image" content="https://example.com/image.[hash].png" />
Processed HTML:
<meta property="og:image" content="https://example.com/image.1fa9a3.png">
<meta property="twitter:image" content="https://example.com/image.1fa9a3.png">
v1.2.0
Features
- Expand attribute matchers (
href
,src
) to include "content" - Add optional
transformPath
method to modify matched attribute values for local file resolution
The transformPath
can be used to manipulate and filter matching attribute values. In the following example, asset names with remote origins can be resolved locally and hashed.
Unprocessed HTML file:
<!-- build/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta property="og:image" content="https://example.com/image.[hash].png" />
</head>
<body></body>
</html>
Post-build script:
posthtml()
.use(
hash({
hashLength: 6,
transformPath: (filepath) => {
// removes the targeted remote origin URL when looking up the files locally
return filepath.replace("https://example.com/", "");
},
})
)
.process(html)
.then((result) => fs.writeFileSync("./build/index.html", result.html));
Processed HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta property="og:image" content="https://example.com/image.1fa9a3.png">
</head>
<body></body>
</html>
Housekeeping
- Upgrade
posthtml
,typescript
versions