Skip to content

narrowFilterBandwidthHz was too narrow #62

narrowFilterBandwidthHz was too narrow

narrowFilterBandwidthHz was too narrow #62

Workflow file for this run

name: Inline & Package HTML (minify + inline assets)
# allow workflow to write back to the repository
permissions:
contents: write
on:
workflow_dispatch:
inputs:
target_folder:
description: 'Folder to minify'
required: false
default: '.'
index_file:
description: 'HTML entry file to inline (relative to repo root)'
required: false
default: 'index.html'
output_file:
description: 'Output inlined HTML filename'
required: false
default: 'package.html'
push:
paths:
- '**.js'
- '**.css'
branches:
- main
jobs:
minify-and-inline:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install tools (terser, clean-css, html-minifier-terser)
run: |
npm install -g terser
npm install -g clean-css-cli
npm install -g html-minifier-terser
npm install --no-save cheerio # <-- add cheerio to runtime deps
- name: Minify JavaScript
run: |
FOLDER="${{ github.event.inputs.target_folder || '.' }}"
FOLDER=${FOLDER:-.}
find "$FOLDER" -name "*.js" ! -name "*.min.js" -exec sh -c '
for f; do
terser "$f" -o "${f%.js}.min.js" --compress --mangle --comments false
done
' sh {} +
- name: Minify CSS
run: |
FOLDER="${{ github.event.inputs.target_folder || '.' }}"
FOLDER=${FOLDER:-.}
find "$FOLDER" -name "*.css" ! -name "*.min.css" -exec sh -c '
for f; do
echo "Minifying: $f"
# use a supported option (or omit options entirely)
cleancss -o "${f%.css}.min.css" "$f"
done
' sh {} +
- name: Create inline-assets script
run: |
mkdir -p .github/workflows/tmp
cat > .github/workflows/tmp/inline-assets.js <<'NODE'
const fs = require('fs');
const path = require('path');
const cheerio = require('cheerio');
const indexFile = process.argv[2] || 'index.html';
const outFile = process.argv[3] || 'package.html';
if(!fs.existsSync(indexFile)) {
console.error('Index file not found:', indexFile);
process.exit(2);
}
const baseDir = path.dirname(indexFile);
let html = fs.readFileSync(indexFile, 'utf8');
const $ = cheerio.load(html, { decodeEntities: false });
// inline scripts
$('script[src]').each((i, el) => {
const src = $(el).attr('src');
if (!src || /^https?:\/\//i.test(src)) return; // skip external
const srcPath = path.resolve(baseDir, src);
const minPath = srcPath.replace(/\.js$/, '.min.js');
const usePath = fs.existsSync(minPath) ? minPath : (fs.existsSync(srcPath) ? srcPath : null);
if (usePath) {
const code = fs.readFileSync(usePath, 'utf8');
$(el).replaceWith(`<script>${code}</script>`);
}
});
// inline stylesheets (rel="stylesheet" or type="text/css")
$('link[href]').each((i, el) => {
const rel = ($(el).attr('rel') || '').toLowerCase();
const type = ($(el).attr('type') || '').toLowerCase();
if (rel !== 'stylesheet' && type !== 'text/css') return; // not a CSS link
const href = $(el).attr('href');
if (!href || /^https?:\/\//i.test(href)) return; // skip external
const hrefPath = path.resolve(baseDir, href);
const minPath = hrefPath.replace(/\.css$/, '.min.css');
const usePath = fs.existsSync(minPath) ? minPath : (fs.existsSync(hrefPath) ? hrefPath : null);
if (usePath) {
const css = fs.readFileSync(usePath, 'utf8');
$(el).replaceWith(`<style>${css}</style>`);
}
});
// write out
fs.writeFileSync(outFile, $.html(), 'utf8');
console.log('Wrote', outFile);
NODE
- name: Inline minified assets into HTML
run: |
INDEX_FILE="${{ github.event.inputs.index_file || 'index.html' }}"
OUT_FILE="${{ github.event.inputs.output_file || 'package.html' }}"
node .github/workflows/tmp/inline-assets.js "$INDEX_FILE" "$OUT_FILE"
- name: Minify inlined HTML
run: |
OUT="${{ github.event.inputs.output_file || 'package.html' }}"
if [ -f "$OUT" ]; then
html-minifier-terser "$OUT" \
--collapse-whitespace \
--remove-comments \
--minify-css true \
--minify-js true \
--remove-optional-tags \
-o "$OUT"
echo "Minified $OUT"
else
echo "$OUT not found, skipping minify"
fi
- name: Show output file size
run: |
OUT="${{ github.event.inputs.output_file || 'package.html' }}"
ls -lh "$OUT" || true
wc -c "$OUT" || true
- name: Upload packaged artifact
uses: actions/upload-artifact@v4
with:
name: packaged-html
path: ${{ github.event.inputs.output_file || 'package.html' }}
- name: Commit and push generated files (always run)
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
OUT="${{ github.event.inputs.output_file || 'package.html' }}"
# add generated assets and the packaged HTML output to the repo
git add '*.min.js' '*.min.css' "$OUT" || true
if git diff --cached --quiet; then
echo "No generated file changes to commit."
else
git commit -m "auto-minified and packaged: $OUT [skip ci]"
git push origin HEAD:${{ github.ref_name || 'main' }}
fi