Barazo default frontend
barazo.forum
1/**
2 * Maturity-aware SEO helpers.
3 * Determines meta tags, JSON-LD inclusion, and OG tag inclusion
4 * based on content maturity ratings (safe/mature/adult).
5 * @see decisions/frontend.md Section: Content Maturity + SEO
6 */
7
8import type { Metadata } from 'next'
9import type { MaturityRating } from '@/lib/api/types'
10
11/** Maturity tier ordering for comparison. */
12const MATURITY_ORDER: Record<MaturityRating, number> = {
13 safe: 0,
14 mature: 1,
15 adult: 2,
16}
17
18/**
19 * Returns the higher (more restrictive) of two maturity ratings.
20 * Used to combine community-level and category-level ratings.
21 */
22export function getEffectiveMaturity(
23 communityRating: MaturityRating,
24 categoryRating: MaturityRating
25): MaturityRating {
26 return MATURITY_ORDER[communityRating] >= MATURITY_ORDER[categoryRating]
27 ? communityRating
28 : categoryRating
29}
30
31/**
32 * Returns metadata fields to merge based on the effective maturity rating.
33 * - safe: no special tags
34 * - mature: adds rating meta tag
35 * - adult: sets noindex/nofollow
36 */
37export function getMaturityMeta(rating: MaturityRating): Partial<Metadata> {
38 switch (rating) {
39 case 'safe':
40 return {}
41 case 'mature':
42 return {
43 other: { rating: 'mature' },
44 }
45 case 'adult':
46 return {
47 robots: { index: false, follow: false },
48 }
49 }
50}
51
52/** Whether JSON-LD structured data should be included for this rating. */
53export function shouldIncludeJsonLd(rating: MaturityRating): boolean {
54 return rating !== 'adult'
55}
56
57/** Whether OpenGraph tags should be included for this rating. */
58export function shouldIncludeOgTags(rating: MaturityRating): boolean {
59 return rating !== 'adult'
60}