Skip to content

Commit

Permalink
Merge pull request #42 from seemorg/dev
Browse files Browse the repository at this point in the history
Production deployment
  • Loading branch information
ahmedriad1 authored Dec 5, 2024
2 parents fd0cd78 + 850f46d commit b5b5370
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 69 deletions.
8 changes: 4 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ model Book {
/// [BookVersion]
versions Json[]
/// [BookFlags]
flags Json @default("{}")
numberOfVersions Int @default(0)
/// [BookExtraProperties]
extraProperties Json @default("{}")
/// [BookPhysicalDetails]
physicalDetails Json?
genres Genre[]
advancedGenres AdvancedGenre[]
author Author @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: Cascade)
authorId String
physicalDetails String?
coverImageUrl String?
coverImageUrl String?
createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/t/[bookId]/_components/ai-tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export default function AITab({ bookSlug, bookResponse }: TabProps) {
const isLoading = isPending;

const isVersionMismatch =
bookResponse.book.flags.aiVersion !== bookResponse.content.versionId;
bookResponse.book.aiVersion !== bookResponse.content.versionId;

return (
<div className="pb-2">
{isVersionMismatch && (
<SidebarContainer className="my-4">
<VersionAlert
versionId={bookResponse.book.flags.aiVersion!}
versionId={bookResponse.book.aiVersion!}
versions={bookResponse.book.versions}
feature="ask-ai"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/app/[locale]/t/[bookId]/_components/search-tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function SearchTab({ bookSlug, bookResponse }: TabProps) {
const { value, setValue, results, setResults } = useSearchStore();

const isVersionMismatch =
bookResponse.book.flags.aiVersion !== bookResponse.content.versionId;
bookResponse.book.aiVersion !== bookResponse.content.versionId;

const { mutateAsync, isPending, error } = useMutation<
SemanticSearchBookNode[],
Expand Down Expand Up @@ -120,7 +120,7 @@ export default function SearchTab({ bookSlug, bookResponse }: TabProps) {
{isVersionMismatch && (
<SidebarContainer className="my-4">
<VersionAlert
versionId={bookResponse.book.flags.aiVersion!}
versionId={bookResponse.book.aiVersion!}
versions={bookResponse.book.versions}
feature="search"
/>
Expand Down
2 changes: 1 addition & 1 deletion src/app/[locale]/t/[bookId]/_components/tab-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const TabContent = ({
}: TabProps & {
tabId: keyof typeof tabIdToComponent;
}) => {
const isSupported = props.bookResponse.book.flags.aiSupported;
const isSupported = props.bookResponse.book.aiSupported;

if (
(props.bookResponse.content.source === "external" || !isSupported) &&
Expand Down
93 changes: 50 additions & 43 deletions src/data/popular-books.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,54 @@ import { db } from "@/server/db";
import { getLocaleWhereClause } from "@/server/db/localization";

export const popularBooks = [
{ slug: "sahih" },
{ slug: "sahih-1" },
{ slug: "sunan-4" },
{ slug: "sunan-3" },
{ slug: "sahih-wa-dacif-sunan-tirmidhi" },
{ slug: "sunan-sughra" },
{ slug: "muwatta" },
{ slug: "riyad-salihin" },
{ slug: "ihya-culum-din" },
{ slug: "tafsir-jalalayn" },
{ slug: "tafsir-quran-6" },
{ slug: "fath-bari" },
{ id: "0256Bukhari.Sahih" },
{ id: "0261Muslim.Sahih" },
{ id: "0275AbuDawudSijistani.Sunan" },
{ id: "0273IbnMaja.Sunan" },
{ id: "0303Nasai.SunanSughra" },
{ id: "1420MuhammadNasirDinAlbani.SahihWaDacifSunanTirmidhi" },
{ id: "0179MalikIbnAnas.Muwatta" },
{ id: "0676Nawawi.RiyadSalihin" },
{ id: "0505Ghazali.IhyaCulumDin" },
{ id: "0911Suyuti.TafsirJalalayn" },
{ id: "0774IbnKathir.TafsirQuran" },
{ id: "0852IbnHajarCasqalani.FathBari" },
];

export const popularIslamicLawBooks = [
{ slug: "muwatta" },
{ slug: "mughni" },
{ slug: "hidaya-fi-sharh-bidaya" },
{ slug: "bidayat-mujtahid" },
{ slug: "umm" },
{ slug: "mukhtasar-4" },
{ slug: "risala" },
{ slug: "mukhtasar-sahih-bukhari" },
{ slug: "mabsut-1" },
{ slug: "radd-muhtar" },
{ slug: "muhalla-bi-athar" },
{ id: "0179MalikIbnAnas.Muwatta" },
{ id: "0620IbnQudamaMaqdisi.Mughni" },
{ id: "0593BurhanDinFarghaniMarghinani.HidayaFiSharhBidaya" },
{ id: "0595IbnRushdHafid.BidayatMujtahid" },
{ id: "0204Shafici.Umm" },
{ id: "0428AbuHusaynQuduri.Mukhtasar" },
{ id: "0204Shafici.Risala" },
{ id: "0695IbnAbiJamra.MukhtasarSahihBukhari" },
{ id: "0483IbnAhmadSarakhsi.Mabsut" },
{ id: "1252IbnCabidinDimashqi.RaddMuhtar" },
{ id: "0456IbnHazm.MuhallaBiAthar" },
];

export const popularIslamicHistoryBooks = [
{ slug: "sira-nabawiyya" },
{ slug: "sira" },
{ slug: "zad-macad" },
{ slug: "bidaya-1" },
{ slug: "tarikh-5" },
{ slug: "fadail-sahaba" },
{ slug: "sira-1" },
{ slug: "wafat" },
{ slug: "jawamic-sira" },
{ slug: "qisas-anbiya-1" },
{ id: "0213IbnHisham.SiraNabawiyya" },
{ id: "0151IbnIshaq.Sira" },
{ id: "0751IbnQayyimJawziyya.ZadMacad" },
{ id: "0774IbnKathir.Bidaya" },
{ id: "0310Tabari.Tarikh" },
{ id: "0241IbnHanbal.FadailSahaba" },
{ id: "0354IbnHibbanBusti.Sira" },
{ id: "0303Nasai.Wafat" },
{ id: "0456IbnHazm.JawamicSira" },
{ id: "0774IbnKathir.QisasAnbiya" },
];

const fetchBooksBySlugs = (slugs: string[], locale: PathLocale) => {
const fetchBooksByIds = async (ids: string[], locale: PathLocale) => {
const localeWhere = getLocaleWhereClause(locale);

return db.book.findMany({
const books = await db.book.findMany({
where: {
slug: {
in: slugs,
id: {
in: ids,
},
},
include: {
Expand All @@ -67,25 +67,32 @@ const fetchBooksBySlugs = (slugs: string[], locale: PathLocale) => {
},
},
});

// Order books by their index in the ids array to maintain specified order
return books.sort((a, b) => {
const aIndex = ids.indexOf(a.id);
const bIndex = ids.indexOf(b.id);
return aIndex - bIndex;
});
};

export const fetchPopularBooks = async (locale: PathLocale) => {
return fetchBooksBySlugs(
popularBooks.map((s) => s.slug),
return fetchBooksByIds(
popularBooks.map((s) => s.id),
locale,
);
};

export const fetchPopularIslamicLawBooks = async (locale: PathLocale) => {
return fetchBooksBySlugs(
popularIslamicLawBooks.map((b) => b.slug),
return fetchBooksByIds(
popularIslamicLawBooks.map((b) => b.id),
locale,
);
};

export const fetchPopularIslamicHistoryBooks = async (locale: PathLocale) => {
return fetchBooksBySlugs(
popularIslamicHistoryBooks.map((b) => b.slug),
return fetchBooksByIds(
popularIslamicHistoryBooks.map((b) => b.id),
locale,
);
};
5 changes: 3 additions & 2 deletions src/lib/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ export const getMetadata = async ({
...newDescription,
keywords,
authors,

openGraph: {
type: "website",
siteName,
url: "/",
locale,
locale: locale ?? "en_US",
...newTitle,
...newDescription,
...newImages,
Expand Down Expand Up @@ -117,7 +118,7 @@ export const getMetadata = async ({
siteName,
url: "/",
title,
locale,
locale: locale ?? "en_US",
description: description ?? defaultDescription,
images,
},
Expand Down
3 changes: 2 additions & 1 deletion src/types/ApiBookResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ type BookDetails = {
bio: string;
};
transliteration: string;
aiSupported: boolean;
aiVersion: string;
versions: PrismaJson.BookVersion[];
numberOfVersions: number;
flags: PrismaJson.BookFlags;
primaryName: string;
otherNames: string[];
secondaryName?: string | null;
Expand Down
49 changes: 35 additions & 14 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
interface PublicationDetails {
investigator?: string;
publisher?: string;
publisherLocation?: string;
editionNumber?: string;
publicationYear?: number; // hijri
}

type SplitsData = { start: number; end: number }[];

declare global {
namespace PrismaJson {
interface BookVersion {
source: "openiti" | "turath" | "external" | "pdf";
type BookVersion = (
| {
source: "openiti" | "turath" | "external";
}
| {
source: "pdf";
ocrBookId?: string;
splitsData?: SplitsData;
}
) & {
id: string;
value: string;
publicationDetails?: {
investigator?: string;
publisher?: string;
editionNumber?: string;
publicationYear?: number; // hijri
};
}

interface BookFlags {
publicationDetails?: PublicationDetails;
aiSupported?: boolean;
aiVersion?: string;
}
keywordSupported?: boolean;
};

interface AuthorExtraProperties {
_airtableReference?: string;
}

interface BookExtraProperties {
splitsData?: { start: number; end: number }[];
_airtableReference?: string;
}

type BookPhysicalDetails = (
| {
type: "manuscript";
}
| ({
type: "published";
} & PublicationDetails)
) & {
notes?: string;
};

interface GenreExtraProperties {
_airtableReference?: string;
}
Expand Down

0 comments on commit b5b5370

Please sign in to comment.