--- // Poet (/p238), category (/p238/shaeri/c641) and poem (/p238/shaeri/c641/sh6556) pages import Base from '../layouts/Base.astro'; import Seg from '../components/Seg.astro'; import { api } from '../lib/api'; import { ud, years, highlighter, parts } from '../lib/urdu'; const url = '/' + (Astro.params.path ?? ''); const page = await api(`/api/page?url=${encodeURIComponent(url)}`); if (!page) return new Response(null, { status: 404, statusText: 'Not found' }); // group verses into couplets / single lines / paragraphs for rendering type Verse = { position: string; couplet: number; text: string }; const blocks: { kind: 'couplet' | 'single' | 'para'; lines: string[]; mark?: string }[] = []; if (page.type === 'poem') { const { matla, maqta } = page.poem; for (const v of page.verses as Verse[]) { if (v.position === 'Right') blocks.push({ kind: 'couplet', lines: [v.text], mark: v.couplet === matla ? 'مطلع' : v.couplet === maqta ? 'مقطع' : undefined }); else if (v.position === 'Left' && blocks.at(-1)?.kind === 'couplet' && blocks.at(-1)!.lines.length === 1) blocks.at(-1)!.lines.push(v.text); else if (v.position === 'Paragraph') blocks.push({ kind: 'para', lines: [v.text] }); else blocks.push({ kind: 'single', lines: [v.text] }); } } // pen name (marked ؔ in the text) set apart; split() with a capture group puts matches at odd indexes // ?hl= (from search results) marks the searched words on the page; segments: [text, 'mark' | 'pen' | ''] const hlq = Astro.url.searchParams.get('hl') ?? ''; const re = highlighter(hlq); const show = (line: string) => parts(line, re).flatMap((s, i): [string, string][] => i % 2 ? [[s, 'mark']] : s.split(/(\S*\u0614\S*)/).map((t, j) => [t, j % 2 ? 'pen' : ''])); // contents of a divan grouped by radif letter ("ردیف الف … ی"); ے is filed under ی as in printed divans const LETTER = (l: string) => (l === 'ا' ? 'الف' : l === 'ے' ? 'ی' : l); const groups: { letter: string | null; poems: any[] }[] = []; for (const p of page.poems ?? []) { const l = p.radif_letter ? LETTER(p.radif_letter) : null; if (groups.at(-1)?.letter !== l || !groups.length) groups.push({ letter: l, poems: [] }); groups.at(-1)!.poems.push(p); } const crumbs = page.breadcrumbs ?? []; const title = page.type === 'poem' ? page.poem.title : page.type === 'poet' ? page.poet.nickname : page.category.title; --- {page.type !== 'poet' && ( )} {page.type === 'poet' && ( <>

{page.poet.name}

{years(page.poet)}

{page.poet.description &&
{page.poet.description}
} )} {page.type === 'category' &&

{page.category.title}

} {page.type !== 'poem' && page.children.length > 0 && (
{page.children.map((c: any) => ( {c.title}{c.poems > 0 && {ud(c.poems)}} ))}
)} {page.type !== 'poem' && groups.map((g) => ( <> {g.letter &&

ردیف {g.letter}

}
    {g.poems.map((p: any) =>
  1. {p.title}
  2. )}
))} {page.type === 'poem' && ( <>

{re && (

«{hlq}» نمایاں · تلاش کے نتائج · نشان ہٹائیں

)} {page.poem.radif != null &&

{page.poem.radif ? `ردیف: ${page.poem.radif}` : 'غیر مردف'}

}
{blocks.map((b) => b.kind === 'couplet' ?
{b.lines.map((l) =>

)}
: b.kind === 'para' ?

:

)}

کسی لفظ کو منتخب کریں تو اس کے معنی اور تلفظ ساتھ نظر آئیں گے۔

{page.poem.source_url && (

ماخذ: ویکی ماخذ · {page.poet && {page.poet.nickname}}

)} )} {re && }