Files
leetcode/apps/docs/companies.ts
T

37 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* The `companies:` frontmatter vocabulary, shared by its writer
* (`apps/cli/sync.ts`, from the local DuckDB company-frequency database), its
* schema (`blume.config.ts`) and its two readers: the company table under a
* problem page's badge row (`components/ProblemBadges.astro`) and the
* Companies section of the Appendix (`pages/appendix.astro`), where each
* company's card — anchored at `companyHref()` — lists the problems it asked.
* Plain data, no Astro imports: sync imports this file under Bun.
*/
/** The database's recency windows, most recent first; they nest, so a company is filed under the first it appears in. */
export const RECENCY = ["Thirty Days", "Three Months", "Six Months"] as const;
export type Recency = (typeof RECENCY)[number];
/** Read under an "Asked within" heading (the company table) or as a row chip (the Appendix card). */
export const RECENCY_LABEL: Record<Recency, string> = {
"Thirty Days": "30 days",
"Three Months": "3 months",
"Six Months": "6 months",
};
export interface Company {
name: string;
/** The most recent window the company asked the problem in. */
period: Recency;
/** 5–100, relative within the company and window: 100 is its most-asked problem there. */
frequency: number;
}
/** The company's card on the Appendix; `company-` keeps it clear of the tag cards' `#<slug>` ids. */
export function companyHref(name: string): string {
return `/appendix#company-${name
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-|-$/g, "")}`;
}