Update routing in next.config.ts to redirect "/tercih-robotu" to the hero form, add simple-icons dependency in package.json, and enhance database indexing for improved query performance. Remove unused SVG files and update metadata across various pages for better SEO and clarity.
All checks were successful
Deploy / deploy (push) Successful in 14m14s
All checks were successful
Deploy / deploy (push) Successful in 14m14s
This commit is contained in:
86
src/app/api/katalog-ara/route.ts
Normal file
86
src/app/api/katalog-ara/route.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
import { getAllBolumler, getAllUniversiteler } from "@/lib/katalog";
|
||||
import { trBaslikDuzeni } from "@/lib/slug";
|
||||
|
||||
const SONUC_SINIRI = 6;
|
||||
|
||||
function normalize(metin: string): string {
|
||||
return metin
|
||||
.toLocaleLowerCase("tr-TR")
|
||||
.replace(/ı/g, "i")
|
||||
.replace(/ş/g, "s")
|
||||
.replace(/ğ/g, "g")
|
||||
.replace(/ü/g, "u")
|
||||
.replace(/ö/g, "o")
|
||||
.replace(/ç/g, "c")
|
||||
.replace(/â/g, "a")
|
||||
.replace(/î/g, "i")
|
||||
.replace(/û/g, "u")
|
||||
.normalize("NFKD")
|
||||
.replace(/[̀-ͯ]/g, "");
|
||||
}
|
||||
|
||||
function eslesmePuani(ad: string, sorgu: string): number {
|
||||
const normalAd = normalize(ad);
|
||||
if (normalAd === sorgu) return 0;
|
||||
if (normalAd.startsWith(sorgu)) return 1;
|
||||
if (normalAd.split(/\s+/).some((kelime) => kelime.startsWith(sorgu))) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
export function GET(request: NextRequest) {
|
||||
const hamSorgu = request.nextUrl.searchParams.get("q")?.trim() ?? "";
|
||||
const sorgu = normalize(hamSorgu).slice(0, 80);
|
||||
|
||||
if (sorgu.length < 2) {
|
||||
return NextResponse.json({ bolumler: [], universiteler: [] });
|
||||
}
|
||||
|
||||
const bolumler = getAllBolumler()
|
||||
.filter((bolum) => normalize(bolum.ad).includes(sorgu))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
eslesmePuani(a.ad, sorgu) - eslesmePuani(b.ad, sorgu) ||
|
||||
b.programSayisi - a.programSayisi,
|
||||
)
|
||||
.slice(0, SONUC_SINIRI)
|
||||
.map((bolum) => ({
|
||||
href: `/bolum/${bolum.slug}`,
|
||||
ad: bolum.ad,
|
||||
programSayisi: bolum.programSayisi,
|
||||
enIyiSira: bolum.enIyiSira,
|
||||
seviye:
|
||||
bolum.lisans && bolum.onlisans
|
||||
? "Lisans ve önlisans"
|
||||
: bolum.lisans
|
||||
? "Lisans"
|
||||
: "Önlisans",
|
||||
}));
|
||||
|
||||
const universiteler = getAllUniversiteler()
|
||||
.filter((universite) => normalize(universite.ad).includes(sorgu))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
eslesmePuani(a.ad, sorgu) - eslesmePuani(b.ad, sorgu) ||
|
||||
b.programSayisi - a.programSayisi,
|
||||
)
|
||||
.slice(0, SONUC_SINIRI)
|
||||
.map((universite) => ({
|
||||
href: `/universite/${universite.slug}`,
|
||||
ad: universite.ad,
|
||||
il: universite.il ? trBaslikDuzeni(universite.il) : null,
|
||||
tur:
|
||||
universite.unitur === "DEVLET"
|
||||
? "Devlet"
|
||||
: universite.unitur &&
|
||||
["VAKIF", "VAKIF MYO"].includes(universite.unitur)
|
||||
? "Vakıf"
|
||||
: universite.unitur
|
||||
? "KKTC / Yurt dışı"
|
||||
: null,
|
||||
programSayisi: universite.programSayisi,
|
||||
fakulteSayisi: universite.fakulteSayisi,
|
||||
}));
|
||||
|
||||
return NextResponse.json({ bolumler, universiteler });
|
||||
}
|
||||
Reference in New Issue
Block a user