@@ -13,45 +13,74 @@ permissions:
1313# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
1414# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
1515concurrency :
16- group : " pages"
17- cancel-in-progress : false
16+ group : pages-${{ github.ref }}
17+ cancel-in-progress : true
1818
1919jobs :
20- # Build job
20+ # Build and optimize job
2121 build :
2222 runs-on : ubuntu-latest
2323 steps :
2424 - name : Checkout
2525 uses : actions/checkout@v4
26-
27- - name : Setup Ruby
28- uses : ruby /setup-ruby@v1
26+
27+ - name : Setup Node.js
28+ uses : actions /setup-node@v4
2929 with :
30- ruby-version : ' 3.1'
31- bundler-cache : true
30+ node-version : ' 18'
31+ cache : ' npm'
32+
33+ - name : Install build dependencies
34+ run : |
35+ npm init -y
36+ npm install --save-dev html-minifier-terser clean-css-cli terser html-validate
37+
38+ - name : Validate HTML files
39+ run : |
40+ echo "Validating HTML files..."
41+ npx html-validate *.html pages/*.html || echo "HTML validation completed with warnings"
42+
43+ - name : Optimize assets
44+ run : |
45+ echo "Optimizing HTML files..."
46+ # Create backup directory
47+ mkdir -p .backup
48+
49+ # Minify HTML files (preserve original structure)
50+ find . -name "*.html" -not -path "./node_modules/*" -not -path "./.backup/*" | while read file; do
51+ echo "Minifying: $file"
52+ npx html-minifier-terser \
53+ --collapse-whitespace \
54+ --remove-comments \
55+ --remove-optional-tags \
56+ --remove-redundant-attributes \
57+ --remove-script-type-attributes \
58+ --remove-style-link-type-attributes \
59+ --minify-css \
60+ --minify-js \
61+ "$file" -o "$file.tmp" && mv "$file.tmp" "$file"
62+ done
3263
64+ # Minify CSS files if any exist
65+ if find . -name "*.css" -not -path "./node_modules/*" -not -path "./.backup/*" | grep -q .; then
66+ echo "Optimizing CSS files..."
67+ find . -name "*.css" -not -path "./node_modules/*" -not -path "./.backup/*" | while read file; do
68+ echo "Minifying: $file"
69+ npx cleancss "$file" -o "$file"
70+ done
71+ fi
72+
73+ # Remove build dependencies from final artifact
74+ rm -rf node_modules package*.json
75+
3376 - name : Setup Pages
3477 id : pages
3578 uses : actions/configure-pages@v4
36-
37- - name : Install dependencies
38- run : |
39- gem install jekyll bundler
40- bundle init
41- echo 'gem "jekyll", "~> 4.3"' >> Gemfile
42- echo 'gem "minima", "~> 2.5"' >> Gemfile
43- echo 'gem "jekyll-feed"' >> Gemfile
44- echo 'gem "jekyll-sitemap"' >> Gemfile
45- echo 'gem "jekyll-seo-tag"' >> Gemfile
46- bundle install
47-
48- - name : Build with Jekyll
49- run : bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
50- env :
51- JEKYLL_ENV : production
52-
79+
5380 - name : Upload artifact
5481 uses : actions/upload-pages-artifact@v3
82+ with :
83+ path : ' .'
5584
5685 # Deployment job
5786 deploy :
6089 url : ${{ steps.deployment.outputs.page_url }}
6190 runs-on : ubuntu-latest
6291 needs : build
63- if : github.ref == 'refs/heads/main'
6492 steps :
6593 - name : Deploy to GitHub Pages
6694 id : deployment
0 commit comments