feat: Add smart document auto-detection and generic project path support for fellow students
This commit is contained in:
@@ -16,6 +16,7 @@ Docker-Image und Build-Umgebung zum plattformunabhängigen, reproduzierbaren Kom
|
||||
- [3. Docker Compose](#3-docker-compose)
|
||||
- [4. Reines Docker CLI](#4-reines-docker-cli)
|
||||
- [5. Makefile](#5-makefile)
|
||||
- [Nutzung durch Mitstudierende (Beliebige Ordnerstrukturen)](#nutzung-durch-mitstudierende-beliebige-ordnerstrukturen)
|
||||
- [Image selbst bauen](#image-selbst-bauen)
|
||||
- [Git Remote & Image Registry](#git-remote--image-registry)
|
||||
- [Code ins Git-Repo pushen](#code-ins-git-repo-pushen)
|
||||
@@ -114,6 +115,41 @@ make shell # Interaktive Bash-Shell im Container öffnen
|
||||
|
||||
---
|
||||
|
||||
## Nutzung durch Mitstudierende (Beliebige Ordnerstrukturen)
|
||||
|
||||
**Ja!** Das Docker-Image ist so konzipiert, dass es für **jede beliebige Ordnerstruktur und Dateinamen** funktioniert:
|
||||
|
||||
### Automatische Erkennung
|
||||
Das Image erkennt automatisch das Hauptdokument im übergebenen Ordner:
|
||||
1. Typische Dateinamen: `seminararbeit.tex`, `thesis.tex`, `main.tex`, `bachelorarbeit.tex`, `masterarbeit.tex`, `arbeit.tex`, `document.tex`.
|
||||
2. Findet es keinen dieser Namen, sucht es automatisch nach der Datei, die `\documentclass` enthält.
|
||||
3. Hat das Projekt eine `.latexmkrc` (z. B. für Ausgabe nach `out/`), wird diese automatisch beachtet. Falls keine vorhanden ist, kompiliert es im Hauptverzeichnis.
|
||||
|
||||
### 1-Zeiler für Mitstudierende (ohne dieses Repo clonen zu müssen)
|
||||
Mitstudierende müssen nur in ihren eigenen Projektordner wechseln und folgenden Befehl ausführen:
|
||||
|
||||
**Windows PowerShell:**
|
||||
```powershell
|
||||
docker run --rm -v "${PWD}:/workspace" latex-docker:latest
|
||||
```
|
||||
|
||||
**Linux / macOS / WSL:**
|
||||
```bash
|
||||
docker run --rm -v "$(pwd):/workspace" latex-docker:latest
|
||||
```
|
||||
|
||||
Falls die Datei einen unüblichen Namen hat (z. B. `mein_projekt.tex`):
|
||||
```bash
|
||||
docker run --rm -v "${PWD}:/workspace" latex-docker:latest build mein_projekt.tex
|
||||
```
|
||||
|
||||
### Mit dem Skript für andere Pfade
|
||||
```powershell
|
||||
.\build-seminar.ps1 -ProjectPath "C:\Pfad\Zu\Beliebigem\Projekt"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Image selbst bauen
|
||||
|
||||
Das Image lokal bauen und mit Tags versehen:
|
||||
|
||||
+31
-12
@@ -26,14 +26,29 @@ param(
|
||||
[switch]$Watch,
|
||||
[switch]$RebuildImage,
|
||||
[string]$ProjectPath = "",
|
||||
[string]$File = "seminararbeit.tex"
|
||||
[string]$File = ""
|
||||
)
|
||||
|
||||
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
if ([string]::IsNullOrWhiteSpace($ProjectPath)) {
|
||||
$ProjectPath = Join-Path $ScriptDir "..\Seminar_Arbeit_BITI_Gruber"
|
||||
} elseif (-not [System.IO.Path]::IsPathRooted($ProjectPath)) {
|
||||
$ProjectPath = Join-Path $ScriptDir $ProjectPath
|
||||
# 1. Wenn im aktuellen Verzeichnis (wo der User steht) .tex-Dateien existieren -> nimm dieses
|
||||
if (Get-ChildItem -Path (Get-Location) -Filter "*.tex" -ErrorAction SilentlyContinue) {
|
||||
$ProjectPath = (Get-Location).Path
|
||||
}
|
||||
# 2. Falls ../Seminar_Arbeit_BITI_Gruber existiert
|
||||
elseif (Test-Path (Join-Path $ScriptDir "..\Seminar_Arbeit_BITI_Gruber")) {
|
||||
$ProjectPath = Join-Path $ScriptDir "..\Seminar_Arbeit_BITI_Gruber"
|
||||
}
|
||||
else {
|
||||
$ProjectPath = (Get-Location).Path
|
||||
}
|
||||
} else {
|
||||
# Prüfen, ob relativ zum aktuellen Verzeichnis oder relativ zum Skriptverzeichnis
|
||||
if (Test-Path $ProjectPath) {
|
||||
$ProjectPath = (Resolve-Path $ProjectPath).Path
|
||||
} elseif (Test-Path (Join-Path $ScriptDir $ProjectPath)) {
|
||||
$ProjectPath = (Resolve-Path (Join-Path $ScriptDir $ProjectPath)).Path
|
||||
}
|
||||
}
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
@@ -81,13 +96,15 @@ if ($Clean) {
|
||||
Write-Host "==> Bereinige Projektverzeichnis: $FullProjectPath" -ForegroundColor Yellow
|
||||
$cmdArgs += "clean"
|
||||
} elseif ($Watch) {
|
||||
Write-Host "==> Starte Watch-Modus für: $File" -ForegroundColor Cyan
|
||||
$targetName = if ($File) { $File } else { "Hauptdokument" }
|
||||
Write-Host "==> Starte Watch-Modus für: $targetName in $FullProjectPath" -ForegroundColor Cyan
|
||||
$cmdArgs += "watch"
|
||||
$cmdArgs += $File
|
||||
if ($File) { $cmdArgs += $File }
|
||||
} else {
|
||||
Write-Host "==> Kompiliere Seminararbeit: $File" -ForegroundColor Green
|
||||
$targetName = if ($File) { $File } else { "Dokument (Auto-Detection)" }
|
||||
Write-Host "==> Kompiliere LaTeX-Projekt: $targetName in $FullProjectPath" -ForegroundColor Green
|
||||
$cmdArgs += "build"
|
||||
$cmdArgs += $File
|
||||
if ($File) { $cmdArgs += $File }
|
||||
}
|
||||
|
||||
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
@@ -98,11 +115,13 @@ $stopwatch.Stop()
|
||||
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
if (-not $Clean -and -not $Watch) {
|
||||
$pdfPath = Join-Path $FullProjectPath "out\seminararbeit.pdf"
|
||||
Write-Host "`n[OK] Build erfolgreich abgeschlossen in $([math]::Round($stopwatch.Elapsed.TotalSeconds, 1))s!" -ForegroundColor Green
|
||||
if (Test-Path $pdfPath) {
|
||||
$pdfItem = Get-Item $pdfPath
|
||||
Write-Host "PDF generiert: $pdfPath ($([math]::Round($pdfItem.Length / 1KB, 1)) KB)" -ForegroundColor Cyan
|
||||
# Zuletzt geänderte PDF-Datei im Projekt/out-Verzeichnis suchen
|
||||
$pdfFile = Get-ChildItem -Path $FullProjectPath -Filter "*.pdf" -Recurse -File -ErrorAction SilentlyContinue |
|
||||
Sort-Object LastWriteTime -Descending |
|
||||
Select-Object -First 1
|
||||
if ($pdfFile) {
|
||||
Write-Host "PDF generiert: $($pdfFile.FullName) ($([math]::Round($pdfFile.Length / 1KB, 1)) KB)" -ForegroundColor Cyan
|
||||
}
|
||||
} else {
|
||||
Write-Host "`n[OK] Aktion erfolgreich beendet!" -ForegroundColor Green
|
||||
|
||||
+17
-2
@@ -5,9 +5,24 @@
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_DIR="${1:-"${SCRIPT_DIR}/../Seminar_Arbeit_BITI_Gruber"}"
|
||||
IMAGE_NAME="latex-docker:latest"
|
||||
TARGET_DIR="${1:-""}"
|
||||
|
||||
# Wenn kein Pfad übergeben:
|
||||
# 1. Wenn im aktuellen Verzeichnis *.tex liegt -> nimm das aktuelle Verzeichnis
|
||||
# 2. Sonst prüfe Standard-Projektordner ../Seminar_Arbeit_BITI_Gruber
|
||||
if [ -z "$TARGET_DIR" ]; then
|
||||
if compgen -G "*.tex" > /dev/null 2>&1; then
|
||||
PROJECT_DIR="$(pwd)"
|
||||
elif [ -d "${SCRIPT_DIR}/../Seminar_Arbeit_BITI_Gruber" ]; then
|
||||
PROJECT_DIR="${SCRIPT_DIR}/../Seminar_Arbeit_BITI_Gruber"
|
||||
else
|
||||
PROJECT_DIR="$(pwd)"
|
||||
fi
|
||||
else
|
||||
PROJECT_DIR="$TARGET_DIR"
|
||||
fi
|
||||
|
||||
IMAGE_NAME="latex-docker:latest"
|
||||
ACTION="${2:-build}"
|
||||
|
||||
if ! command -v docker &> /dev/null; then
|
||||
|
||||
+21
-7
@@ -9,16 +9,30 @@ set -e
|
||||
# Beliebiger Befehl (z.B. latexmk -pdf ...)
|
||||
|
||||
resolve_target() {
|
||||
# 1. Wenn explizit als Argument übergeben
|
||||
if [ -n "$1" ]; then
|
||||
echo "$1"
|
||||
elif [ -f "seminararbeit.tex" ]; then
|
||||
echo "seminararbeit.tex"
|
||||
elif [ -f "main.tex" ]; then
|
||||
echo "main.tex"
|
||||
else
|
||||
# Fallback auf alle tex-Dateien oder Standard-latexmk-Verhalten
|
||||
echo ""
|
||||
return
|
||||
fi
|
||||
|
||||
# 2. Bekannte typische Hauptdateinamen prüfen
|
||||
for name in seminararbeit.tex main.tex thesis.tex bachelorarbeit.tex masterarbeit.tex arbeit.tex document.tex index.tex; do
|
||||
if [ -f "$name" ]; then
|
||||
echo "$name"
|
||||
return
|
||||
fi
|
||||
done
|
||||
|
||||
# 3. Automatische Suche nach einer .tex-Datei mit \documentclass im Verzeichnis
|
||||
candidates=$(grep -l "\\\\documentclass" *.tex 2>/dev/null || true)
|
||||
count=$(echo "$candidates" | grep -v '^$' | wc -l)
|
||||
if [ "$count" -eq 1 ]; then
|
||||
echo "$candidates"
|
||||
return
|
||||
fi
|
||||
|
||||
# Fallback: latexmk entscheidet selbst anhand von .latexmkrc oder allen tex-Dateien
|
||||
echo ""
|
||||
}
|
||||
|
||||
COMMAND="${1:-build}"
|
||||
|
||||
Reference in New Issue
Block a user