File size: 2,866 Bytes
eab9566 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | /**
* 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<string, unknown>): ArticleTemplate {
return fm.template === "paper" ? "paper" : "article";
}
/** `tocExpanded` wins; `tableOfContentsAutoCollapse: true` is the legacy spelling of `false`. */
export function resolveTocExpanded(fm: Record<string, unknown>): 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, unknown>): 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())}`;
}
|