diff --git a/api/src/import.ts b/api/src/import.ts index ce4f6368..8c6e527d 100644 --- a/api/src/import.ts +++ b/api/src/import.ts @@ -31,11 +31,13 @@ for (const entry of manifest.Poets) { try { await client.query('BEGIN'); await client.query( - `INSERT INTO poets (id, url, name, nickname, description, birth_year_ah, death_year_ah) - VALUES ($1,$2,$3,$4,$5,$6,$7) - ON CONFLICT (id) DO UPDATE SET url=$2, name=$3, nickname=$4, description=$5, birth_year_ah=$6, death_year_ah=$7`, + `INSERT INTO poets (id, url, name, nickname, description, birth_year_ah, death_year_ah, birth_year_ce, death_year_ce) + VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9) + ON CONFLICT (id) DO UPDATE SET url=$2, name=$3, nickname=$4, description=$5, birth_year_ah=$6, death_year_ah=$7, + birth_year_ce=$8, death_year_ce=$9`, [poet.Id, poet.FullUrl, poet.Name, poet.Nickname, poet.Description, - poet.ValidBirthDate ? poet.BirthYearInLHijri : null, poet.ValidDeathDate ? poet.DeathYearInLHijri : null], + poet.ValidBirthDate ? poet.BirthYearInLHijri : null, poet.ValidDeathDate ? poet.DeathYearInLHijri : null, + poet.BirthYearCE ?? null, poet.DeathYearCE ?? null], ); // categories depth-first so parents exist before children const walk = async (url: string, position: number): Promise => { diff --git a/api/src/server.ts b/api/src/server.ts index 85132b1f..335232ed 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -17,7 +17,7 @@ app.get('/health', async () => { app.get('/api/poets', async () => { const { rows } = await pool.query( - 'SELECT id, url, name, nickname, birth_year_ah, death_year_ah, pin_order FROM poets ORDER BY birth_year_ah NULLS LAST, nickname', + 'SELECT id, url, name, nickname, birth_year_ah, death_year_ah, birth_year_ce, death_year_ce, pin_order FROM poets ORDER BY birth_year_ah NULLS LAST, nickname', ); return rows; }); diff --git a/db/schema.sql b/db/schema.sql index ffb729e0..c94aa7e8 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -15,6 +15,8 @@ CREATE TABLE IF NOT EXISTS poets ( pin_order integer -- featured on the home page (db/featured.sql) ); ALTER TABLE poets ADD COLUMN IF NOT EXISTS pin_order integer; +ALTER TABLE poets ADD COLUMN IF NOT EXISTS birth_year_ce integer; -- Gregorian (عیسوی) +ALTER TABLE poets ADD COLUMN IF NOT EXISTS death_year_ce integer; CREATE TABLE IF NOT EXISTS categories ( id integer PRIMARY KEY, diff --git a/web/src/lib/urdu.ts b/web/src/lib/urdu.ts index bc4946d5..18e3ee3b 100644 --- a/web/src/lib/urdu.ts +++ b/web/src/lib/urdu.ts @@ -8,5 +8,8 @@ const ORDINALS = ['', 'پہلی', 'دوسری', 'تیسری', 'چوتھی', 'پ export const centuryOf = (yearAh: number | null) => (yearAh ? Math.floor(yearAh / 100) + 1 : null); export const centuryName = (c: number | null) => (c ? `${ORDINALS[c] ?? ud(c)} صدی ہجری` : 'دیگر شعرا'); -export const years = (birth: number | null, death: number | null) => - birth || death ? `${birth ? ud(birth) : '؟'} – ${death ? ud(death) : '؟'} ھ` : ''; +const span = (a: number | null, b: number | null, mark: string) => + a || b ? `${a ? ud(a) : '؟'} – ${b ? ud(b) : '؟'} ${mark}` : ''; +// Hijri and Gregorian (عیسوی): "۱۲۹۴ – ۱۳۵۷ ھ · ۱۸۷۷ – ۱۹۳۸ ء" +export const years = (p: { birth_year_ah: number | null; death_year_ah: number | null; birth_year_ce?: number | null; death_year_ce?: number | null }) => + [span(p.birth_year_ah, p.death_year_ah, 'ھ'), span(p.birth_year_ce ?? null, p.death_year_ce ?? null, 'ء')].filter(Boolean).join(' · '); diff --git a/web/src/pages/[...path].astro b/web/src/pages/[...path].astro index 752fcca5..94241bfd 100644 --- a/web/src/pages/[...path].astro +++ b/web/src/pages/[...path].astro @@ -34,7 +34,7 @@ const title = page.type === 'poem' ? page.poem.title : page.type === 'poet' ? pa {page.type === 'poet' && ( <>

{page.poet.name}

-

{years(page.poet.birth_year_ah, page.poet.death_year_ah)}

+

{years(page.poet)}

{page.poet.description &&
{page.poet.description}
} )} diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index bc1843e1..4c29ee8e 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -29,7 +29,7 @@ const pinned = poets.filter((p) => p.pin_order).sort((a, b) => a.pin_order! - b.

مقبول شعرا

{pinned.map((p) => ( - {p.nickname}{years(p.birth_year_ah, p.death_year_ah)} + {p.nickname}{years(p)} ))}
@@ -42,7 +42,7 @@ const pinned = poets.filter((p) => p.pin_order).sort((a, b) => a.pin_order! - b. {list.map((p) => ( {p.nickname} - {years(p.birth_year_ah, p.death_year_ah)} + {years(p)} ))}