Skip to content

Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) + full-text search + page-level content filter#38

Draft
Copilot wants to merge 7 commits into
cairofrom
copilot/add-hadiths-output-files
Draft

Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) + full-text search + page-level content filter#38
Copilot wants to merge 7 commits into
cairofrom
copilot/add-hadiths-output-files

Conversation

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

No hadith data existed in the repo. Adds a complete hadith section sourced from fawazahmed0/hadith-api covering all major Sunni collections with English + Arabic, and hand-curated Hindi for An-Nawawi's 40. Includes a full-text search page with collection dropdown and field filters, and per-page content filter panels styled like the Qur'an surah pages.

Collections (36,512 hadith total)

Collection Count Languages Output
Forty Hadith of an-Nawawi 42 EN + AR + HI single page
Forty Hadith Qudsi 40 EN + AR single page
Forty Hadith — Dehlawi 40 EN + AR single page
Sahih al-Bukhari 7,589 EN + AR 98 book pages
Sahih Muslim 7,563 EN + AR 16 book pages
Sunan Abu Dawud 5,274 EN + AR 43 book pages
Jami At-Tirmidhi 3,998 EN + AR 50 book pages
Sunan Ibn Majah 4,343 EN + AR 38 book pages
Sunan an-Nasai 5,765 EN + AR 52 book pages
Muwatta Malik 1,858 EN + AR 62 book pages

