minify_json_tags
This script will minify JSON-structured script tags in the given HTML file.
<html>
…
<script type="importmap">
{
"imports": {
"utils": "/j/utils.mjs"
}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://sdavids.de/"
}
</script>
…
</html>
⇓
<html>
…
<script type="importmap">{"imports":{"utils":"/j/utils.mjs"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"Organization","url":"https://sdavids.de/"}</script>
…
</html>
Usage
$ node scripts/web/minify_json_tags.mjs dist/index.html
$ find dist -type f -name '*.html' -exec node scripts/web/minify_json_tags.mjs {} \;