export const dynamic = "force-dynamic"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; import { getBookMeta } from "@/lib/api"; import { ogForBook } from "@/lib/og"; import { PageHeader } from "@/components/layout/page-header"; import { JsonLd } from "@/components/seo/json-ld"; import { bookJsonLd } from "@/lib/jsonld"; import { Card, CardContent } from "@/components/ui/card"; import { ExtractedVerseCount } from "../extracted-verse-count"; import fs from "fs"; import path from "path"; export function generateMetadata(): Metadata { return ogForBook("nbs"); } type NbsMeta = { book: string; title: string; author: string; year?: number; description?: string; totalChapters: number; chapters: { number: number; title: string; totalVerses: number }[]; }; type NbsIntroSegment = { slug: string; title: string; type: string; book: string; order: number; paragraphs: string[]; }; const NBS_JSON_DIR = path.join(process.cwd(), "lib", "jsons", "books", "nbs"); async function getMetaWithFallback(): Promise { const meta = await getBookMeta("nbs"); if (meta) return meta as unknown as NbsMeta; const introPath = path.join(NBS_JSON_DIR, "intro.json"); if (!fs.existsSync(introPath)) return null; try { return JSON.parse(fs.readFileSync(introPath, "utf-8")) as NbsMeta; } catch { return null; } } function getLocalIntroSegments(): NbsIntroSegment[] { const introDir = path.join(NBS_JSON_DIR, "intro"); if (!fs.existsSync(introDir)) return []; const results: NbsIntroSegment[] = []; const files = ["introduction.json"]; for (const file of files) { const filePath = path.join(introDir, file); if (fs.existsSync(filePath)) { try { results.push( JSON.parse(fs.readFileSync(filePath, "utf-8")) as NbsIntroSegment, ); } catch { // skip } } } return results.sort((a, b) => a.order - b.order); } export default async function NbsPage() { const meta = await getMetaWithFallback(); if (!meta) notFound(); const introSegments = getLocalIntroSegments(); const introduction = introSegments.find((s) => s.slug === "introduction"); return (
← Books

{meta.title}

{meta.author}

{meta.description && (

{meta.description}

)}
{/* Front Matter */} {introduction && (

Front Matter

  • {introduction.title}

)} {/* Chapters */}

Chapters

    {meta.chapters.map((ch) => (
  • Chapter {ch.number}

    {ch.title}

  • ))}
); }