quiz seo image and authguard
This commit is contained in:
@@ -318,6 +318,68 @@ export function ogForLettersByLocation(location: string, count: number) {
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Quizzes
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const QUIZ_DESCRIPTION =
|
||||
"Test your understanding of Śrīla Prabhupāda's books, lectures and conversations.";
|
||||
|
||||
const QUIZ_KIND_LABEL: Record<string, string> = {
|
||||
chapter: "Book chapter",
|
||||
lecture: "Lecture",
|
||||
conversation: "Conversation",
|
||||
};
|
||||
|
||||
/**
|
||||
* Admin text carries light formatting markers (*bold*, _italic_, links…).
|
||||
* A preview card wants the words only.
|
||||
*/
|
||||
function stripRichMarkers(text: string): string {
|
||||
return text
|
||||
.replace(/\[([^\]\n]+)\]\((https?:\/\/[^\s)]+)\)/g, "$1")
|
||||
.replace(/__([^_\n]+?)__/g, "$1")
|
||||
.replace(/\*([^*\n]+?)\*/g, "$1")
|
||||
.replace(/~([^~\n]+?)~/g, "$1")
|
||||
.replace(/(^|\W)_([^_\n]+?)_(?=\W|$)/g, "$1$2")
|
||||
.replace(/\s+/g, " ")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/** OG metadata for a single quiz. */
|
||||
export function ogForQuiz(quiz: {
|
||||
title: string;
|
||||
description?: string;
|
||||
target_kind: string;
|
||||
target_title?: string;
|
||||
question_count: number;
|
||||
}) {
|
||||
const kind = QUIZ_KIND_LABEL[quiz.target_kind];
|
||||
const count = `${quiz.question_count} question${quiz.question_count === 1 ? "" : "s"}`;
|
||||
const detail = [
|
||||
"Quiz",
|
||||
kind && quiz.target_title ? `${kind}: ${quiz.target_title}` : null,
|
||||
count,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
const about = stripRichMarkers(quiz.description ?? "");
|
||||
return buildOgMeta({
|
||||
title: quiz.title,
|
||||
detail,
|
||||
quote: about || QUIZ_DESCRIPTION,
|
||||
});
|
||||
}
|
||||
|
||||
/** OG metadata for the /quizzes index. */
|
||||
export function ogForQuizzes() {
|
||||
return buildOgMeta({
|
||||
title: "Quizzes",
|
||||
detail: "Prabhupāda Says",
|
||||
quote: QUIZ_DESCRIPTION,
|
||||
});
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// hl= query param → OG quote extraction
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user