/** * Frontmatter rules and hero meta tiers of the research-article-template * layout (index.astro, Hero.astro, HeroPaper.astro, MetaColumns.astro), * shared by the editor view and the publisher so both render the same page. */ export type ArticleTemplate = "article" | "paper"; export function resolveTemplate(fm: Record): ArticleTemplate { return fm.template === "paper" ? "paper" : "article"; } /** `tocExpanded` wins; `tableOfContentsAutoCollapse: true` is the legacy spelling of `false`. */ export function resolveTocExpanded(fm: Record): boolean { if (typeof fm.tocExpanded === "boolean") return fm.tocExpanded; return fm.tableOfContentsAutoCollapse !== true; } /** Banner embed name, or undefined when hidden (`banner: false` or empty). */ export function resolveBanner(fm: Record): string | undefined { if (fm.banner === false || fm.banner === "") return undefined; return typeof fm.banner === "string" ? fm.banner : "banner.html"; } export function heroTitleSize(title: string, template: ArticleTemplate): string | undefined { const len = title.replace(/\s+/g, " ").trim().length; if (template === "paper") return len > 100 ? "sm" : len > 60 ? "md" : undefined; return len > 90 ? "long" : undefined; } // Authors are never hidden behind a hover: up to 6 listed, 7-12 in a // double-width cell, beyond that the first ones plus the last author and an // in-place "Show all" toggle. export const META_AUTHORS_SHOWN = 10; export const META_AFFILIATIONS_MAX = 6; export const META_AFFILIATIONS_SHOWN = 5; export type MetaTier = "list" | "wide" | "long"; export function metaTier(authorCount: number): MetaTier { return authorCount <= 6 ? "list" : authorCount <= 12 ? "wide" : "long"; } export function metaKeepAuthor(tier: MetaTier, authorCount: number, index: number): boolean { return tier !== "long" || index < META_AUTHORS_SHOWN - 1 || index === authorCount - 1; } /** `--meta-template` value for the meta columns grid. */ export function metaColumnsTemplate(tier: MetaTier, cells: number): string { return tier === "list" ? `repeat(${cells}, minmax(0, 1fr))` : `minmax(0, 2fr) repeat(${cells - 1}, minmax(0, 1fr))`; } /** ISO dates are formatted, free-form dates ("Sep. 01, 2025") are shown as written. */ export function displayDate(value: string): string { if (!/^\d{4}-\d{2}-\d{2}/.test(value)) return value; const d = new Date(value); if (Number.isNaN(d.getTime())) return value; return d.toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" }); } export function isoDate(value: string): string | undefined { const d = new Date(value); if (Number.isNaN(d.getTime())) return undefined; const pad = (v: number) => String(v).padStart(2, "0"); return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`; }