c89b67a06d
- Merge lang package into constants (add IsValidLang, ValidateLang, AllLangs) - Rename internal/services to internal/email for consistency with pdf package - Rename types to avoid redundancy: EmailService→Service, EmailConfig→Config - Update all imports and references across codebase - Delete internal/lang directory (functions moved to constants)
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package cv
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
c "github.com/juanatsap/cv-site/internal/constants"
|
|
"github.com/juanatsap/cv-site/internal/fileutil"
|
|
)
|
|
|
|
// LoadCV loads CV data from a JSON file for the specified language
|
|
func LoadCV(language string) (*CV, error) {
|
|
if err := c.ValidateLang(language); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var cvData CV
|
|
filename := fmt.Sprintf("%s/cv-%s.json", c.DirData, language)
|
|
if err := fileutil.LoadJSON(filename, &cvData); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Replace {{YEAR}} placeholder in reference URLs with current year
|
|
currentYear := fmt.Sprintf("%d", time.Now().Year())
|
|
for i := range cvData.References {
|
|
cvData.References[i].URL = replaceYearPlaceholder(cvData.References[i].URL, currentYear)
|
|
}
|
|
|
|
// Validate the loaded CV data
|
|
if err := cvData.Validate(); err != nil {
|
|
return nil, fmt.Errorf("validation failed: %w", err)
|
|
}
|
|
|
|
return &cvData, nil
|
|
}
|
|
|
|
// replaceYearPlaceholder replaces {{YEAR}} with the current year
|
|
func replaceYearPlaceholder(url string, year string) string {
|
|
return strings.ReplaceAll(url, "{{YEAR}}", year)
|
|
}
|