Skip to content

Commit 94762d1

Browse files
committed
Optimize PageSpeed.
1 parent f22e220 commit 94762d1

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

.githooks/pre-commit

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Digital Bazaar — Pre-commit Hook
3+
# Ensures assets are optimized and site builds before committing
4+
5+
set -e
6+
7+
echo "🔍 Running pre-commit checks..."
8+
9+
# Colors
10+
RED='\033[0;31m'
11+
GREEN='\033[0;32m'
12+
YELLOW='\033[0;33m'
13+
NC='\033[0m' # No Color
14+
15+
# Check if image source files changed
16+
IMAGES_CHANGED=$(git diff --cached --name-only | grep -E "assets/img/digital_bazaar.*\.(jpg|png)$" || true)
17+
18+
if [ -n "$IMAGES_CHANGED" ]; then
19+
echo -e "${YELLOW}📷 Image source files changed, optimizing...${NC}"
20+
make images
21+
make images-webp
22+
# Stage the generated files
23+
git add assets/img/*.webp assets/img/logo-*.jpg assets/img/favicon-*.png assets/img/apple-touch-icon.png 2>/dev/null || true
24+
fi
25+
26+
# Check if any content/style files changed
27+
CONTENT_CHANGED=$(git diff --cached --name-only | grep -E "\.(html|md|yml|scss|css)$" || true)
28+
29+
if [ -n "$CONTENT_CHANGED" ] || [ -n "$IMAGES_CHANGED" ]; then
30+
echo -e "${YELLOW}🔨 Building for production...${NC}"
31+
make prod-build
32+
33+
if [ $? -eq 0 ]; then
34+
echo -e "${GREEN}✅ Production build successful${NC}"
35+
else
36+
echo -e "${RED}❌ Production build failed${NC}"
37+
exit 1
38+
fi
39+
else
40+
echo -e "${GREEN}✅ No content changes, skipping build${NC}"
41+
fi
42+
43+
echo -e "${GREEN}✅ Pre-commit checks passed${NC}"
44+

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Digital Bazaar — Makefile
22
# Simplifies common development tasks
33

4-
.PHONY: help install update build serve clean fonts prod-build serve-drafts images images-webp
4+
.PHONY: help install update build serve clean fonts prod-build serve-drafts images images-webp setup-hooks
55

66
# Homebrew Ruby paths (macOS)
77
RUBY_BIN := /opt/homebrew/opt/ruby/bin
@@ -63,6 +63,11 @@ images-webp: ## Convert images to WebP (requires: brew install webp)
6363
@cd assets/img && \
6464
cwebp -q 80 logo-128.jpg -o logo-128.webp 2>/dev/null && \
6565
cwebp -q 80 logo-256.jpg -o logo-256.webp 2>/dev/null && \
66-
cwebp -q 80 logo-512.jpg -o logo-512.webp 2>/dev/null && \
66+
cwebp -q 90 logo-512.jpg -o logo-512-hq.webp 2>/dev/null && \
6767
echo "✓ WebP images created:" && \
6868
ls -lh logo-*.webp
69+
70+
setup-hooks: ## Enable git pre-commit hooks
71+
@echo "Setting up git hooks..."
72+
@git config core.hooksPath .githooks
73+
@echo "✓ Git hooks enabled. Pre-commit will run: images, images-webp, prod-build"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
git clone https://github.com/DigitalBazaarHub/digitalbazaar.github.io.git
2424
cd digitalbazaar.github.io
2525
make install
26+
make setup-hooks # Enable pre-commit checks
2627
make serve
2728
```
2829
@@ -40,6 +41,7 @@ Visit [http://localhost:4000](http://localhost:4000)
4041
| `make fonts` | Download self-hosted fonts |
4142
| `make images` | Optimize images (PNG/JPG) |
4243
| `make images-webp` | Convert to WebP (requires `webp`) |
44+
| `make setup-hooks` | Enable git pre-commit hooks |
4345

4446
## Workflows
4547

_layouts/default.html

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,8 @@
4343
<link rel="preload" href="{{ '/assets/img/logo-512-hq.webp' | relative_url }}" as="image" type="image/webp" fetchpriority="high">
4444
{%- endif -%}
4545

46-
<!-- Critical inline CSS (prevents FOUC) -->
47-
<style>
48-
:root{--sand:#F4E6C4;--terracotta:#B34E36;--night:#152029;--ink:#21313B}
49-
html,body{margin:0;padding:0;color:var(--ink);background:linear-gradient(180deg,#FFFDF6 0%,var(--sand) 100%);min-height:100vh}
50-
html[dir="rtl"],html[dir="rtl"] body{font-family:'Tajawal',sans-serif;line-height:1.8}
51-
html[dir="ltr"],html[dir="ltr"] body{font-family:'DM Sans',sans-serif;line-height:1.6}
52-
.wrap{max-width:940px;margin:0 auto;padding:32px 20px 64px}
53-
</style>
54-
55-
<!-- Full styles (async load to avoid render blocking) -->
56-
<link rel="preload" href="{{ '/assets/css/styles.css' | relative_url }}" as="style" onload="this.onload=null;this.rel='stylesheet'">
57-
<noscript><link rel="stylesheet" href="{{ '/assets/css/styles.css' | relative_url }}"></noscript>
46+
<!-- Styles -->
47+
<link rel="stylesheet" href="{{ '/assets/css/styles.css' | relative_url }}">
5848

5949
<!-- SEO -->
6050
{% seo %}

0 commit comments

Comments
 (0)