Each year, the day after Thanksgiving, our family gathers to watch an entire day of movies. We eat leftovers and try to do as little as possible. It’s a lot of fun, especially after the chaos that is the day before.
Which movies we watch has become a bit of a competition. Everyone submits a theme and their suggested movies, the self-styled King of Sloth (my FIL) picks from our submissions, and we’re off to the races. This is our 8th year running.
When we tell friends about this, they always want to know more. What have the best themes been, do we have any fun ideas, how did it start, etc. Well, wonder no longer. Feast your eyes upon:
Tech wise, it’s yet another Astro & Tailwind affair. It let me model any data I have and provides strong typing for all of it. It’s one of my favorite developer experiences.
The data layer is intentionally simple. Authors and years are each simple toml files that I handwrite. Themes are MDX files- mostly markdown and the TMDB ids of the included movies.
The most interesting bit is the movie metadata (title, poster, etc). I’m always wary of coupling my ability to build the site to an external data source. But I also don’t want to enter that data by hand. So, I cut the middle: a sync script fetches data when I run the site locally, but I check in the result. So as long as I don’t add any new movies, the site will build indefinitely. Plus not needing to fetch any data at build time means those builds are lickety split. My API key never needs to leave my computer and, if push comes to shove, I can make manual edits to the stored data.
The one wrinkle was that you can’t query Astro’s content collections outside of an Astro-created process. Inside the site, I can get all the themes (and by extension, all the movies) using Astro’s query process:
import { getCollection } from "astro:content";
const themes = await getCollection("themes");const movies = themes.flatMap((theme) => theme.data.movies);But when I put the same code in my sync script, I got an error I’d never seen:
Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. Received protocol 'astro:'Turns out importing from astro:* only works if its dev server has done the necessary setup. Running node sync.ts doesn’t do that setup, so it errors out. Instead, I had to find all my files by hand and use gray-matter to parse the frontmatter:
const blogFiles = await Array.fromAsync( fs.glob("**/*.mdx", { cwd: themesDir }),);
const extractMovieIds = async (file: string): Promise<string[]> => { const raw = await fs.readFile(pjoin(themesDir, file), "utf-8"); const { data } = gm(raw);
try { return data.movies.map(extractTmdbId); } catch { throw new Error(`Error extracting tmdb IDs from theme "${file}"`); }};
const neededIds = new Set( (await Promise.all(blogFiles.map(extractMovieIds))).flat(),);// ...I had to be more careful than usual when organizing my utils. Nothing that imported from Astro could be in a file that the sync script needed. Not too bad, but more careful than I tend to be.
Once that stuff was sorted, this project was a lot of editing prose. I was cleaning up old emails, pulling tmdb ids, and clarifying old jokes. It was great reliving some of this family history and I’m glad we get to share our tradition with the world though.
Happy slothing!