This is a project to create an interactive accompaniment to the book The Banished Immortal: A Life of Li Bai, by Ha Jin. The book details the life story of the eighth-century Tang Dynasty poet Li Bai, widely recognized as one of the greatest if not the greatest Chinese poet in history.
Li Bai led a nomadic life, moving frequently throughout China as he sought to advance his career. While the book tells a compelling story, some may find it difficult to track the movement of the protagonist without a map. This project aims to create an accompanying tracker to add to the experience of reading the book.
The itinerary traced in the map is saved in src/data/libai-stop.json, a GeoJSON file. src/data/README.md describes each field.
The site is a Vite + React 19 + TypeScript single-page app. The map uses mapbox-gl 1.x, and the controls are built with ui-sdk.
- Use the current Node LTS and run
npm install. - Copy
.env.exampleto.env.localand setVITE_MAPBOX_API_TOKENto a Mapbox public access token. - Run
npm run dev.
| Script | What it does |
|---|---|
npm run dev |
Start the dev server |
npm run build |
Type check and build static files into dist/ |
npm run preview |
Serve the production build locally |
npm test |
Run the Vitest suite |
npm run lint |
Lint with oxlint |
The site builds through Vercel with each commit. The project settings need:
- Framework preset: Vite. The build command is
npm run buildand the output directory isdist. - Environment variable
VITE_MAPBOX_API_TOKENholding the Mapbox token. It replaces the oldGATSBY_MAPBOX_API_TOKEN. - Environment variables
AZURE_SPEECH_KEYandAZURE_SPEECH_REGIONfor poem narration (see below). They have noVITE_prefix, so they stay on the server.
The poem reader's Listen button reads the Chinese poem aloud, line by line. Each line comes from /api/narrate (api/narrate.ts), a Vercel function that asks Azure AI Speech to read it in the poetry-reading style.
- Create an Azure AI Speech resource and copy one of its keys and its region (for example
eastasia). - Set
AZURE_SPEECH_KEYandAZURE_SPEECH_REGIONin the Vercel project, and in.env.localfornpm run dev, which serves the same function. - The voice, style, pace and pause live in
src/narration/voice.ts. Responses are cached at the CDN for a year, so bumpVOICE_VERSIONthere whenever you change the voice.
The function only speaks lines from src/data/libai-stop.json and rejects any other URL. Without the Azure variables it answers 503, and the reader falls back to a Chinese voice built into the browser, or says narration is unavailable when the browser has none.
The first version of this site was based on the Gatsby-Mapbox starter by brendan-ward.