Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions apps/web/app/components/career-page.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type { PublishedCareer } from "@catalyst/schemas";
import { CareerPage } from "./career-page";

const demo = loadDemoProjection().career!;
const render = (career: PublishedCareer, places: string[] = ["paris"], projects: string[] = []) =>
renderToStaticMarkup(createElement(StaticRouter, { location: "/career" }, createElement(CareerPage, { career, places, projects })));
const render = (career: PublishedCareer, places: string[] = ["paris"], projects: string[] = [], today?: string | null) =>
renderToStaticMarkup(createElement(StaticRouter, { location: "/career" }, createElement(CareerPage, { career, places, projects, ...(today !== undefined ? { today } : {}) })));
const without = <K extends keyof PublishedCareer>(c: PublishedCareer, ...keys: K[]): PublishedCareer => {
const copy = { ...c };
for (const k of keys) delete copy[k];
Expand Down Expand Up @@ -72,6 +72,45 @@ describe("CareerPage", () => {
expect(html).not.toContain("data-upcoming");
});

describe("a position that begins on a given day (`upcoming: YYYY-MM-DD`)", () => {
const { end: _end, ...open } = { ...demo.roles[0]!, id: "joining-co", org: "Joining Co", start: "2026-11", upcoming: "2026-11-30" as const };
const career = { ...demo, updated: "2026-11", roles: [open, ...demo.roles] };
const item = (page: string) => {
const from = page.slice(page.indexOf('id="joining-co"'));
return from.slice(0, from.indexOf("</li>"));
};

it("is prerendered as it is authored: the server has no clock, and the first client render must equal it", () => {
// no `today` given: the hook says "not hydrated" in a server render, as in the hydration pass
for (const li of [item(render(career)), item(render(career, ["paris"], [], null))]) {
expect(li).toContain('data-upcoming="true"');
expect(li).toContain('<span class="career-status">Joining</span>');
expect(li).not.toMatch(/data-current|Present|career-duration/);
}
});
it("still says Joining on the days before", () => {
expect(item(render(career, ["paris"], [], "2026-11-29"))).toContain('data-upcoming="true"');
});
it("is the position in progress from that day, with no end meaning Present and a stay counted to the review month", () => {
const li = item(render(career, ["paris"], [], "2026-11-30"));
expect(li).toContain('data-current="true"');
expect(li).not.toContain("data-upcoming");
expect(li).not.toContain("career-status");
expect(li).toContain("Present");
expect(li).toContain("November 2026 to present");
expect(li).toContain(">1m<"); // Nov 2026 to the review month, Nov 2026, both counted
});
});

it("reads the clock in one place: the career page has no other `Date` in it (the server and the static page have none)", () => {
const here = (f: string) => readFileSync(new URL(f, import.meta.url), "utf8");
expect(here("./career-page.tsx")).not.toMatch(/new Date|Date\.now|performance\.now/);
const lib = here("../lib/career.ts");
expect(lib.match(/new Date|Date\.now/g)).toEqual(["new Date"]); // `localDay`'s default, nothing else
expect(here("../lib/career-meta.ts")).not.toMatch(/new Date|Date\.now/);
expect(here("../lib/llm-text.ts")).not.toMatch(/new Date|Date\.now/);
});

it("shows a year-only start with no end as the year alone", () => {
const item = html.slice(html.indexOf('id="interface-designer-placeholder-co"'));
expect(item.slice(0, item.indexOf("</li>"))).toMatch(/<time dateTime="2021">2021<\/time>/);
Expand Down
18 changes: 12 additions & 6 deletions apps/web/app/components/career-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { useEffect, useRef, useState } from "react";
import { Link } from "react-router";
import type { PublishedCareer, PublishedCareerEducation, PublishedCareerProject, PublishedCareerRole } from "@catalyst/schemas";
import { ContactForm } from "~/components/contact-form";
import { useHydrated } from "~/hooks/use-hydrated";
import { SiteFooter } from "~/components/site-footer";
import { Button, Icon } from "~/components/ui";
import type { IconName } from "~/components/ui/icon";
import { asOfText, CAREER_PATH, careerDuration, careerIcon, careerLogoSrc, careerPeriod, formatCareerMonth, isCurrent, isUpcoming, languageDetail, safeLinks, safePortrait, safeProjects } from "~/lib/career";
import { asOfText, CAREER_PATH, careerDuration, careerIcon, careerLogoSrc, careerPeriod, formatCareerMonth, languageDetail, localDay, roleState, safeLinks, safePortrait, safeProjects } from "~/lib/career";
import { CONTACT_ID } from "~/lib/contact";
import { safeExternalUrl } from "~/lib/entry-blocks";
import { entryPath, placePath } from "~/lib/entries";
Expand All @@ -25,7 +26,11 @@ import { useForcedScheme } from "~/lib/theme";
* one way to reach the owner is the contact form (`ContactForm`, docs/career-page.md, "Contact") after the socials: a "Get in touch"
* button in the head scrolls to it. There is no address, phone number or mailto link anywhere (the contract has no field for one).
*/
export function CareerPage({ career, places = [], projects = [] }: { career: PublishedCareer; places?: readonly string[]; projects?: readonly string[] }) {
export function CareerPage({ career, places = [], projects = [], today: given }: { career: PublishedCareer; places?: readonly string[]; projects?: readonly string[]; today?: string | null }) {
// The day, for the one thing that depends on it: a position that begins on a given day (`upcoming: YYYY-MM-DD`) turns into the one in progress by itself. The page is a static file, so the
// clock is read in the browser only, after hydration (null on the server and in the hydration pass: the first client render is the prerendered HTML). `today` is for tests.
const hydrated = useHydrated();
const today = given !== undefined ? given : hydrated ? localDay() : null;
const portrait = safePortrait(career);
const crashed = usePortraitEgg(portrait?.egg);
const links = safeLinks(career);
Expand Down Expand Up @@ -123,7 +128,7 @@ export function CareerPage({ career, places = [], projects = [] }: { career: Pub
<Block id="experience" title="Experience" count={career.roles.length}>
<ol className="career-timeline" aria-labelledby="experience-h">
{career.roles.map((role) => (
<RoleItem key={role.id} role={role} placeKnown={role.place !== undefined && known.has(role.place)} projectKnown={(slug) => haveProject.has(slug)} asOf={career.updated} />
<RoleItem key={role.id} role={role} placeKnown={role.place !== undefined && known.has(role.place)} projectKnown={(slug) => haveProject.has(slug)} asOf={career.updated} today={today} />
))}
</ol>
</Block>
Expand Down Expand Up @@ -356,11 +361,12 @@ function OrgName({ name, url }: { name: string; url: string | null }) {
);
}

function RoleItem({ role, placeKnown, projectKnown, asOf }: { role: PublishedCareerRole; placeKnown: boolean; projectKnown: (slug: string) => boolean; asOf: string }) {
function RoleItem({ role, placeKnown, projectKnown, asOf, today }: { role: PublishedCareerRole; placeKnown: boolean; projectKnown: (slug: string) => boolean; asOf: string; today: string | null }) {
const state = roleState(role, today);
const orgUrl = role.orgUrl ? safeExternalUrl(role.orgUrl) : null;
const projects = safeProjects(role);
return (
<li id={role.id} data-slot="career-role" data-current={isCurrent(role) ? "true" : undefined} data-upcoming={isUpcoming(role) ? "true" : undefined} className="career-item">
<li id={role.id} data-slot="career-role" data-current={state.current ? "true" : undefined} data-upcoming={state.upcoming ? "true" : undefined} className="career-item">
<Marker item={role} name={role.org} icon={careerIcon(role.title, "role")} />
<div className="career-head">
<div className="career-top">
Expand All @@ -372,7 +378,7 @@ function RoleItem({ role, placeKnown, projectKnown, asOf }: { role: PublishedCar
{role.title}
</p>
<div className="career-meta type-meta">
<Period start={role.start} end={role.end} asOf={asOf} upcoming={isUpcoming(role)} />
<Period start={role.start} end={state.end} asOf={asOf} upcoming={state.upcoming} />
</div>
<p className="career-facts">
<Where text={role.location} place={role.place} known={placeKnown} />
Expand Down
41 changes: 29 additions & 12 deletions apps/web/app/lib/career.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { loadDemoProjection } from "@catalyst/published/dev";
import type { PublishedCareer } from "@catalyst/schemas";
import { asOfText, careerDuration, careerIcon, careerLogo, careerLogoSrc, careerJsonLd, careerPeriod, formatCareerMonth, isCurrent, isUpcoming, languageDetail, safeLinks, safePortrait, safeProjects } from "./career";
import { asOfText, careerDuration, careerIcon, careerLogo, careerLogoSrc, careerJsonLd, careerPeriod, formatCareerMonth, languageDetail, localDay, roleState, safeLinks, safePortrait, safeProjects } from "./career";
import { SITE } from "./site";

const demo = loadDemoProjection().career!;
Expand Down Expand Up @@ -133,17 +133,34 @@ describe("careerLogo", () => {
});
});

describe("isCurrent, languageDetail", () => {
it("only `present` is current", () => {
expect(isCurrent({ end: "present" })).toBe(true);
expect(isCurrent({ end: "2025" })).toBe(false);
expect(isCurrent({})).toBe(false);
});
it("a role that has not begun is upcoming and never current", () => {
expect(isUpcoming({ upcoming: true })).toBe(true);
expect(isUpcoming({})).toBe(false);
expect(isCurrent({ end: "present", upcoming: true })).toBe(false);
expect(isCurrent({ upcoming: true })).toBe(false);
describe("roleState, localDay, languageDetail", () => {
it("a role with an end of `present` is the one in progress, any other end is not", () => {
expect(roleState({ end: "present" }, null)).toEqual({ upcoming: false, end: "present", current: true });
expect(roleState({ end: "2025" }, null)).toEqual({ upcoming: false, end: "2025", current: false });
expect(roleState({}, "2030-01-01")).toEqual({ upcoming: false, end: undefined, current: false });
});
it("`upcoming: true` has not begun, whatever the day, and is never current", () => {
for (const today of [null, "2026-11-01", "2099-01-01"]) expect(roleState({ upcoming: true }, today)).toEqual({ upcoming: true, end: undefined, current: false });
});
it("`upcoming: <day>` has not begun until that day, with the document as authored when the day is unknown (server, static page, hydration pass)", () => {
const r = { upcoming: "2026-11-30" } as const;
for (const today of [null, "2026-11-26", "2026-11-29"]) expect(roleState(r, today)).toEqual({ upcoming: true, end: undefined, current: false });
});
it("`upcoming: <day>` begins ON that day: the role is the one in progress, an absent end meaning `present`", () => {
const r = { upcoming: "2026-11-30" } as const;
for (const today of ["2026-11-30", "2026-12-01", "2027-06-15"]) expect(roleState(r, today)).toEqual({ upcoming: false, end: "present", current: true });
});
it("a begun `upcoming: <day>` role keeps a dated end, and is then not in progress", () => {
expect(roleState({ upcoming: "2026-11-30", end: "2027-05" }, "2026-12-01")).toEqual({ upcoming: false, end: "2027-05", current: false });
expect(roleState({ upcoming: "2026-11-30", end: "present" }, "2026-12-01")).toEqual({ upcoming: false, end: "present", current: true });
});
it("compares days as text, so a month or a year boundary is no special case", () => {
expect(roleState({ upcoming: "2027-01-01" }, "2026-12-31").upcoming).toBe(true);
expect(roleState({ upcoming: "2027-01-01" }, "2027-01-01").upcoming).toBe(false);
});
it("localDay is the visitor's calendar day, zero padded", () => {
expect(localDay(new Date(2026, 0, 5, 23, 59))).toBe("2026-01-05");
expect(localDay(new Date(2026, 10, 30, 0, 0))).toBe("2026-11-30");
});
it("joins the label and the level, never the same word twice", () => {
expect(languageDetail({ name: "English", level: "C2", label: "Native" })).toBe("Native, C2");
Expand Down
36 changes: 29 additions & 7 deletions apps/web/app/lib/career.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* The career page's pure part (docs/career-page.md): dates as the page shows them, the languages line, the share/structured-data
* facts. Everything is derived from the projection's `career` (nothing is invented) and the site's own name. No clock: the page
* shows authored months only ("as of September 2026"), never "x years ago", so server and client agree and nothing goes stale in a
* cached page.
* facts. Everything is derived from the projection's `career` (nothing is invented) and the site's own name. No clock, with ONE
* exception: the page shows authored months only ("as of September 2026"), never "x years ago", so server and client agree and nothing
* goes stale in a static file; the exception is `roleState` (a position that begins on a given day), which takes the day as an argument,
* and `localDay`, its only source, which the page calls in the browser after hydration (docs/career-page.md, "The one use of the clock").
*/
import type { PublishedCareer, PublishedCareerLanguage, PublishedCareerProject, PublishedCareerRole } from "@catalyst/schemas";
import type { IconName } from "~/components/ui/icon";
Expand Down Expand Up @@ -104,11 +105,32 @@ export function careerLogo(name: string): string | null {
return hit ? `/career-logos/${hit[1]}.webp` : null;
}

/** Whether a role is the one in progress (`end: present`, and begun). */
export const isCurrent = (r: Pick<PublishedCareerRole, "end" | "upcoming">): boolean => r.end === "present" && !r.upcoming;
/** Today's date in the browser as `YYYY-MM-DD`, the visitor's own calendar day (the page's one use of a clock: `roleState`, and only after hydration). */
export function localDay(d: Date = new Date()): string {
const two = (n: number) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${two(d.getMonth() + 1)}-${two(d.getDate())}`;
}

export interface RoleState {
/** Accepted, not begun: the page says "Joining", counts no stay, marks nothing as in progress. */
upcoming: boolean;
/** The end the page draws: the document's, except a begun `upcoming` role with no end, which is `present`. */
end: string | undefined;
/** The role in progress (`end: present`, and begun). */
current: boolean;
}

/** Whether a role is accepted but not begun (`upcoming: true`, authored: a month cannot tell the 30th from the 1st and the page reads no clock). */
export const isUpcoming = (r: Pick<PublishedCareerRole, "upcoming">): boolean => r.upcoming === true;
/**
* The state of a role on `today` (`YYYY-MM-DD`; null = unknown: the server, the static page and the hydration pass, which show the document as authored, so the first
* client render equals the prerendered HTML). `upcoming: true` stays so until the owner removes it; `upcoming: "YYYY-MM-DD"` stops on that day: the role is then begun, and
* without an end it is the one in progress (docs/career-page.md, "A position that has not begun"). Pure.
*/
export function roleState(r: Pick<PublishedCareerRole, "end" | "upcoming">, today: string | null): RoleState {
const day = typeof r.upcoming === "string" ? r.upcoming : null;
if (r.upcoming && !(day !== null && today !== null && today >= day)) return { upcoming: true, end: r.end, current: false };
const end = r.upcoming ? (r.end ?? "present") : r.end;
return { upcoming: false, end, current: end === "present" };
}

/** A language as the line reads it: the label and the level, not the same word twice (`Native, C2`; `A2`). */
export function languageDetail(l: PublishedCareerLanguage): string {
Expand Down
5 changes: 5 additions & 0 deletions apps/web/app/lib/llm-text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,9 @@ describe("listMarkdown and careerMarkdown", () => {
expect(md).toContain("Joining 2026-12 · ");
expect(md).not.toContain("2026-12 to now");
});
it("words a role with a start day with no state of its own: the twin is a static file and reads no clock", () => {
const career = projection.career!;
const md = careerMarkdown({ ...career, roles: [{ ...career.roles[0]!, start: "2026-12", end: undefined, upcoming: "2026-12-07" }, ...career.roles.slice(1)] }, ORIGIN);
expect(md).toContain("Starts 2026-12-07 · ");
});
});
2 changes: 1 addition & 1 deletion apps/web/app/lib/llm-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function careerMarkdown(career: PublishedCareer, origin: string): string
...career.roles.map((r) =>
[
`### ${r.title}, ${r.org}`,
`${r.upcoming ? `Joining ${r.start}${r.end && r.end !== "present" ? `, to ${r.end}` : ""}` : range(r.start, r.end)} · ${r.location}${r.employment ? ` · ${r.employment}` : ""}`,
`${r.upcoming ? `${typeof r.upcoming === "string" ? `Starts ${r.upcoming}` : `Joining ${r.start}`}${r.end && r.end !== "present" ? `, to ${r.end}` : ""}` : range(r.start, r.end)} · ${r.location}${r.employment ? ` · ${r.employment}` : ""}`,
...(r.highlights.length ? [r.highlights.map((h) => `- ${h}`).join("\n")] : []),
...(r.projects?.length ? [r.projects.map((p) => `- ${p.title}: ${p.summary}`).join("\n")] : []),
...(r.skills.length ? [`Skills: ${r.skills.join(", ")}`] : []),
Expand Down
Loading
Loading