Files
Reactive-Resume/packages/pdf/src/section-title.ts
T
Amruth Pillai a4999c04af refactor: remove dead code, unused exports and redundant dependencies
- drop dotenv (Node 24 process.loadEnvFile) and dompurify (only used by dead code)
- delete unused ui components/hooks (card, progress, checkbox, use-confirm, use-prompt)
- delete dead sanitizeHtml/sanitizeCss, url-security helpers, patch-resume tool,
  schema/page, createResumePatches, patch-proposal preview builder, fonts fallback helpers
- inline single-caller wrappers (flags service, auth getSession, pdf renderer passthrough)
- deduplicate template color helpers into shared/color-helpers
- unexport 50+ internal-only symbols, remove dead export-map entries
- replace hand-rolled unique()/useIsMobile with Set spread and usehooks-ts
2026-07-03 20:04:36 +02:00

101 lines
2.8 KiB
TypeScript

import type { ResumeData, SectionType } from "@reactive-resume/schema/resume/data";
type SectionTitleResolverInput = {
sectionId: string;
locale: string;
sectionKind: "summary" | "builtin" | "custom";
customSectionType?: string;
defaultEnglishTitle?: string | undefined;
};
export type SectionTitleResolver = (input: SectionTitleResolverInput) => string;
const defaultEnglishSectionTitles: Record<"summary" | SectionType, string> = {
summary: "Summary",
profiles: "Profiles",
experience: "Experience",
education: "Education",
projects: "Projects",
skills: "Skills",
languages: "Languages",
interests: "Interests",
awards: "Awards",
certifications: "Certifications",
publications: "Publications",
volunteer: "Volunteer",
references: "References",
};
const defaultEnglishCustomSectionTitles: Record<string, string> = {
"cover-letter": "Cover Letter",
};
export const resolveSectionTitle = (
title: string,
input: SectionTitleResolverInput,
resolver?: SectionTitleResolver,
legacyFallback?: string,
) => {
if (title.trim()) return title;
const resolvedTitle = resolver?.(input);
if (resolvedTitle?.trim()) return resolvedTitle;
if (legacyFallback !== undefined) return legacyFallback;
return input.defaultEnglishTitle ?? input.sectionId;
};
type RenderData = ResumeData & {
resolveSectionTitle?: SectionTitleResolver | undefined;
};
export const getResumeSectionTitle = (data: RenderData, sectionId: string, legacyFallback?: string) => {
const locale = data.metadata.page.locale;
if (sectionId === "summary") {
const defaultEnglishTitle = defaultEnglishSectionTitles.summary;
return resolveSectionTitle(
data.summary.title,
{ sectionId, locale, sectionKind: "summary", defaultEnglishTitle },
data.resolveSectionTitle,
legacyFallback,
);
}
if (sectionId in data.sections) {
const sectionType = sectionId as SectionType;
const defaultEnglishTitle = defaultEnglishSectionTitles[sectionType];
return resolveSectionTitle(
data.sections[sectionType].title,
{ sectionId, locale, sectionKind: "builtin", defaultEnglishTitle },
data.resolveSectionTitle,
legacyFallback,
);
}
const customSection = data.customSections.find((section) => section.id === sectionId);
if (customSection) {
const defaultEnglishTitle =
customSection.type in data.sections
? defaultEnglishSectionTitles[customSection.type as SectionType]
: (defaultEnglishCustomSectionTitles[customSection.type] ?? customSection.type);
return resolveSectionTitle(
customSection.title,
{ sectionId, locale, sectionKind: "custom", customSectionType: customSection.type, defaultEnglishTitle },
data.resolveSectionTitle,
legacyFallback,
);
}
return (
data.resolveSectionTitle?.({ sectionId, locale, sectionKind: "custom", defaultEnglishTitle: sectionId }) ??
legacyFallback ??
sectionId
);
};