Skip to content

Commit 01e746a

Browse files
Refactor Conf Code (#153)
1 parent 0b94abb commit 01e746a

11 files changed

+61
-809
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ WORKDIR /remixapp
4747

4848
COPY --from=production-deps /remixapp/node_modules /remixapp/node_modules
4949
COPY --from=build /remixapp/build /remixapp/build
50-
COPY --from=build /remixapp/data /remixapp/data
5150
COPY --from=build /remixapp/server.js /remixapp/server.js
5251
COPY --from=build /remixapp/package.json /remixapp/package.json
5352
COPY --from=build /remixapp/start.sh /remixapp/start.sh

app/lib/conf.server.ts renamed to app/lib/conf2022.server.ts

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import fsp from "fs/promises";
2-
import path from "path";
31
import invariant from "tiny-invariant";
42
import { processMarkdown } from "~/lib/md.server";
53

@@ -27,6 +25,11 @@ import {
2725
sluggify,
2826
} from "./conf";
2927

28+
import speakersYamlFileContents from "../../data/conf/2022/speakers.yaml?raw";
29+
import sponsorsYamlFileContents from "../../data/conf/2022/sponsors.yaml?raw";
30+
import talksYamlFileContents from "../../data/conf/2022/talks.yaml?raw";
31+
import scheduleYamlFileContents from "../../data/conf/2022/schedule.yaml?raw";
32+
3033
let cache = new LRUCache<
3134
string,
3235
Array<Speaker> | Array<Sponsor> | Array<Talk> | Array<ScheduleItem>
@@ -38,30 +41,13 @@ let cache = new LRUCache<
3841
},
3942
});
4043

