Skip to content

Commit 09921bb

Browse files
committed
switch to a generated source file for SHAs
1 parent b3128b0 commit 09921bb

4 files changed

Lines changed: 25 additions & 30 deletions

File tree

scripts/update-sha.sh

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
#!/bin/bash
22

3-
DOCS=www/src/content/docs/01-get-started/01-installation.md
3+
JSON=www/src/data/integrity.json
44

55
# Calculate SHAs
66
MINIFIED_SHA=$(cat dist/htmx.min.js | openssl dgst -sha384 -binary | openssl base64 -A)
77
FULL_SHA=$(cat dist/htmx.js | openssl dgst -sha384 -binary | openssl base64 -A)
88
ESM_MIN_SHA=$(cat dist/htmx.esm.min.js | openssl dgst -sha384 -binary | openssl base64 -A)
99
ESM_SHA=$(cat dist/htmx.esm.js | openssl dgst -sha384 -binary | openssl base64 -A)
1010

11-
echo "Updating $DOCS with new SHAs..."
11+
echo "Updating $JSON with new SHAs..."
1212
echo "htmx.min.js: sha384-$MINIFIED_SHA"
1313
echo "htmx.js: sha384-$FULL_SHA"
1414
echo "htmx.esm.min.js: sha384-$ESM_MIN_SHA"
1515
echo "htmx.esm.js: sha384-$ESM_SHA"
1616

17-
awk -v minified="sha384-$MINIFIED_SHA" -v full="sha384-$FULL_SHA" \
18-
-v esm_min="sha384-$ESM_MIN_SHA" -v esm="sha384-$ESM_SHA" '
19-
/integrity="sha384-[^"]*"/ && /htmx\.esm\.min\.js/ { sub(/sha384-[^"]*/, esm_min) }
20-
/integrity="sha384-[^"]*"/ && /htmx\.esm\.js/ && !/htmx\.esm\.min\.js/ { sub(/sha384-[^"]*/, esm) }
21-
/integrity="sha384-[^"]*"/ && /htmx\.min\.js/ && !/htmx\.esm/ { sub(/sha384-[^"]*/, minified) }
22-
/integrity="sha384-[^"]*"/ && /htmx\.js/ && !/htmx\.min\.js/ && !/htmx\.esm/ { sub(/sha384-[^"]*/, full) }
23-
/integrity="sha384-[^"]*"/ && /htmx\.org@/ && !/dist\// { sub(/sha384-[^"]*/, minified) }
24-
{print}
25-
' "$DOCS" > "$DOCS.tmp" && mv "$DOCS.tmp" "$DOCS"
17+
cat > "$JSON" <<EOF
18+
{
19+
"min": "sha384-$MINIFIED_SHA",
20+
"full": "sha384-$FULL_SHA",
21+
"esmMin": "sha384-$ESM_MIN_SHA",
22+
"esm": "sha384-$ESM_SHA"
23+
}
24+
EOF
2625

27-
echo "$DOCS updated successfully"
26+
echo "$JSON updated successfully"

www/src/components/CDNSnippet.astro

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
---
2-
import fs from 'node:fs';
3-
import path from 'node:path';
4-
import crypto from 'node:crypto';
52
import pkg from '../../../package.json';
3+
import integrity from '../data/integrity.json';
64
75
const CDN_URL = `https://cdn.jsdelivr.net/npm/htmx.org@${pkg.version}/dist/htmx.min.js`;
8-
9-
const distPath = path.resolve(import.meta.dirname, '../../../dist/htmx.min.js');
10-
const INTEGRITY = 'sha384-' + crypto.createHash('sha384').update(fs.readFileSync(distPath)).digest('base64');
6+
const INTEGRITY = integrity.min;
117
---
128

139
<!-- CDN one-liner: click anywhere to copy full <script> tag -->

www/src/content/docs/01-get-started/01-installation.md renamed to www/src/content/docs/01-get-started/01-installation.mdx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,28 @@ description: "Install htmx via CDN, npm, or direct download"
44
thumbnail: "docs/installation.svg"
55
keywords: [ "install", "setup", "cdn", "npm", "download", "getting started", "quick start" ]
66
---
7+
import { Code } from 'astro:components';
8+
import integrity from '../../../data/integrity.json';
79

810
htmx is a single JavaScript file with no dependencies. No build step is required to use it.
911

1012
## CDN
1113

1214
Add this in your `<head>` tag:
1315

14-
```html
15-
<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4" integrity="sha384-QSU8eEPO3hB2t20eEzufWO6ScLxBF2S8u7QHNNLRL4IET5zcvx444MHG6+fDzzTT" crossorigin="anonymous"></script>
16-
```
16+
<Code lang="html" code={`<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4" integrity="${integrity.min}" crossorigin="anonymous"></script>`} />
1717

1818
### Unminified
1919

20-
```html
21-
<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.js" integrity="sha384-G5PQhA8wo5Dkem9VtU3izHNsalIpaptQKXnc/cj8QRc9XeJX2KTO3Pr2KS2A6Eif" crossorigin="anonymous"></script>
22-
```
20+
<Code lang="html" code={`<script src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.js" integrity="${integrity.full}" crossorigin="anonymous"></script>`} />
2321

2422
### ES Module
2523

26-
```html
27-
<script type="module" src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.min.js" integrity="sha384-E+JDpCUAgcyKFT22Xh4zlu3I5xV0JfjDHlB3jqwPIAemJxXq2Ovlsw8x3DbQ3tc1" crossorigin="anonymous"></script>
28-
```
24+
<Code lang="html" code={`<script type="module" src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.min.js" integrity="${integrity.esmMin}" crossorigin="anonymous"></script>`} />
2925

3026
### ES Module (unminified)
3127

32-
```html
33-
<script type="module" src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.js" integrity="sha384-b3Sl18uCZMYg5GnkP+EDF3gyiYazT9PHLZ0JV75UnL+LP1WGIIxUqTXL7MqM67Ed" crossorigin="anonymous"></script>
34-
```
28+
<Code lang="html" code={`<script type="module" src="https://cdn.jsdelivr.net/npm/htmx.org@4.0.0-beta4/dist/htmx.esm.js" integrity="${integrity.esm}" crossorigin="anonymous"></script>`} />
3529

3630
## Download
3731

www/src/data/integrity.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"min": "sha384-aWZK1NtOs/aWb/+YZdTM8q2JkWEshlMc9mgZ189numT9bwFhyAyYEoO4nO/2dTXt",
3+
"full": "sha384-OFLRIZpuqI2wwFozxvDGcuF3TQ36ySMgp44WEthOiR4wFzRkhZbK72HFaBo2C3cx",
4+
"esmMin": "sha384-md54RSbheZ0Mpr9oo11vo7Cvrz9acwqg8tSLEoFeo1R6FsZmD3jFVKokISxCeT6Q",
5+
"esm": "sha384-S5fILq7gG/U3b/j34NWMf77PgT3ojxi6CQxRFhqRLklkKJ+3KujL7RaZOgV2cmkz"
6+
}

0 commit comments

Comments
 (0)