This site has two small tools: an airport distance calculator, and Fukuoka weather and outfits. Both work, but in Google's eyes each is "one page with one input box". I checked Google autocomplete for common Taiwanese searches and found that people are searching for:
- "Taipei to Fukuoka flight distance", "Taoyuan airport distance"
- "Fukuoka March outfit", "Fukuoka December outfit"
(These searches are in Chinese; the site is mainly for Taiwanese travelers to Japan.) People who search want to see the answer directly, not type it in. So I split each of the two tools into "one answer, one page": 30 flight routes and 12 months, 42 pages in all, all statically generated.
Principle: the first sentence is the answer, and numbers are never hand-written
Each page's first sentence gives the conclusion directly, for example:
The straight-line distance from Taipei (Taoyuan, TPE) to Fukuoka (FUK) is about 1,300 km (810 miles), with a flight time of about 2 hours 8 minutes.
That sentence, the page title, the description and the numbers in the table are all computed by the same function, not typed by me. This has three benefits: if I later change the method (say, the cruising speed), all pages update together; numbers cannot have typos; and unit tests can cover it.
For the distance pages: 5 Taiwanese airports times 6 Japanese airports, computed with the great-circle distance formula, with flight time roughly estimated as "distance ÷ 800 km/h + 30 minutes for takeoff and landing". The page says it is a rough estimate that ignores wind. The coordinates are hard-coded in the code, but a unit test compares them with the airports.json used by the interactive tool, and fails if the two disagree.
Temperatures can't come from impressions: compute from real data
An outfit page needs "average temperature in March". This kind of number is easiest to write from impressions, so I do not write it. Instead I use Open-Meteo's historical weather API (free, no key) to fetch ten years, 2015 to 2024, of daily highs, lows and precipitation, with a script that computes each month's average and outputs one JSON file into the project. The pages only read that JSON.
The clothing advice follows a few brackets of "average high" (12, 17, 22, 27 degrees), with any month whose low is below 5 degrees counted as heavy winter wear, and each bracket maps to a list. The rules are in code, with the boundaries covered by tests.
When the data disagrees with intuition: be honest
I had assumed "Kaohsiung is warmer than Fukuoka every month", and the page copy said so: "about N degrees colder than Kaohsiung". A unit test stopped that assumption: in August, Fukuoka's average high is 31.3°C and Kaohsiung's only 30.3°C, so Fukuoka comes out hotter.
That is very unlikely to be true (Kaohsiung's summer is not actually cooler than Fukuoka's). The cause is in the data itself: Open-Meteo's historical data is ERA5 reanalysis, with grid cells of about 25 km, and coastal cities get "pulled down" by the sea surface. I did two things:
- Make the copy conditional: if the daytime difference is under 2 degrees, do not write "colder than Kaohsiung" and write "about the same temperature as Kaohsiung, no need to change seasons" instead. Only in winter, when the difference is over 10 degrees, does it say "about 14 degrees colder than Kaohsiung".
- State it honestly on the page: each page says at the bottom where the data comes from, the period, the resolution, and "this can differ by a degree or two from weather station measurements, and is not official Japan Meteorological Agency statistics".
If I had written the test as "Fukuoka is always colder than Kaohsiung" to match my assumption, this error would have gone onto 12 pages as fact.
Two traps hit along the way
With more pages, a test's time limit was no longer enough. One test in the project opens every page in the sitemap one by one to check for CSP violations, with a limit of 240 seconds. After the page count grew from fifty-odd to ninety-odd, CI's dev-mode server (which has to compile each page on demand) could not finish, and it timed out twice in a row. Before simply raising the limit I checked: one page (the newly added /ask) always had a request running, so it never reached "network idle", and that hung the test. The fix is to wait at most 15 seconds per page and move on if it does not settle, while still collecting violations.
Shared computation has to be extracted. The distance formula used to live in the interactive tool's component. After extracting it into a shared function, I also fixed an old bug: flight time computed minutes with Math.round((h % 1) * 60), which shows "2 hours 60 minutes" for 2.9999 hours. The new hm() rounds the total minutes first and then splits, so 60 minutes never appears.
Summary
- Check Google autocomplete for search terms, and split a "tool" into "one answer per page"; the first sentence is the answer
- Every number on a page is computed by code, not hand-written; the data and algorithm need tests
- Store external data as JSON inside the project first (generated by a script, committed to git), and have the pages read only that, never calling the external API at request time
- When data disagrees with intuition, do not make the test follow intuition: make the copy conditional, and state the data source and its limits on the page
- When pages multiply, check that the tests that "go through every page" can still finish