fix: og image generation

This commit is contained in:
gosangam
2026-05-06 01:35:06 +05:30
parent b81b18632d
commit de374eab8b
27 changed files with 703 additions and 4 deletions
+38
View File
@@ -6,6 +6,7 @@
*/
import { BOOK_NAMES, CC_LILAS } from "@/lib/constants";
import { decodeTextFragment } from "@/lib/text-highlight";
const SITE_URL =
process.env.NEXT_PUBLIC_SITE_URL || "https://prabhupadasays.org";
@@ -297,6 +298,43 @@ export function ogForLettersByLocation(location: string, count: number) {
});
}
// ---------------------------------------------------------------------------
// hl= query param → OG quote extraction
// ---------------------------------------------------------------------------
/**
* Extract a display quote from the `?hl=` search param.
*
* The `hl` param encodes `prefix,suffix,length`. We reconstruct a readable
* snippet from the prefix + suffix: "first few words ... last few words"
*
* Returns null if hl is missing or invalid.
*/
export function extractQuoteFromHl(
searchParams: Record<string, string | string[] | undefined> | URLSearchParams,
): string | null {
const raw =
searchParams instanceof URLSearchParams
? searchParams.get("hl")
: typeof searchParams.hl === "string"
? searchParams.hl
: null;
if (!raw) return null;
const fragment = decodeTextFragment(raw);
if (!fragment) return null;
const { prefix, suffix } = fragment;
if (!prefix) return null;
if (suffix && suffix !== prefix) {
return `${prefix} ... ${suffix}`;
}
return prefix;
}
/** Default OG metadata for the site. */
export function ogDefault() {
return buildOgMeta({