New files

  • src/gen_hadith_html.py — single generator; downloads from jsDelivr CDN, caches to data/hadith/*.json.zip, then regenerates all HTML + txt + search data. Re-runnable.
  • data/hadith/ — 10 compressed .json.zip source files
  • docs/hadith/ — 370+ HTML pages: collection index, small-collection single pages, large-collection per-book pages with prev/next navigation; plus search.html
  • docs/hadith/sd/ — 31 search data JSON files (meta + EN + AR per collection; Hindi for Nawawi), lazy-loaded by the search page
  • output/hadith/ — 21 plain-text files (EN + AR per collection; HI for Nawawi)
  • docs/index.html — Hadith section link injected before </main>

Search page (docs/hadith/search.html)

  • Collection dropdown — search all collections or narrow to one
  • Field filter pills — English (on by default), Arabic, Hindi (visible only when Nawawi is in scope)
  • Lazy loading — only fetches the JSON files needed for the selected collection and fields
  • Keyword highlighting — matched terms highlighted with <mark class="hl">
  • Pagination — 15 results per page with prev/next and page numbers
  • Direct links — each result links to the exact hadith via #h{n} anchor on the relevant page
  • Shareable URLs?q=...&coll=... params auto-trigger the search on load
  • Dark mode — full dark theme support
  • A 🔍 Search link is present in every hadith page header; a "Search All Hadith" button appears on the collections index

Page-level content filter (like Qur'an surah pages)

Every hadith reading page now carries a collapsible "✔ Hadith & Content Filter" panel (<details class="verse-chooser">):

  • Hadith Range — From/To number inputs with Show All / Hide All buttons; filters rows in-page via JS
  • Content pills — Arabic, English, Grade, Reference toggles (+ Hindi and Narrator for Nawawi 40); defaults persist to localStorage
  • Font Size — A−/A/A+ steps, persisted per browser via localStorage
  • Book nav dropdown — "☁ Jump to Book…" <select> in the header of every large-collection book page (Bukhari, Muslim, etc.), with the current book pre-selected
  • Permalink anchors — each hadith separator row contains a direct <a href="#h{n}"> link
  • Scroll-to-top — floating button appears after 300 px of scroll
  • Anchor highlight#h{N} deep links trigger a gold pulse animation on the target row
  • Block-table mobile layout — label row stacks above content on narrow screens (matching Qur'an surah page style)
  • Full dark mode — body, header, table rows, and filter panel
  • Print styles — navigation and filter UI hidden; table layout restored

Design notes

  • Large collections (Bukhari etc.) split by book to keep page size manageable
  • All hadith rows carry id="h{n}" and data-hadith="{n}" attributes enabling direct deep-linking and JS-driven row filtering
  • Hindi available only for Nawawi 40 — no machine translation; all 42 entries hand-curated
  • All hadith text HTML-escaped at render time; int() coercion on book IDs prevents path injection
  • "Book 0, Hadith 0" placeholder references from upstream data are suppressed
  • Breadcrumbs truncate at word boundaries via truncate_words()

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits March 13, 2026 11:13
Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>
Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>
Copilot AI changed the title [WIP] Add hadiths in English and Hindi languages Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) Mar 13, 2026
Copilot AI requested a review from druvx13 March 13, 2026 11:21
@druvx13

druvx13 commented Mar 13, 2026

Copy link
Copy Markdown
Owner

Nice work @copilot ; Now Add these The search page, dropdown selection, and filter(s) [like those of used in The Qur'an website in /docs].

…n, direct links

Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

Nice work @copilot ; Now Add these The search page, dropdown selection, and filter(s) [like those of used in The Qur'an website in /docs].

Done in commit 4d808b5. Added docs/hadith/search.html with:

Collection dropdown — "All Collections" or any individual collection
Field filter pills — English (on by default), Arabic, Hindi (visible only when Nawawi is in scope)
Pagination — 15 results/page with prev/next and page numbers
Keyword highlighting — matched terms highlighted in yellow
Direct links — each result links to the exact hadith via #h{n} anchor
Shareable URLs?q=...&coll=... params auto-trigger search on load
Dark mode — full dark theme support

Search data lives in docs/hadith/sd/ (31 JSON files: meta + EN + AR per collection + Hindi for Nawawi). Files are lazy-loaded — only the selected collection(s) and field(s) are fetched when the user first searches. A 🔍 Search link has been added to every hadith page header, and a "Search All Hadith" button appears on the collections index page.

Here is a preview of the search page UI:

search page

The page source shows all 10 collections in the dropdown, English/Arabic/Hindi field pills, and the full search + results + pagination infrastructure matching the Qur'an search design.

Copilot AI changed the title Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) + full-text search Mar 13, 2026
@druvx13

druvx13 commented Mar 13, 2026

Copy link
Copy Markdown
Owner

@copilot ; restyle it like how the Qur'an's surahs are structured in their specific pages, and also implement page level filter (like it is in surah pages) and so on.

…rk mode, mobile layout

Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ; restyle it like how the Qur'an's surahs are structured in their specific pages, and also implement page level filter (like it is in surah pages) and so on.

Done in commit b2499f6. Here's what was added to match the Qur'an surah page style:

"✔ Hadith & Content Filter" panel (collapsible <details>) above every table:

  • Hadith Range — From/To number inputs with Show All / Hide All buttons
  • Content pills — Arabic, English, Grade, Reference (+ Hindi and Narrator for Nawawi 40); defaults to Arabic+English on; preferences saved to localStorage
  • Font Size — A−/A/A+ steps persisted per browser

Book nav dropdown — "☁ Jump to Book…" <select> in the header of every large-collection book page (Bukhari, Muslim, etc.), with the current book pre-selected

Also:

  • Permalink <a> anchor in each hadith separator row
  • Floating scroll-to-top button (appears after 300 px scroll)
  • #h{N} deep links highlight the target row with a gold pulse animation
  • Block-table layout on mobile (like Qur'an surah pages — label row stacks above content)
  • Full dark mode for body, header, table rows, and filter panel
  • Print styles (hide navigation/filter, restore table layout)

All 370 HTML pages regenerated.

Copilot AI changed the title Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) + full-text search Add hadith section: 10 collections, 36,512 hadith (EN + AR + HI) + full-text search + page-level content filter Mar 13, 2026
@druvx13

druvx13 commented Mar 13, 2026

Copy link
Copy Markdown
Owner

Nice work @copilot but THERE ARE MANY VERSES NOT PRESENT IN THE WHOLE OF MANY HADITHS , THEY ARE EMPTY OF HADITHS!!!

…rect counts

Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

Nice work @copilot but THERE ARE MANY VERSES NOT PRESENT IN THE WHOLE OF MANY HADITHS , THEY ARE EMPTY OF HADITHS!!!

Fixed in commit 5b651c4. The upstream API contains stub/placeholder entries with no English or Arabic text (203 in Muslim, 86 in Nasai, 72 in Tirmidhi, 40 in Malik, 9 in Bukhari, 3 in Ibn Majah, 2 in Abu Dawud). These were being rendered as separator rows with empty content.

Changes made:

  • Added has_hadith_content() helper to identify hadiths with at least some text
  • render_hadith_rows() now returns "" for empty hadiths and also skips the English/Arabic row individually if that field is empty
  • gen_large_collection_pages() filters to only sections with valid content and only renders valid hadiths within each section — prev/next navigation and the "Jump to Book" dropdown only list sections with actual content
  • Collection counts on the index page and search page now reflect only valid hadiths
  • Deleted malik-book-000.html (the one section that was 100% empty)

Valid hadiths shown: 36,108 (from 36,512 raw entries — 404 empty stubs removed).

@druvx13

druvx13 commented Mar 13, 2026

Copy link
Copy Markdown
Owner

@copilot ; well you did a job, but why there are hadiths missing like why some starts from 3 , why some has only some numbers of hadiths and are remaining, and also some has reference remaining and so on and on why is that!!! Fix all of em! But before doing it do a comprehensive analysis in-depth about every single hadiths present and which are missing, where technical error is occurring and so on!!

…page cleanup

- Add _resolve_sec() to gen_large_collection_pages() that uses math.floor(n)
  for fractional hadith numbers and nearest-preceding section for gap hadiths.
  72 hadiths (Bukhari 26, Tirmidhi 37, IbnMajah 2, Nasai 7) now appear in
  their correct book pages instead of a spurious "General" (book-000) page.
- Fix reference row condition: was 'book!=0 AND hadith!=0'; now 'hadith!=0'.
  IbnMajah's 266 Introduction hadiths (book=0, hadith=N) now show references.
  Format: 'Hadith N' when book=0, 'Book X, Hadith Y' otherwise.
- Add cleanup loop to remove stale per-book HTML files no longer generated.
- Regenerate all 370+ docs/hadith/ pages.

Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>

Copilot AI commented Mar 13, 2026

Copy link
Copy Markdown
Contributor Author

@copilot ; well you did a job, but why there are hadiths missing like why some starts from 3 , why some has only some numbers of hadiths and are remaining, and also some has referenc...

Done in commit 12db642. Here's the full analysis and what was fixed:

Root causes identified:

Issue Root Cause Affected
Fractional hadith numbers (815.2, 3604.02…) all land in "General" section_map used integer range keys, so float lookups always missed Tirmidhi 37, Bukhari 26, IbnMajah 2, Nasai 7 = 72 hadiths
Section-gap hadiths land in "General" Integer hadiths between section ranges (e.g. Bukhari 521 between sec 8 ending at 520 and sec 9 starting at 522) also missed Bukhari 6 integer hadiths
IbnMajah 266 references missing Condition was book!=0 AND hadith!=0; IbnMajah Introduction uses book=0, hadith=N IbnMajah 266 hadiths
"Starts from 3" (Muslim), other gaps Genuine upstream data gap — hadiths 1, 2 are not translated in fawazahmed0/hadith-api Not fixable (source data)

Fixes applied:

  • Added _resolve_sec() helper that falls back to floor(n) for fractional hadith numbers, and finds the nearest preceding section for gap hadiths — so all 72 orphaned hadiths now appear in their correct book pages
  • Changed reference condition to hadith!=0 (dropping the book!=0 requirement); book=0 refs now display as "Hadith N" instead of "Book 0, Hadith N"
  • Added cleanup: stale book-000 pages for Tirmidhi, Bukhari, Nasai are deleted automatically on re-generation

Page count changes:

  • Tirmidhi: 50 → 49 books (book-000 removed, 37 fractional hadiths in correct books)
  • Bukhari: 98 → 97 books (book-000 removed)
  • Nasai: 52 → 51 books (book-000 removed)
  • IbnMajah book-000 (Introduction): now shows all 266 references correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants