fix: og image for glossary

This commit is contained in:
gosangam
2026-05-06 15:52:44 +05:30
parent e5fb370997
commit cbd9c55777
3 changed files with 90 additions and 8 deletions
+13
View File
@@ -1,6 +1,7 @@
"use client";
import { useState, useMemo, useRef, useEffect, useCallback } from "react";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { Search, X, Menu, ChevronLeft, ChevronRight } from "lucide-react";
import { Input } from "@/components/ui/input";
@@ -289,6 +290,7 @@ export function GlossaryClient({
letters,
letterCounts,
}: Props) {
const router = useRouter();
const [query, setQuery] = useState("");
const [activeTermRaw, setActiveTerm] = useState(entries[0]?.term || "");
const contentRef = useRef<HTMLDivElement>(null);
@@ -347,6 +349,17 @@ export function GlossaryClient({
return idx !== undefined ? entries[idx] : null;
}, [entries, termIndex, activeTerm]);
// Update URL with ?term= when active term changes (for OG + shareable links)
useEffect(() => {
const url = new URL(window.location.href);
if (activeTerm) {
url.searchParams.set("term", activeTerm);
} else {
url.searchParams.delete("term");
}
window.history.replaceState({}, "", url.toString());
}, [activeTerm]);
const handleSelectTerm = useCallback((term: string) => {
setActiveTerm(term);
contentRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });