From 7b158eb19224b399ec5859d523ba96309166e15c Mon Sep 17 00:00:00 2001 From: Alzer Del Zeyger <75466035+Dx-Alz-xD@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:01:48 +0530 Subject: [PATCH] fix(subject): stop showing BMAT102L for subjects without a course code extractBracketContent fell back to BMAT102L when a subject had no code in brackets, so cards showed it and downloads were named after it. it now returns null, the card leaves the code out, and file names use the subject name instead --- src/app/paper/[id]/page.tsx | 4 ++-- src/lib/utils/download.ts | 4 ++-- src/lib/utils/string.ts | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/paper/[id]/page.tsx b/src/app/paper/[id]/page.tsx index 7e8fba2b..a0002080 100644 --- a/src/app/paper/[id]/page.tsx +++ b/src/app/paper/[id]/page.tsx @@ -2,7 +2,7 @@ import { fetchPaperID } from "@/app/actions/get-papers-by-id"; import RelatedPapers from "@/components/RelatedPaper"; import Loader from "@/components/ui/loader"; import { type ErrorResponse, type PaperResponse } from "@/interface"; -import { extractBracketContent } from "@/lib/utils/string"; +import { courseCodeOrName } from "@/lib/utils/string"; import axios, { type AxiosResponse } from "axios"; import { type Metadata } from "next"; import { redirect } from "next/navigation"; @@ -177,7 +177,7 @@ const PaperPage = async ({ params }: { params: { id: string } }) => { + name={`${courseCodeOrName(paper.subject)}-${paper.exam}-${paper.slot}-${paper.year}`}/> {/* export const generateFileName = (paper: IPaper): string => { const extension = paper.file_url.split(".").pop(); - return `${extractBracketContent(paper.subject)}-${paper.exam}-${paper.slot}-${paper.year}.${extension}`; + return `${courseCodeOrName(paper.subject)}-${paper.exam}-${paper.slot}-${paper.year}.${extension}`; }; export const downloadFile = async ( diff --git a/src/lib/utils/string.ts b/src/lib/utils/string.ts index 63daa3c7..a116b67d 100644 --- a/src/lib/utils/string.ts +++ b/src/lib/utils/string.ts @@ -16,9 +16,13 @@ export function toSentenceCase(input: string): string { export function extractBracketContent(subject: string): string | null { const regex = /\[(.*?)\]/; const match = regex.exec(subject); - return match?.[1] ?? "BMAT102L"; + return match?.[1] ?? null; } export function extractWithoutBracketContent(subject: string): string { return subject.replace(/\s*\[.*?\]\s*/g, "").trim(); +} + +export function courseCodeOrName(subject: string): string { + return extractBracketContent(subject) ?? extractWithoutBracketContent(subject); } \ No newline at end of file