Skip to content

Add LinkedIn Insight Tag integration to footer for enhanced tracking … #156

Add LinkedIn Insight Tag integration to footer for enhanced tracking …

Add LinkedIn Insight Tag integration to footer for enhanced tracking … #156

name: Minify and Deploy to GitHub Pages
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
minify-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: |
npm install -g clean-css-cli terser
- name: Create minified CSS files
run: |
# Create minified versions of all CSS files except themes.css
for file in css/*.css; do
if [ -f "$file" ] && [ "$(basename "$file")" != "themes.css" ]; then
echo "Minifying $file..."
cleancss --compatibility "*" -o "${file%.css}.min.css" "$file"
fi
done
# Handle planet-styles subdirectory
for file in css/planet-styles/*.css; do
if [ -f "$file" ]; then
echo "Minifying $file..."
cleancss --compatibility "*" -o "${file%.css}.min.css" "$file"
fi
done
- name: Create minified JS files
run: |
# Create minified versions of all JS files
for file in js/*.js; do
if [ -f "$file" ]; then
echo "Minifying $file..."
terser "$file" -o "${file%.js}.min.js" --compress --mangle
fi
done
- name: Update HTML files to use minified versions
run: |
# Update all HTML files to reference minified CSS and JS (only local files)
find . -name "*.html" -type f | while read file; do
echo "Updating $file..."
# Replace local CSS references (avoid external CDN files)
sed -i 's/href="css\/\([^"]*\)\.css"/href="css\/\1\.min\.css"/g' "$file"
sed -i "s/href='css\/\([^']*\)\.css'/href='css\/\1\.min\.css'/g" "$file"
# Replace local JS references
sed -i 's/src="js\/\([^"]*\)\.js"/src="js\/\1\.min\.js"/g' "$file"
sed -i "s/src='js\/\([^']*\)\.js'/src='js\/\1\.min\.js'/g" "$file"
# Revert themes.css back to original (since we didn't minify it)
sed -i 's/themes\.min\.css"/themes\.css"/g' "$file"
sed -i "s/themes\.min\.css'/themes\.css'/g" "$file"
done
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Check if minified branch exists
id: check-branch
run: |
if git ls-remote --heads origin minified | grep -q minified; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Push to minified branch (new branch)
if: steps.check-branch.outputs.exists == 'false'
run: |
git add -A
git diff --quiet && git diff --staged --quiet || git commit -m "Minify CSS and JS files [skip ci]"
git push origin HEAD:minified
- name: Push to minified branch (existing branch)
if: steps.check-branch.outputs.exists == 'true'
run: |
git add -A
git diff --quiet && git diff --staged --quiet || git commit -m "Minify CSS and JS files [skip ci]"
git push origin HEAD:minified --force
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Checkout minified branch
uses: actions/checkout@v4
with:
ref: minified
token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: .
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4