feat(cv): qualify templates and reliable local import processing

This commit is contained in:
cesnimda
2026-10-28 14:36:12 +01:00
parent 73ea888375
commit 3f4db8ca81
69 changed files with 2597 additions and 180 deletions
@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace JobTrackerApi.Models;
@@ -6,6 +7,10 @@ namespace JobTrackerApi.Models;
public sealed class CoverLetterDocumentSettings
{
public int SchemaVersion { get; set; } = 1;
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int? DesignVersion { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? HeadingFont { get; set; }
public string Language { get; set; } = "en";
public string SenderName { get; set; } = "";
public string SenderTitle { get; set; } = "";
@@ -38,16 +43,18 @@ public static class CoverLetterDocumentSettingsJson
public static CoverLetterDocumentSettings Normalize(CoverLetterDocumentSettings? value)
{
value ??= new();
var theme = CvThemeCatalog.Resolve(value.ThemeId);
var theme = CvThemeCatalog.Resolve(value.ThemeId, value.DesignVersion);
var style = CvVariantSettingsJson.Normalize(new()
{
AccentColor = value.AccentColor, BodyFont = value.BodyFont,
AccentColor = value.AccentColor, BodyFont = value.BodyFont, HeadingFont = value.HeadingFont,
BaseFontSizePt = value.BaseFontSizePt, LineHeight = value.LineHeight, PageMarginMm = value.PageMarginMm,
});
static string Text(string? text, int limit) => (text ?? "")[..Math.Min(text?.Length ?? 0, limit)];
return new()
{
SchemaVersion = 1, ThemeId = theme.Id,
DesignVersion = value.DesignVersion is 1 or 2 ? value.DesignVersion : null,
HeadingFont = value.DesignVersion == 2 ? style.HeadingFont ?? theme.HeadingFont : null,
Language = value.Language?.Trim().ToLowerInvariant() is "nb" or "nb-no" ? "nb-NO" : "en",
SenderName = Text(value.SenderName, 300), SenderTitle = Text(value.SenderTitle, 300),
SenderEmail = Text(value.SenderEmail, 300), SenderPhone = Text(value.SenderPhone, 100), SenderLocation = Text(value.SenderLocation, 300),