Pinned poets on the home page (مقبول شعرا): Iqbal, Ghalib, Mir Taqi Mir, Mir Dard, Dagh

- 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 <noreply@anthropic.com>
This commit is contained in:
Anas Rashid 2026-10-08 20:42:33 +02:00
parent 6b414c3d2d
commit d70e0a1fed
5 changed files with 28 additions and 3 deletions

View File

@ -80,5 +80,6 @@ for (const entry of manifest.Poets) {
} }
process.stdout.write(`\r${poems} poems`); 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`); console.log(`\nimported ${manifest.Poets.length} poets, ${poems} poems`);
await pool.end(); await pool.end();

View File

@ -17,7 +17,7 @@ app.get('/health', async () => {
app.get('/api/poets', async () => { app.get('/api/poets', async () => {
const { rows } = await pool.query( 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; return rows;
}); });

10
db/featured.sql Normal file
View File

@ -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;

View File

@ -11,8 +11,10 @@ CREATE TABLE IF NOT EXISTS poets (
nickname text NOT NULL, nickname text NOT NULL,
description text, -- short intro (Urdu Wikipedia lead) description text, -- short intro (Urdu Wikipedia lead)
birth_year_ah integer, -- Hijri, approximate 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 ( CREATE TABLE IF NOT EXISTS categories (
id integer PRIMARY KEY, id integer PRIMARY KEY,

View File

@ -3,7 +3,7 @@ import Base from '../layouts/Base.astro';
import { api } from '../lib/api'; import { api } from '../lib/api';
import { centuryOf, centuryName, years, ud } from '../lib/urdu'; 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<Poet[]>('/api/poets')) ?? []; const poets = (await api<Poet[]>('/api/poets')) ?? [];
// group by Hijri century of birth (poets without a known year last) // 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); groups.get(c)!.push(p);
} }
const ordered = [...groups.entries()].sort(([a], [b]) => (a ?? 99) - (b ?? 99)); 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!);
--- ---
<Base> <Base>
<section class="hero"> <section class="hero">
@ -23,6 +24,17 @@ const ordered = [...groups.entries()].sort(([a], [b]) => (a ?? 99) - (b ?? 99));
{poets.length === 0 && <p class="muted">مواد تیار کیا جا رہا ہے۔ براہِ کرم کچھ دیر بعد دوبارہ تشریف لائیں۔</p>} {poets.length === 0 && <p class="muted">مواد تیار کیا جا رہا ہے۔ براہِ کرم کچھ دیر بعد دوبارہ تشریف لائیں۔</p>}
{pinned.length > 0 && (
<section class="century">
<h2>مقبول شعرا</h2>
<div class="poets">
{pinned.map((p) => (
<a class="poet-card" href={p.url}>{p.nickname}<small>{years(p.birth_year_ah, p.death_year_ah)}</small></a>
))}
</div>
</section>
)}
{ordered.map(([century, list]) => ( {ordered.map(([century, list]) => (
<section class="century"> <section class="century">
<h2>{centuryName(century)}</h2> <h2>{centuryName(century)}</h2>