41-
const DATA_DIR = path.join(process.cwd(), "data");
42-
const CONF_ROOT_DIR = path.join(DATA_DIR, "conf");
43-
44-
function getConfPaths(year: ConfYear) {
45-
let confDir = path.join(CONF_ROOT_DIR, String(year));
46-
return {
47-
speakersFile: path.join(confDir, "speakers.yaml"),
48-
sponsorsFile: path.join(confDir, "sponsors.yaml"),
49-
talksFile: path.join(confDir, "talks.yaml"),
50-
scheduleFile: path.join(confDir, "schedule.yaml"),
51-
};
52-
}
53-
54-
type ConfYear = 2022 | 2023;
55-
56-
export async function getSpeakers(year: ConfYear) {
57-
let cached = cache.get(`speakers-${year}`);
44+
export async function getSpeakers() {
45+
let cached = cache.get("speakers");
5846
if (isSpeakerArray(cached)) {
5947
return cached;
6048
}
6149

62-
let { speakersFile: SPEAKERS_FILE } = getConfPaths(year);
63-
let speakersFileContents = await fsp.readFile(SPEAKERS_FILE, "utf8");
64-
let speakersRaw = yaml.parse(speakersFileContents);
50+
let speakersRaw = yaml.parse(speakersYamlFileContents);
6551
let speakers: Array<Speaker> = [];
6652
for (let speakerRaw of speakersRaw) {
6753
let { html: bioHTML } = await processMarkdown(speakerRaw.bio);
@@ -86,15 +72,13 @@ export async function getSpeakers(year: ConfYear) {
8672
return speakers;
8773
}
8874

89-
export async function getSponsors(year: ConfYear) {
90-
let cached = cache.get(`sponsors-${year}`);
75+
export async function getSponsors() {
76+
let cached = cache.get("sponsors");
9177
if (isSponsorArray(cached)) {
9278
return cached;
9379
}
9480

95-
let { sponsorsFile: SPONSORS_FILE } = getConfPaths(year);
96-
let sponsorsFileContents = await fsp.readFile(SPONSORS_FILE, "utf8");
97-
let sponsorsRaw = yaml.parse(sponsorsFileContents);
81+
let sponsorsRaw = yaml.parse(sponsorsYamlFileContents);
9882
let sponsors: Array<Sponsor> = [];
9983
for (let sponsorRaw of sponsorsRaw) {
10084
invariant(
@@ -110,15 +94,13 @@ export async function getSponsors(year: ConfYear) {
11094
return sponsors;
11195
}
11296

113-
export async function getTalks(year: ConfYear) {
114-
let cached = cache.get(`talks-${year}`);
97+
export async function getTalks() {
98+
let cached = cache.get("talks");
11599
if (isTalkArray(cached)) {
116100
return cached;
117101
}
118102

119-
let { talksFile: TALKS_FILE } = getConfPaths(year);
120-
let talksFileContents = await fsp.readFile(TALKS_FILE, "utf8");
121-
let talksRaw = yaml.parse(talksFileContents);
103+
let talksRaw = yaml.parse(talksYamlFileContents);
122104
let talks: Array<Talk> = [];
123105
for (let talkRaw of talksRaw) {
124106
invariant(
@@ -138,18 +120,16 @@ export async function getTalks(year: ConfYear) {
138120
return talks;
139121
}
140122

141-
export async function getSchedule(year: ConfYear) {
142-
let cached = cache.get(`schedule-${year}`);
123+
export async function getSchedule() {
124+
let cached = cache.get("schedule");
143125
if (isScheduleItemArray(cached)) {
144126
return cached;
145127
}
146128

147-
let { scheduleFile: SCHEDULE_FILE } = getConfPaths(year);
148-
let allTalks = await getTalks(year);
149-
let allSpeakers = await getSpeakers(year);
129+
let allTalks = await getTalks();
130+
let allSpeakers = await getSpeakers();
150131

151-
let schedulesFileContents = await fsp.readFile(SCHEDULE_FILE, "utf8");
152-
let scheduleItemsRaw = yaml.parse(schedulesFileContents);
132+
let scheduleItemsRaw = yaml.parse(scheduleYamlFileContents);
153133
let scheduleItems: Array<ScheduleItem> = [];
154134

155135
for (let scheduleItemRaw of scheduleItemsRaw) {

app/lib/conf2023.server.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import LRUCache from "lru-cache";
22
import { DateTime } from "luxon";
3+
import yaml from "yaml";
4+
import invariant from "tiny-invariant";
35
import {
46
sluggify,
57
validateSessionizeSessionData,
68
validateSessionizeSpeakerData,
79
} from "./conf2023";
10+
import sponsorsYamlFileContents from "../../data/conf/2023/sponsors.yaml?raw";
811
import type {
912
Speaker,
1013
SpeakerSession,
@@ -13,20 +16,23 @@ import type {
1316
SessionizeSpeakerData,
1417
SessionizeSessionData,
1518
} from "./conf2023";
19+
import type { Sponsor } from "./conf";
20+
import { isSponsor, isSponsorArray } from "./conf";
1621

1722
const CONF_TIME_ZONE = "America/Denver";
1823
const NO_CACHE =
1924
process.env.NO_CACHE != null ? process.env.NO_CACHE === "true" : undefined;
2025
const SPEAKERS_CACHE_KEY = "speakers";
2126
const SESSIONS_CACHE_KEY = "sessions";
2227
const SCHEDULES_CACHE_KEY = "schedules";
28+
const SPONSORS_CACHE_KEY = "schedules";
2329
const SESSIONIZE_ENDPOINT = "https://sessionize.com/api/v2/s8ds2hnu";
2430
const SESSIONIZE_API_DETAILS_URL =
2531
"https://sessionize.com/app/organizer/schedule/api/endpoint/9617/7818";
2632

2733
let cache = new LRUCache<
2834
"speakers" | "sessions" | "schedules",
29-
(Speaker | SpeakerSession | Schedule)[]
35+
(Speaker | SpeakerSession | Schedule | Sponsor)[]
3036
>({
3137
max: 250,
3238
maxSize: 1024 * 1024 * 12, // 12 mb
@@ -495,3 +501,25 @@ async function fetchNaiveStaleWhileRevalidate(
495501
});
496502
}
497503
}
504+
505+
export async function getSponsors() {
506+
let cached = cache.get(SPONSORS_CACHE_KEY);
507+
if (isSponsorArray(cached)) {
508+
return cached;
509+
}
510+
511+
let sponsorsRaw = yaml.parse(sponsorsYamlFileContents);
512+
let sponsors: Array<Sponsor> = [];
513+
for (let sponsorRaw of sponsorsRaw) {
514+
invariant(
515+
isSponsor(sponsorRaw),
516+
`Sponsor ${JSON.stringify(
517+
sponsorRaw,
518+
)} is not valid. Please check the sponsors file.`,
519+
);
520+
sponsors.push(sponsorRaw);
521+
}
522+
cache.set(SPONSORS_CACHE_KEY, sponsors);
523+
524+
return sponsors;
525+
}

app/routes/conf.2022._index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { OutlineButtonLink, primaryButtonLinkClass } from "~/ui/buttons";
77
import "~/styles/index.css";
88
import { Fragment } from "react";
99
import type { Sponsor, Speaker } from "~/lib/conf";
10-
import { getSpeakers, getSponsors } from "~/lib/conf.server";
10+
import { getSpeakers, getSponsors } from "~/lib/conf2022.server";
1111
import { Link } from "~/ui/link";
1212
import { CACHE_CONTROL } from "~/lib/http.server";
1313

@@ -35,7 +35,7 @@ export const meta: MetaFunction<typeof loader> = (args) => {
3535
};
3636

3737
export const loader = async ({ request }: LoaderFunctionArgs) => {
38-
const speakersOrdered = await getSpeakers(2022);
38+
const speakersOrdered = await getSpeakers();
3939
const speakersShuffled = speakersOrdered
4040
// save a bit of data by not sending along the bio to the home page
4141
.map(
@@ -47,7 +47,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
4747
)
4848
.sort(() => Math.random() - 0.5);
4949

50-
const allSponsors = await getSponsors(2022);
50+
const allSponsors = await getSponsors();
5151
const sponsors = {
5252
premier: allSponsors.find((s) => s.level === "premier"),
5353
gold: allSponsors

app/routes/conf.2022._inner.schedule.may-25.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { json } from "@remix-run/node";
33
import { Link, useLoaderData } from "@remix-run/react";
44
import type { MetaFunction } from "@remix-run/react";
55
import { metaV1 } from "@remix-run/v1-meta";
6-
import { getSchedule } from "~/lib/conf.server";
6+
import { getSchedule } from "~/lib/conf2022.server";
77
import { CACHE_CONTROL } from "~/lib/http.server";
88
import { sluggify } from "~/lib/conf";
99

@@ -17,7 +17,7 @@ export const meta: MetaFunction = (args) => {
1717
type LoaderData = { scheduleItems: Awaited<ReturnType<typeof getSchedule>> };
1818

1919
export const loader: LoaderFunction = async () => {
20-
const scheduleItems = await getSchedule(2022);
20+
const scheduleItems = await getSchedule();
2121
return json<LoaderData>(
2222
{ scheduleItems },
2323
{ headers: { "Cache-Control": CACHE_CONTROL.DEFAULT } },

app/routes/conf.2022._inner.speakers.$speakerSlug.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import type { MetaFunction } from "@remix-run/react";
1010
import { json } from "@remix-run/node";
1111
import { metaV1 } from "@remix-run/v1-meta";
12-
import { getSpeakers, getTalks } from "~/lib/conf.server";
12+
import { getSpeakers, getTalks } from "~/lib/conf2022.server";
1313
import "~/styles/conf-speaker.css";
1414
import { sluggify } from "~/lib/conf";
1515
import { CACHE_CONTROL } from "~/lib/http.server";
@@ -34,8 +34,8 @@ export const meta: MetaFunction<typeof loader> = (args) => {
3434

3535
export const loader = async ({ params }: LoaderFunctionArgs) => {
3636
const [allTalks, allSpeakers] = await Promise.all([
37-
getTalks(2022),
38-
getSpeakers(2022),
37+
getTalks(),
38+
getSpeakers(),
3939
]);
4040
const speaker = allSpeakers.find((s) => s.slug === params.speakerSlug);
4141
if (!speaker) throw new Response("Speaker not found", { status: 404 });

app/routes/conf.2022._inner.workshops.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default function Workshops() {
4242
href="https://twitter.com/kentcdodds"
4343
>
4444
<img
45-
src="/k.jpg"
45+
src="/authors/profile-kent-c-dodds.png"
4646
alt="Kent C. Dodds"
4747
className="w-36 rounded-md"
4848
/>
@@ -53,7 +53,7 @@ export default function Workshops() {
5353
href="https://twitter.com/ryanflorence"
5454
>
5555
<img
56-
src="/r.jpg"
56+
src="/authors/profile-ryan-florence.png"
5757
alt="Ryan Florence"
5858
className="w-36 rounded-md"
5959
/>

app/routes/conf.2023._index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import {
1010
} from "~/ui/buttons";
1111
import "~/styles/index.css";
1212
import { Fragment } from "react";
13-
import { getSponsors } from "~/lib/conf.server";
1413
import type { Sponsor, SponsorLevel } from "~/lib/conf";
1514
import { Link } from "~/ui/link";
1615
import { CACHE_CONTROL } from "~/lib/http.server";
17-
import { getSpeakers } from "~/lib/conf2023.server";
16+
import { getSpeakers, getSponsors } from "~/lib/conf2023.server";
1817
import type { Speaker } from "~/lib/conf2023";
1918

2019
export const meta: MetaFunction<typeof loader> = (args) => {
@@ -50,7 +49,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
5049
console.error(err);
5150
}
5251

53-
let allSponsors = await getSponsors(2023);
52+
let allSponsors = await getSponsors();
5453
let sponsors: Partial<Record<SponsorLevel, Sponsor[]>> = {};
5554
for (let sponsor of allSponsors.sort(randomSort)) {
5655
let level = sponsor.level;
@@ -149,7 +148,7 @@ function EarlySponsors() {
149148
</p>
150149
<div className="w-72 max-w-full sm:w-80 xl:w-96">
151150
<GridCell>
152-
<GridCellLink to=".">
151+
<GridCellLink to="https://shopify.com/">
153152
<div className="flex w-full p-12 md:p-14 lg:p-16 2xl:p-20">
154153
<LogoShopify className="h-auto w-full" aria-hidden />
155154
</div>

data/conf/2023/schedule.yaml

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)