fix: References section link corruption and download filename issues

**Issue 1: URL corruption in "See this CV in..." links**
- Bug: replaceYearPlaceholder used fmt.Sprintf on ALL URLs
- URLs like "/?lang=es" were corrupted to "/?lang=es%!(EXTRA string=2025)"
- Fix: Changed to strings.ReplaceAll("{{YEAR}}", year)
- Result: Only replaces actual {{YEAR}} placeholders, leaves other URLs intact

**Issue 2: Download filename not respected**
- Bug: Shortcut URLs (cv-jamr-2025-en.pdf) redirected with HTTP 301
- Browsers used original URL filename instead of Content-Disposition header
- Fix: Generate PDF directly in DefaultCVShortcut handler
- Result: Returns PDF with correct filename in Content-Disposition header

Files changed:
- internal/models/cv.go: Fixed replaceYearPlaceholder function
- internal/handlers/cv.go: Changed redirect to direct PDF generation

Both fixes verified:
- "See this CV in Spanish" link: href="/?lang=es" ✓
- Download link: filename=cv-jamr-2025-en.pdf ✓
This commit is contained in:
juanatsap
2025-11-20 13:00:06 +00:00
parent c88879b180
commit 810ee7955b
8 changed files with 407 additions and 9 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"html/template"
"os"
"strings"
"time"
)
@@ -241,7 +242,7 @@ func LoadCV(lang string) (*CV, error) {
// replaceYearPlaceholder replaces {{YEAR}} with the current year
func replaceYearPlaceholder(url string, year string) string {
return fmt.Sprintf(url, year)
return strings.ReplaceAll(url, "{{YEAR}}", year)
}
// LoadUI loads UI translations from a JSON file for the specified language