From d70e0a1fedd783c06f40c8ad9945f81632e36c8a Mon Sep 17 00:00:00 2001 From: Anas Rashid Date: Thu, 8 Oct 2026 20:42:33 +0200 Subject: [PATCH] =?UTF-8?q?Pinned=20poets=20on=20the=20home=20page=20(?= =?UTF-8?q?=D9=85=D9=82=D8=A8=D9=88=D9=84=20=D8=B4=D8=B9=D8=B1=D8=A7):=20I?= =?UTF-8?q?qbal,=20Ghalib,=20Mir=20Taqi=20Mir,=20Mir=20Dard,=20Dagh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - poets.pin_order; editorial list in db/featured.sql, applied after every import - home page shows the pinned row first, like Ganjoor - Faiz is not included: his work is under copyright until 2035, so not in divan-data Co-Authored-By: Claude Opus 5.5 --- api/src/import.ts | 1 + api/src/server.ts | 2 +- db/featured.sql | 10 ++++++++++ db/schema.sql | 4 +++- web/src/pages/index.astro | 14 +++++++++++++- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 db/featured.sql diff --git a/api/src/import.ts b/api/src/import.ts index c11e27a1..ce4f6368 100644 --- a/api/src/import.ts +++ b/api/src/import.ts @@ -80,5 +80,6 @@ for (const entry of manifest.Poets) { } process.stdout.write(`\r${poems} poems`); } +await pool.query(await readFile(new URL('../../db/featured.sql', import.meta.url), 'utf8')); console.log(`\nimported ${manifest.Poets.length} poets, ${poems} poems`); await pool.end(); diff --git a/api/src/server.ts b/api/src/server.ts index 44546f50..85132b1f 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 FROM poets ORDER BY birth_year_ah NULLS LAST, nickname', + 'SELECT id, url, name, nickname, birth_year_ah, death_year_ah, pin_order FROM poets ORDER BY birth_year_ah NULLS LAST, nickname', ); return rows; }); diff --git a/db/featured.sql b/db/featured.sql new file mode 100644 index 00000000..9a9e9d34 --- /dev/null +++ b/db/featured.sql @@ -0,0 +1,10 @@ +-- Poets pinned to the top of the home page ("مقبول شعرا"), in this order. +-- Applied by api/src/import.ts after every import. Ids/URLs are stable divan-data ids. +UPDATE poets SET pin_order = NULL; +UPDATE poets SET pin_order = v.ord FROM (VALUES + ('/p238', 1), -- محمد اقبال + ('/p266', 2), -- مرزا غالب + ('/p303', 3), -- میر تقی میر + ('/p99', 4), -- خواجہ میر درد + ('/p102', 5) -- داغ دہلوی +) AS v(url, ord) WHERE poets.url = v.url; diff --git a/db/schema.sql b/db/schema.sql index 1fc997d0..ffb729e0 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -11,8 +11,10 @@ CREATE TABLE IF NOT EXISTS poets ( nickname text NOT NULL, description text, -- short intro (Urdu Wikipedia lead) birth_year_ah integer, -- Hijri, approximate - death_year_ah integer + death_year_ah integer, + pin_order integer -- featured on the home page (db/featured.sql) ); +ALTER TABLE poets ADD COLUMN IF NOT EXISTS pin_order integer; CREATE TABLE IF NOT EXISTS categories ( id integer PRIMARY KEY, diff --git a/web/src/pages/index.astro b/web/src/pages/index.astro index f2e17f3b..bc1843e1 100644 --- a/web/src/pages/index.astro +++ b/web/src/pages/index.astro @@ -3,7 +3,7 @@ import Base from '../layouts/Base.astro'; import { api } from '../lib/api'; import { centuryOf, centuryName, years, ud } from '../lib/urdu'; -type Poet = { id: number; url: string; nickname: string; birth_year_ah: number | null; death_year_ah: number | null }; +type Poet = { id: number; url: string; nickname: string; birth_year_ah: number | null; death_year_ah: number | null; pin_order: number | null }; const poets = (await api('/api/poets')) ?? []; // group by Hijri century of birth (poets without a known year last) @@ -14,6 +14,7 @@ for (const p of poets) { groups.get(c)!.push(p); } const ordered = [...groups.entries()].sort(([a], [b]) => (a ?? 99) - (b ?? 99)); +const pinned = poets.filter((p) => p.pin_order).sort((a, b) => a.pin_order! - b.pin_order!); ---
@@ -23,6 +24,17 @@ const ordered = [...groups.entries()].sort(([a], [b]) => (a ?? 99) - (b ?? 99)); {poets.length === 0 &&

مواد تیار کیا جا رہا ہے۔ براہِ کرم کچھ دیر بعد دوبارہ تشریف لائیں۔

} + {pinned.length > 0 && ( +
+

مقبول شعرا

+ +
+ )} + {ordered.map(([century, list]) => (

{centuryName(century)}