diff --git a/.githooks/README.md b/.githooks/README.md new file mode 100644 index 0000000..f9e8e9e --- /dev/null +++ b/.githooks/README.md @@ -0,0 +1,33 @@ +# Git Hooks + +This directory contains Git hooks for the CV project. + +## Installation + +To install the hooks, run: + +```bash +.githooks/install-hooks.sh +``` + +Or, configure Git to use this directory for hooks (Git 2.9+): + +```bash +git config core.hooksPath .githooks +``` + +## Available Hooks + +### pre-commit + +Automatically generates `img/cv.webp` from `cv.pdf` when changes are committed. + +**Requirements:** +- `pdftoppm` (from poppler-utils) +- `magick` (ImageMagick) + +The hook will: +1. Check if `cv.pdf` is being committed or has been modified +2. Convert the first page of `cv.pdf` to a WebP image +3. Save it as `img/cv.webp` +4. Add the generated image to the commit diff --git a/.githooks/install-hooks.sh b/.githooks/install-hooks.sh new file mode 100755 index 0000000..bc40d15 --- /dev/null +++ b/.githooks/install-hooks.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Install git hooks from .githooks directory + +HOOKS_DIR=".githooks" +GIT_HOOKS_DIR=".git/hooks" + +# Ensure .git/hooks directory exists +if [ ! -d "$GIT_HOOKS_DIR" ]; then + echo "Error: .git/hooks directory not found. Are you in a git repository?" + exit 1 +fi + +# Copy all hooks from .githooks to .git/hooks +for hook in "$HOOKS_DIR"/*; do + # Skip this installation script + if [ "$(basename "$hook")" = "install-hooks.sh" ] || [ "$(basename "$hook")" = "README.md" ]; then + continue + fi + + if [ -f "$hook" ]; then + hook_name=$(basename "$hook") + echo "Installing $hook_name..." + cp "$hook" "$GIT_HOOKS_DIR/$hook_name" + chmod +x "$GIT_HOOKS_DIR/$hook_name" + echo "✓ $hook_name installed" + fi +done + +echo "" +echo "All hooks installed successfully!" diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..751a9f2 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,46 @@ +#!/bin/bash + +# Pre-commit hook to generate cv.webp from cv.pdf + +# Check if cv.pdf exists and is staged +if git diff --cached --name-only | grep -q "^cv\.pdf$"; then + echo "cv.pdf is being committed, generating cv.webp..." + + # Generate webp from first page of PDF + if [ -f "cv.pdf" ]; then + # Use pdftoppm to convert first page to PNG, then ImageMagick to convert to WebP + pdftoppm -png -f 1 -l 1 -singlefile cv.pdf temp_cv && \ + magick temp_cv.png -quality 85 img/cv.webp && \ + rm -f temp_cv.png + + if [ $? -eq 0 ]; then + echo "Successfully generated img/cv.webp" + # Add the generated image to the commit + git add img/cv.webp + else + echo "Warning: Failed to generate cv.webp" + exit 1 + fi + else + echo "Warning: cv.pdf not found, skipping cv.webp generation" + fi +elif [ -f "cv.pdf" ]; then + # cv.pdf exists but is not being committed, check if it's newer than cv.webp + if [ ! -f "img/cv.webp" ] || [ "cv.pdf" -nt "img/cv.webp" ]; then + echo "cv.pdf has been modified but not staged. Generating cv.webp anyway..." + + pdftoppm -png -f 1 -l 1 -singlefile cv.pdf temp_cv && \ + magick temp_cv.png -quality 85 img/cv.webp && \ + rm -f temp_cv.png + + if [ $? -eq 0 ]; then + echo "Successfully generated img/cv.webp" + git add img/cv.webp + else + echo "Warning: Failed to generate cv.webp" + exit 1 + fi + fi +fi + +exit 0