fix: og image generation
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user