diff --git a/.githooks/README.md b/.githooks/README.md index f9e8e9e..e1e7157 100644 --- a/.githooks/README.md +++ b/.githooks/README.md @@ -20,14 +20,27 @@ git config core.hooksPath .githooks ### pre-commit -Automatically generates `img/cv.webp` from `cv.pdf` when changes are committed. +Automatically compiles LaTeX files and generates WebP preview image. **Requirements:** +- `pdflatex` (from TeX Live or similar LaTeX distribution) - `pdftoppm` (from poppler-utils) - `magick` (ImageMagick) The hook will: -1. Check if `cv.pdf` is being committed or has been modified +1. Compile `cv.tex` and `cv_de.tex` to PDF if they've been modified or staged 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 + +### post-push + +Automatically syncs compiled PDFs to bocken.org after pushing. + +**Requirements:** +- `rsync` +- SSH access to `root@bocken.org` + +The hook will: +1. Upload `cv.pdf` to `root@bocken.org:/var/www/static/` +2. Upload `cv_de.pdf` to `root@bocken.org:/var/www/static/` (if exists) diff --git a/.githooks/post-push b/.githooks/post-push new file mode 100755 index 0000000..3a70b8b --- /dev/null +++ b/.githooks/post-push @@ -0,0 +1,38 @@ +#!/bin/bash + +# Post-push hook to rsync CV PDFs to bocken.org + +set -e + +echo "==== Syncing PDFs to bocken.org ====" + +# Check if PDFs exist +if [ ! -f "cv.pdf" ]; then + echo "Warning: cv.pdf not found, skipping sync" + exit 0 +fi + +# Rsync cv.pdf +echo "Uploading cv.pdf..." +if rsync -avz --progress cv.pdf root@bocken.org:/var/www/static/; then + echo "✓ cv.pdf synced successfully" +else + echo "✗ Failed to sync cv.pdf" + exit 1 +fi + +# Rsync cv_de.pdf if it exists +if [ -f "cv_de.pdf" ]; then + echo "Uploading cv_de.pdf..." + if rsync -avz --progress cv_de.pdf root@bocken.org:/var/www/static/; then + echo "✓ cv_de.pdf synced successfully" + else + echo "✗ Failed to sync cv_de.pdf" + exit 1 + fi +fi + +echo "" +echo "==== Sync complete ====" + +exit 0 diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 751a9f2..e96ac3e 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,46 +1,87 @@ #!/bin/bash -# Pre-commit hook to generate cv.webp from cv.pdf +# Pre-commit hook to compile LaTeX files and generate cv.webp -# 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..." +set -e # Exit on error - # 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 +# Function to compile LaTeX file +compile_latex() { + local texfile=$1 + local pdffile="${texfile%.tex}.pdf" - 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 + echo "Compiling $texfile..." + + # Run pdflatex twice to resolve references + pdflatex -interaction=nonstopmode "$texfile" > /tmp/latex_output.log 2>&1 + pdflatex -interaction=nonstopmode "$texfile" > /tmp/latex_output.log 2>&1 + + # Check if PDF was created successfully (ignore exit code as warnings cause non-zero) + if [ -f "$pdffile" ]; then + echo "✓ Successfully compiled $pdffile" + return 0 else - echo "Warning: cv.pdf not found, skipping cv.webp generation" + echo "✗ Failed to compile $texfile" + echo "See /tmp/latex_output.log for details" + return 1 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 +# Function to generate webp from PDF +generate_webp() { + local pdffile=$1 - 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 + echo "Generating cv.webp from $pdffile..." + + # Use pdftoppm to convert first page to PNG, then ImageMagick to convert to WebP + pdftoppm -png -f 1 -l 1 -singlefile "$pdffile" 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 + return 0 + else + echo "✗ Failed to generate cv.webp" + return 1 + fi +} + +# Check if .tex files are staged or modified +if git diff --cached --name-only | grep -qE "^cv(_de)?\.tex$" || \ + [ -f "cv.tex" -a "cv.tex" -nt "cv.pdf" ] || \ + [ -f "cv_de.tex" -a "cv_de.tex" -nt "cv_de.pdf" ]; then + + echo "==== Compiling LaTeX files ====" + + # Compile cv.tex if it exists and is newer than PDF or staged + if [ -f "cv.tex" ]; then + if [ ! -f "cv.pdf" ] || [ "cv.tex" -nt "cv.pdf" ] || \ + git diff --cached --name-only | grep -q "^cv\.tex$"; then + compile_latex "cv.tex" || exit 1 fi fi + + # Compile cv_de.tex if it exists and is newer than PDF or staged + if [ -f "cv_de.tex" ]; then + if [ ! -f "cv_de.pdf" ] || [ "cv_de.tex" -nt "cv_de.pdf" ] || \ + git diff --cached --name-only | grep -q "^cv_de\.tex$"; then + compile_latex "cv_de.tex" || exit 1 + fi + fi + + echo "" +fi + +# Generate cv.webp from cv.pdf +if [ -f "cv.pdf" ]; then + if [ ! -f "img/cv.webp" ] || [ "cv.pdf" -nt "img/cv.webp" ]; then + echo "==== Generating WebP image ====" + generate_webp "cv.pdf" || exit 1 + fi fi +echo "" +echo "==== Pre-commit checks complete ====" + exit 0