Add LaTeX compilation and post-push sync hooks
- Update pre-commit hook to compile cv.tex and cv_de.tex before generating webp - Add post-push hook to rsync PDFs to bocken.org:/var/www/static/ - Update documentation with new hook requirements and functionality
This commit is contained in:
@@ -20,14 +20,27 @@ git config core.hooksPath .githooks
|
|||||||
|
|
||||||
### pre-commit
|
### pre-commit
|
||||||
|
|
||||||
Automatically generates `img/cv.webp` from `cv.pdf` when changes are committed.
|
Automatically compiles LaTeX files and generates WebP preview image.
|
||||||
|
|
||||||
**Requirements:**
|
**Requirements:**
|
||||||
|
- `pdflatex` (from TeX Live or similar LaTeX distribution)
|
||||||
- `pdftoppm` (from poppler-utils)
|
- `pdftoppm` (from poppler-utils)
|
||||||
- `magick` (ImageMagick)
|
- `magick` (ImageMagick)
|
||||||
|
|
||||||
The hook will:
|
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
|
2. Convert the first page of `cv.pdf` to a WebP image
|
||||||
3. Save it as `img/cv.webp`
|
3. Save it as `img/cv.webp`
|
||||||
4. Add the generated image to the commit
|
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)
|
||||||
|
|||||||
38
.githooks/post-push
Executable file
38
.githooks/post-push
Executable file
@@ -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
|
||||||
@@ -1,46 +1,87 @@
|
|||||||
#!/bin/bash
|
#!/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
|
set -e # Exit on error
|
||||||
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
|
# Function to compile LaTeX file
|
||||||
if [ -f "cv.pdf" ]; then
|
compile_latex() {
|
||||||
# Use pdftoppm to convert first page to PNG, then ImageMagick to convert to WebP
|
local texfile=$1
|
||||||
pdftoppm -png -f 1 -l 1 -singlefile cv.pdf temp_cv && \
|
local pdffile="${texfile%.tex}.pdf"
|
||||||
magick temp_cv.png -quality 85 img/cv.webp && \
|
|
||||||
rm -f temp_cv.png
|
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
echo "Compiling $texfile..."
|
||||||
echo "Successfully generated img/cv.webp"
|
|
||||||
# Add the generated image to the commit
|
# Run pdflatex twice to resolve references
|
||||||
git add img/cv.webp
|
pdflatex -interaction=nonstopmode "$texfile" > /tmp/latex_output.log 2>&1
|
||||||
else
|
pdflatex -interaction=nonstopmode "$texfile" > /tmp/latex_output.log 2>&1
|
||||||
echo "Warning: Failed to generate cv.webp"
|
|
||||||
exit 1
|
# Check if PDF was created successfully (ignore exit code as warnings cause non-zero)
|
||||||
fi
|
if [ -f "$pdffile" ]; then
|
||||||
|
echo "✓ Successfully compiled $pdffile"
|
||||||
|
return 0
|
||||||
else
|
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
|
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 && \
|
# Function to generate webp from PDF
|
||||||
magick temp_cv.png -quality 85 img/cv.webp && \
|
generate_webp() {
|
||||||
rm -f temp_cv.png
|
local pdffile=$1
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
echo "Generating cv.webp from $pdffile..."
|
||||||
echo "Successfully generated img/cv.webp"
|
|
||||||
git add img/cv.webp
|
# Use pdftoppm to convert first page to PNG, then ImageMagick to convert to WebP
|
||||||
else
|
pdftoppm -png -f 1 -l 1 -singlefile "$pdffile" temp_cv && \
|
||||||
echo "Warning: Failed to generate cv.webp"
|
magick temp_cv.png -quality 85 img/cv.webp && \
|
||||||
exit 1
|
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
|
||||||
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
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "==== Pre-commit checks complete ===="
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user