Compare commits
2 Commits
091aeb4798
...
10048e7611
| Author | SHA1 | Date | |
|---|---|---|---|
|
10048e7611
|
|||
|
9cec37d7ea
|
46
.githooks/README.md
Normal file
46
.githooks/README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# 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 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. 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)
|
||||
30
.githooks/install-hooks.sh
Executable file
30
.githooks/install-hooks.sh
Executable file
@@ -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!"
|
||||
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
|
||||
87
.githooks/pre-commit
Executable file
87
.githooks/pre-commit
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Pre-commit hook to compile LaTeX files and generate cv.webp
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
# Function to compile LaTeX file
|
||||
compile_latex() {
|
||||
local texfile=$1
|
||||
local pdffile="${texfile%.tex}.pdf"
|
||||
|
||||
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 "✗ Failed to compile $texfile"
|
||||
echo "See /tmp/latex_output.log for details"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to generate webp from PDF
|
||||
generate_webp() {
|
||||
local pdffile=$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
|
||||
Reference in New Issue
Block a user