Add tracked Git hooks and refactor timeline arrows
- Add .githooks directory with pre-commit hook for cv.webp generation - Create installation script for hooks setup - Add documentation for hooks usage - Refactor timeline arrows into reusable commands (\timelinearrow and \timelinearrowcontinue) - Simplify arrow usage by only requiring length parameter
This commit is contained in:
33
.githooks/README.md
Normal file
33
.githooks/README.md
Normal file
@@ -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
|
||||
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!"
|
||||
46
.githooks/pre-commit
Executable file
46
.githooks/pre-commit
Executable file
@@ -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
|
||||
Reference in New Issue
Block a user