diff --git a/documentation/reference-library-index.md b/documentation/reference-library-index.md index 51067daee..5412d2214 100644 --- a/documentation/reference-library-index.md +++ b/documentation/reference-library-index.md @@ -245,17 +245,17 @@ and a change here can break other maps. ### Data (static reference tables) -- **countries** — "value": "AFG", +- **countries** — (no description) `import … from '@map/data/countries.json'` -- **country-posters** — "stats": { +- **country-posters** — (no description) `import … from '@map/data/country-posters.json'` -- **iso-numeric-to-alpha2** — "4":"AF","8":"AL","12":"DZ","24":"AO","32":"AR","36":"AU","40":"AT","50":"BD", +- **iso-numeric-to-alpha2** — (no description) `import … from '@map/data/iso-numeric-to-alpha2.json'` -- **iso3-to-alpha2** — "_meta": { +- **iso3-to-alpha2** — alpha-3 -> alpha-2 so Intl.DisplayNames can produce a LOCALIZED country name. Drives no data fetch. `import … from '@map/data/iso3-to-alpha2.json'` -- **langFamilyByIso** — "aar": "Afro-Asiatic", +- **langFamilyByIso** — (no description) `import … from '@map/data/langFamilyByIso.json'` -- **langFamilyByLanguage** — {"Chamacoco":"Zamucoan","Ninam":"Yanomaman","Yagua":"Yaguan","Muinane":"Witotoan","Finnish":"Uralic","Hill Mar +- **langFamilyByLanguage** — (no description) `import … from '@map/data/langFamilyByLanguage.json'` ### API / data sources (`@map/api`) diff --git a/internal/generate-library-index.mjs b/internal/generate-library-index.mjs index 7921e0ab1..d144c1c83 100644 --- a/internal/generate-library-index.mjs +++ b/internal/generate-library-index.mjs @@ -23,6 +23,17 @@ const LIB = join(ROOT, 'library'); function firstDocLine(file) { let text; try { text = readFileSync(file, 'utf8'); } catch { return ''; } + // A .json file has no header comment: its first line is data ('"_meta": {', '"value": "AFG",'), so read + // the description a data file carries about itself, and otherwise say nothing rather than print a line of JSON. + if (file.endsWith('.json')) { + try { + const j = JSON.parse(text); + const m = j && typeof j === 'object' && !Array.isArray(j) ? j : {}; + const meta = m._meta && typeof m._meta === 'object' ? m._meta : {}; + const d = m._description || meta.description || meta.purpose || ''; + return typeof d === 'string' ? d.replace(/`/g, '').replace(/\s+/g, ' ').trim().slice(0, 110) : ''; + } catch { return ''; } + } const lines = text.split('\n').slice(0, 16); for (let raw of lines) { let l = raw.trim();