initial 2
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 09:26:50 +01:00
parent 194330fb47
commit 3b37368e7d
213 changed files with 14688 additions and 1 deletions

View File

@@ -0,0 +1,41 @@
const PLACEHOLDER_RE = /\{\{(\w+)\}\}/g;
export function renderTemplate(
body: string,
data: Record<string, string | number | unknown>
): string {
return body.replace(PLACEHOLDER_RE, (_, key: string) => {
const val = data[key];
if (val === undefined || val === null) return `{{${key}}}`;
if (typeof val === "object") return JSON.stringify(val);
return String(val);
});
}
export function findMissingPlaceholders(
body: string,
data: Record<string, unknown>
): string[] {
const missing: string[] = [];
let match;
const re = /\{\{(\w+)\}\}/g;
while ((match = re.exec(body)) !== null) {
const key = match[1];
if (data[key] === undefined && !missing.includes(key)) {
missing.push(key);
}
}
return missing;
}
export const SAMPLE_PREVIEW_DATA: Record<string, unknown> = {
user_name: "Traveler",
context: { level: 5, recentReading: 42, exerciseDays: 3 },
topic: "Stoic philosophy",
week_summary: "You read 35 pages, prayed 4 days, and exercised twice.",
reading_progress: "Currently reading page 120 of 300",
exercise_summary: "2 exercise sessions this week",
prayer_summary: "4 of 5 morning prayers completed",
learning_topics: "Roman history, Latin roots",
chronicle_context: "Chapter 3: The Long Road — 45 days on the journey",
};