Skip to content

Releases: posthtml/posthtml-hash

v1.2.2

25 Nov 22:00
Compare
Choose a tag to compare

Republish.

v1.2.1

25 Nov 21:56
Compare
Choose a tag to compare

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

25 Nov 18:46
Compare
Choose a tag to compare

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