-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathStructuredData.tsx
More file actions
191 lines (176 loc) · 5.83 KB
/
Copy pathStructuredData.tsx
File metadata and controls
191 lines (176 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { Course, Review } from '@/lib/types';
import { SOCIAL_LINKS } from '@/lib/socialLinks';
// Schema.org structured data for SEO - these generate rich snippets in Google
interface CourseSchemaProps {
course: Course;
reviews?: Review[];
}
// Course schema with AggregateRating for rich snippets
export function CourseSchema({ course, reviews = [] }: CourseSchemaProps) {
const schema = {
'@context': 'https://schema.org',
'@type': 'Course',
name: course.name,
description: `${course.name} (${course.courseId}) - Georgia Tech Online Master's course. ${course.numReviews || 0} student reviews with average rating of ${course.avgOverall?.toFixed(1) || 'N/A'}/5.`,
provider: {
'@type': 'Organization',
name: 'Georgia Institute of Technology',
sameAs: 'https://www.gatech.edu',
},
courseCode: course.courseId,
...(course.url && { url: course.url }),
...(course.avgOverall && course.numReviews && {
aggregateRating: {
'@type': 'AggregateRating',
ratingValue: course.avgOverall.toFixed(1),
bestRating: '5',
worstRating: '1',
ratingCount: course.numReviews,
reviewCount: course.numReviews,
},
}),
...(reviews.length > 0 && {
review: reviews.slice(0, 5).map((review) => ({
'@type': 'Review',
reviewRating: {
'@type': 'Rating',
ratingValue: review.overall,
bestRating: '5',
worstRating: '1',
},
author: {
'@type': 'Person',
name: 'Anonymous Student',
},
datePublished: new Date(review.created).toISOString().split('T')[0],
reviewBody: review.body.substring(0, 500) + (review.body.length > 500 ? '...' : ''),
})),
}),
teaches: course.name,
educationalLevel: 'Graduate',
...(course.isFoundational && {
coursePrerequisites: 'Admission to Georgia Tech OMS program',
}),
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
// Organization schema for the website
export function OrganizationSchema() {
const schema = {
'@context': 'https://schema.org',
'@type': 'Organization',
name: 'OMSHub',
description: 'Community-driven course reviews for Georgia Tech Online Master\'s programs (OMSCS, OMSA, OMSCyber)',
url: 'https://omshub.org',
logo: 'https://omshub.org/logo.png',
sameAs: [
SOCIAL_LINKS.github,
SOCIAL_LINKS.discord,
SOCIAL_LINKS.reddit,
SOCIAL_LINKS.slack,
],
foundingDate: '2024',
slogan: 'By students, for students',
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
// Website schema with search action for sitelinks search box
export function WebsiteSchema() {
const schema = {
'@context': 'https://schema.org',
'@type': 'WebSite',
name: 'OMSHub',
url: 'https://omshub.org',
description: 'Georgia Tech OMS Course Reviews - Community-driven ratings and reviews',
potentialAction: {
'@type': 'SearchAction',
target: {
'@type': 'EntryPoint',
urlTemplate: 'https://omshub.org/?search={search_term_string}',
},
'query-input': 'required name=search_term_string',
},
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
// Breadcrumb schema for navigation
interface BreadcrumbSchemaProps {
items: { name: string; url: string }[];
}
export function BreadcrumbSchema({ items }: BreadcrumbSchemaProps) {
const schema = {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
itemListElement: items.map((item, index) => ({
'@type': 'ListItem',
position: index + 1,
name: item.name,
item: item.url,
})),
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}
// FAQ schema for course pages with common questions
interface FAQSchemaProps {
course: Course;
}
export function FAQSchema({ course }: FAQSchemaProps) {
const faqs = [
{
question: `How difficult is ${course.courseId} ${course.name}?`,
answer: course.avgDifficulty
? `Based on ${course.numReviews} student reviews, ${course.courseId} has an average difficulty rating of ${course.avgDifficulty.toFixed(1)}/5. Students report an average workload of ${course.avgWorkload?.toFixed(1) || 'N/A'} hours per week.`
: `${course.courseId} does not have enough reviews yet to determine difficulty.`,
},
{
question: `What is the workload for ${course.courseId}?`,
answer: course.avgWorkload
? `Students report spending an average of ${course.avgWorkload.toFixed(1)} hours per week on ${course.courseId} ${course.name}.`
: `Workload data is not yet available for ${course.courseId}.`,
},
{
question: `Is ${course.courseId} worth taking?`,
answer: course.avgOverall
? `${course.courseId} has an overall rating of ${course.avgOverall.toFixed(1)}/5 based on ${course.numReviews} student reviews. ${course.avgOverall >= 4 ? 'Students generally recommend this course.' : course.avgOverall >= 3 ? 'Student opinions are mixed.' : 'Some students have concerns about this course.'}`
: `There are not enough reviews to determine if ${course.courseId} is worth taking.`,
},
];
const schema = {
'@context': 'https://schema.org',
'@type': 'FAQPage',
mainEntity: faqs.map((faq) => ({
'@type': 'Question',
name: faq.question,
acceptedAnswer: {
'@type': 'Answer',
text: faq.answer,
},
})),
};
return (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(schema) }}
/>
);
}