Step-by-step guide for generating Quran data, fonts, and static assets for open-quran-view.
The data generation process creates the local data files needed by open-quran-view:
Quran Foundation API → Local Data Files → Static Assets → Runtime
| Step | Source | Output |
|---|---|---|
| 1. Fetch Metadata | Quran Foundation API | src/data/metadata/ |
| 2. Fetch Pages | Quran Foundation API | src/data/pages/ |
| 3. Download Fonts | verses.quran.foundation | src/data/fonts/ |
| 4. Generate Static Assets | Local data files | src/core/static/ |
Create a .env file with Quran.com API credentials:
QURAN_CLIENT_ID=your_client_id
QURAN_CLIENT_SECRET=your_client_secret
Get credentials: Visit Quran.com API to register.
yarn install
Generates surah and juz metadata from the Quran Foundation API.
yarn generate:metadata
Output:
src/data/metadata/
├── surahs.json # 114 surahs with names, revelation info, page ranges
└── juz.json # 30 juz with verse ranges
Generates page data for all three Mushaf layouts from the Quran Foundation API.
yarn generate:pages
Mushaf Configurations:
| ID | Name | Word Fields | Output |
|---|---|---|---|
| 1 | Hafs QCF V2 | code_v2,text_qpc_hafs,line_number,page_number,position | hafs-v2 |
| 19 | Hafs QCF V4 Tajweed | code_v2,text_qpc_hafs,line_number,page_number,position | hafs-v4 |
| 5 | Hafs Unicode (QPC Hafs) | text_qpc_hafs,line_number,page_number,position | hafs-unicode |
Output:
src/data/pages/
├── hafs-v2/pages.json # 604 pages with QCF v2 glyph codes
├── hafs-v4/pages.json # 604 pages with QCF v4 glyph codes
└── hafs-unicode/pages.json # 604 pages with Unicode text
Downloads page-specific Quranic fonts from verses.quran.foundation.
yarn generate:fonts
Font Sources:
| Layout | Source URL |
|---|---|
| V2 | https://verses.quran.foundation/fonts/quran/hafs/v2/woff2/p{PAGE}.woff2 |
| V4 | https://verses.quran.foundation/fonts/quran/hafs/v4/colrv1/woff2/p{PAGE}.woff2 |
Output:
src/data/fonts/
├── hafs-v2/ # 604 .woff2 files (~25MB)
└── hafs-v4/ # 604 .woff2 files (~30MB)
Note: Fonts total ~50MB and may take several minutes to download.
Generates surah and juz metadata.
tsx scripts/fetch-metadata.ts
What it does:
.envsrc/data/metadata/Generates page data for all Mushaf layouts.
tsx scripts/fetch-pages.ts
What it does:
.envsrc/data/pages/{layout}/pages.jsonDownloads all font files.
tsx scripts/download-fonts.ts
What it does:
src/data/fonts/{layout}/Creates static font URL mappings.
yarn generate:static:fonts
# or
tsx scripts/generate-static-fonts.ts
What it does:
src/data/fonts/ for all font filessrc/core/static/fonts.tsCreates static data URL mappings.
yarn generate:static:data
# or
tsx scripts/generate-static-data.ts
What it does:
src/data/pages/ and src/data/metadata/src/core/static/data.tsStatic assets are pre-generated URLs that work reliably at runtime.
yarn generate:static
This runs:
generate-static-fonts.ts → src/core/static/fonts.tsgenerate-static-data.ts → src/core/static/data.tssrc/core/static/fonts.ts:
export const staticFonts = {
"hafs-v2": {
1: new URL("../../data/fonts/hafs-v2/p1.woff2", import.meta.url).href,
2: new URL("../../data/fonts/hafs-v2/p2.woff2", import.meta.url).href,
// ... 604 entries
},
"hafs-v4": { /* ... */ },
"hafs-unicode": { /* ... */ },
} as const;
export function getFontUrl(layout: MushafLayout, page: number): string {
return staticFonts[layout][page];
}
src/core/static/data.ts:
export const staticData = {
pages: {
"hafs-v2": new URL("../../data/pages/hafs-v2/pages.json", import.meta.url).href,
// ...
},
metadata: {
surahs: new URL("../../data/metadata/surahs.json", import.meta.url).href,
juz: new URL("../../data/metadata/juz.json", import.meta.url).href,
},
} as const;
# 1. Install dependencies
yarn install
# 2. Generate all data (metadata + pages + fonts)
yarn generate:all
# 3. Generate static assets
yarn generate:static
# 4. Build the package
yarn build
yarn install
The prepare script runs automatically:
yarn generate:allyarn build# Step 1: Generate metadata
yarn generate:metadata
# Step 2: Generate page data
yarn generate:pages
# Step 3: Download fonts
yarn generate:fonts
# Step 4: Generate static assets
yarn generate:static
# Step 5: Build
yarn build
Problem: Missing credentials in .env
Solution:
# Create .env file
echo "QURAN_CLIENT_ID=your_id" > .env
echo "QURAN_CLIENT_SECRET=your_secret" >> .env
Problem: API rate limiting or network issues
Solution: The scripts have built-in delays. If issues persist:
Problem: Some fonts fail to download
Solution: The download script shows progress. Failures are expected due to:
Re-run to download missing fonts:
yarn generate:fonts
Problem: Static assets not generated
Solution: Run static asset generation:
yarn generate:static
| Directory | Size | Notes |
|---|---|---|
src/data/metadata/ |
~100 KB | Small, committed to git |
src/data/pages/hafs-v2/ |
~25 MB | Git-ignored |
src/data/pages/hafs-v4/ |
~25 MB | Git-ignored |
src/data/fonts/hafs-v2/ |
~25 MB | Git-ignored |
src/data/fonts/hafs-v4/ |
~30 MB | Git-ignored |
| Total | ~105 MB | Excludes metadata |