My personal website. It's plain HTML, CSS and JavaScript, hosted on Cloudflare Pages. A few small Cloudflare Functions handle the live parts: my latest workout, my lifting and running history, and what I'm listening to on Spotify.
This file explains what I built and why I built it that way.
- One screen, one photo. The home page fits in the window with no scrolling. A big photo album sits in the middle, my name is on the left, links are on the right. Someone should learn who I am in a few seconds.
- Black and gold. Midnight black, not pure black, with gold text and icons and rose gold on hover.
- Show real things I do. My lifting and running are live from the apps I use, not typed in by hand. My music is live from Spotify.
- Keep it simple to change. Adding a photo, or changing which photo starts a group, should mean editing one line.
The site is a handful of pages, so there's no framework and no build tool. build.sh just copies files into dist/. Plain files load fast, and there's nothing to upgrade or break.
-
Photo album (
album.js,photos.js). The photos are in groups: Me, Cat, Nature, Loved ones and Food. The first photo in each group is its cover.- Left alone, the album moves to the next group's cover every 5 seconds, so visitors see a little of everything.
- Hovering pins the photo, and scrolling flips through that group. Since the page itself never scrolls, the scroll wheel can mean "next photo".
- When the mouse leaves, the album carries on. Coming back to a group starts again from its cover.
- On phones, swiping does the same thing.
- A group's other photos only download when someone looks at that group, so the page stays light.
- Photos are resized to 1400 px, and their location data is removed.
-
Name. "Andy He" and "CS @ Waterloo" are the same width (
home.jsmeasures them), so they read as one block. My Chinese name, 何天俊, runs down the left side with its pinyin. -
Waterloo card. Hovering "Waterloo" shows a short note about the University of Waterloo and its co-op program, with a link to the school's About page. Not every company abroad knows the school, so this saves them a search.
-
Theme (
style.css). It's one dark theme with no light mode, so the site always looks the way I designed it. The background has a soft glow and a faint grain, so it feels like leather instead of a flat screen. -
UW CS webring. The top of the icon column links to the webring for Waterloo CS students. The arrows go up and down instead of left and right because the column is vertical. The lion is the webring's own icon (MIT licence), recoloured gold to match the other icons.
-
Right column. My most recent workout sits at the top right and what I was just listening to sits at the bottom right, so they line up with the top and bottom of the photo.
- The real thing, not screenshots (
projects/,projects.js). My old screenshots were mostly walls of small text that didn't show what the projects do. On a wide screen, the list is on the left and the selected project's live demo runs on the right, so you can click around in it without leaving the page.- Pointing at a project shows it after a short pause, so sweeping the mouse down the list doesn't load every demo.
- Each demo is drawn at desktop width and scaled down, like a small browser window. Tabby is a phone app, so it gets a phone-sized frame.
- At most three demos stay loaded at once, to keep the page light.
- On phones there's no room for a second window, so each project shows its description, tools and "Try it" link instead.
- No work history here. My experience is on my resume (linked from the home page), so this page is only about things I built.
- Lifting comes from Hevy (
lib/hevy.js). Hevy's public profile only shows my latest workout. So a small Cloudflare Worker (workers/hevy-sync) checks every hour and saves each new workout to a Cloudflare D1 database. My older history came from a one-time Hevy export (scripts/import_hevy_csv.py).- I used to log some dumbbell lifts as one dumbbell and later as both.
db/adjustments.sqlfixes the older sets so the charts compare like with like.
- I used to log some dumbbell lifts as one dumbbell and later as both.
- Runs come from my Strava export (
scripts/import_strava_csv.py). Weight-training entries in the export are copies that Hevy sent to Strava, so they're skipped to avoid counting a workout twice. - Past year only. Totals, the calendar and the strength chart all cover today back to the same day last year. Every number on the page covers the same window, so the numbers agree with each other.
- Two colours. Lifts are gold and runs are rose, everywhere on the page, so they're easy to tell apart.
- Route shapes (
scripts/strava_routes.py). The run card shows the shape of my latest route. For privacy, the first and last 300 m are cut off, and only the shape is kept, scaled into a 100 × 100 box. There are no map coordinates and no map underneath, so the route can't be traced back to where I live. - Muscle map (
muscles.js). The lift card shows a front and back body with the muscles from that workout filled in. Main muscles are solid, and supporting ones are lighter. It runs on Hevy's own muscle labels, so new exercises work without code changes. The figures are drawn for this site rather than borrowed from Hevy, since Hevy's images belong to Hevy.
- What I'm listening to (
functions/api/now-playing.js). The player shows the song playing right now, or the last one played. - My Spotify Wrapped (
wrapped.js,functions/api/wrapped.js). This grew out of my project Monthly Spotify Wrapped. A button under the player opens a card with:- my top 5 songs and artists for the last 4 weeks, 6 months or year, and my #1 song playable right in the card (both carried over from the original project);
- minutes listened in that window;
- plays of my #1 song;
- my longest daily listening streak;
- a listening clock showing which hours of the day I listen most.
- Real numbers, not rankings. Spotify's API only gives a ranked list of top songs and artists, with no counts. I didn't want stats that were just rankings dressed up as numbers, so every number on the card comes from a log of what I actually played.
- Site colours. My original project took its colours from the #1 album cover. Here the card stays midnight and gold, so it looks like part of the site.
- No empty card. The button only appears once real numbers have loaded.
- Genres can be blank. Spotify often leaves genres out now. When an artist has none, the card shows how many of my top songs they're on.
- Private. Visitors never sign in to anything. Only songs and artists are linked, never the account.
- The listening log (
lib/plays.js,functions/api/spotify-log.js,workers/spotify-log). Spotify's API has no play counts or minutes, and "recently played" only remembers the last 50 songs.- So every 30 minutes, a small worker asks the site to save any new plays to the database. 50 songs is about 2.5 hours of music, so nothing is missed between saves.
- Spotify doesn't say how long a song played, only when it finished. A song can't have played longer than the time since the one before it finished, so each play counts as the shorter of its length and that gap. Skipped songs only count the time they were on.
- The worker doesn't hold any Spotify keys. It only sends a shared key to the site, and the site does the work.
- Older plays can be filled in once from a Spotify data download (
scripts/import_spotify_history.py). That script skips plays under 30 seconds, the same rule Spotify uses, so old and new numbers mean the same thing. - Until the log covers a whole window, the card says when counting started.
- Connecting Spotify (
functions/api/spotify-connect.js,functions/spotify-callback.js,lib/spotify.js). I approve the site once, and it saves its own sign-in to the database. There's nothing to copy and paste. The approval link only works when made by the site.
I built the site at andyhe.ca/testing behind a password, so I could try everything on the real domain before anyone saw it. Now that it's public, old /testing links send people to the same page at the root (functions/_middleware.js). The only page still behind my password is the one that connects Spotify to the site, so nobody else can connect a different account.
| Path | What it is |
|---|---|
index.html, style.css |
Home page and the one stylesheet |
photos.js, photos/ |
The album: groups, order, covers |
album.js, home.js, live.js |
Album, name sizing, music and latest workout |
wrapped.js |
The Spotify Wrapped card |
exercise/, exercise.js, muscles.js, workout.js |
Exercise page |
projects/, projects.js |
Projects page |
functions/ |
Cloudflare Pages Functions (the /api endpoints, the password gate) |
lib/ |
Code shared by the functions and the worker |
workers/hevy-sync/ |
The hourly Hevy job |
workers/spotify-log/ |
The 30-minute Spotify log job |
db/ |
Database tables and one-time fixes |
scripts/ |
One-time importers for Hevy, Strava and Spotify downloads |
sh build.shbuildsdist/, which goes to Cloudflare Pages. It also stamps each CSS and JS link with a fingerprint of the file (scripts/version_assets.py), because Cloudflare lets browsers keep those files for hours; the stamp changes whenever a file does, so visitors always get the latest version.- Keys are encrypted environment variables in Cloudflare, never in this repo:
SPOTIFY_CLIENT_ID,SPOTIFY_CLIENT_SECRET,TEST_PASSWORD, andLOG_KEY(shared with the spotify-log worker). - The database is bound as
DB. Its tables are indb/schema.sql. - Exports from Hevy, Strava and Spotify stay in
data/, which is never committed.