@mandujs/core 0.9.39 → 0.9.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +27 -0
- package/README.md +21 -5
- package/package.json +1 -1
- package/src/config/index.ts +1 -0
- package/src/config/mandu.ts +60 -0
- package/src/contract/client-safe.test.ts +42 -0
- package/src/contract/client-safe.ts +114 -0
- package/src/contract/client.ts +12 -11
- package/src/contract/handler.ts +10 -11
- package/src/contract/index.ts +25 -16
- package/src/contract/registry.test.ts +206 -0
- package/src/contract/registry.ts +568 -0
- package/src/contract/schema.ts +48 -12
- package/src/contract/types.ts +58 -35
- package/src/contract/validator.ts +32 -17
- package/src/filling/context.ts +103 -0
- package/src/generator/templates.ts +70 -17
- package/src/guard/analyzer.ts +9 -4
- package/src/guard/check.ts +66 -30
- package/src/guard/contract-guard.ts +9 -9
- package/src/guard/file-type.test.ts +24 -0
- package/src/guard/presets/index.ts +193 -60
- package/src/guard/rules.ts +12 -6
- package/src/guard/statistics.ts +6 -0
- package/src/guard/suggestions.ts +9 -2
- package/src/guard/types.ts +11 -1
- package/src/guard/validator.ts +160 -9
- package/src/guard/watcher.ts +2 -0
- package/src/index.ts +8 -1
- package/src/runtime/index.ts +1 -0
- package/src/runtime/streaming-ssr.ts +123 -2
- package/src/seo/index.ts +214 -0
- package/src/seo/integration/ssr.ts +307 -0
- package/src/seo/render/basic.ts +427 -0
- package/src/seo/render/index.ts +143 -0
- package/src/seo/render/jsonld.ts +539 -0
- package/src/seo/render/opengraph.ts +191 -0
- package/src/seo/render/robots.ts +116 -0
- package/src/seo/render/sitemap.ts +137 -0
- package/src/seo/render/twitter.ts +126 -0
- package/src/seo/resolve/index.ts +353 -0
- package/src/seo/resolve/opengraph.ts +143 -0
- package/src/seo/resolve/robots.ts +73 -0
- package/src/seo/resolve/title.ts +94 -0
- package/src/seo/resolve/twitter.ts +73 -0
- package/src/seo/resolve/url.ts +97 -0
- package/src/seo/routes/index.ts +290 -0
- package/src/seo/types.ts +575 -0
- package/src/slot/validator.ts +39 -16
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mandu SEO - JSON-LD Rendering
|
|
3
|
+
*
|
|
4
|
+
* 구조화된 데이터 (Schema.org)
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ResolvedMetadata, JsonLd } from '../types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* JSON-LD script 태그 렌더링
|
|
11
|
+
*/
|
|
12
|
+
export function renderJsonLd(metadata: ResolvedMetadata): string {
|
|
13
|
+
if (!metadata.jsonLd || metadata.jsonLd.length === 0) return ''
|
|
14
|
+
|
|
15
|
+
const tags: string[] = []
|
|
16
|
+
|
|
17
|
+
for (const data of metadata.jsonLd) {
|
|
18
|
+
const json = JSON.stringify(data, null, 0)
|
|
19
|
+
tags.push(`<script type="application/ld+json">${json}</script>`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return tags.join('\n')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// ============================================================================
|
|
26
|
+
// JSON-LD Helpers
|
|
27
|
+
// ============================================================================
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Article JSON-LD 생성 헬퍼
|
|
31
|
+
*/
|
|
32
|
+
export function createArticleJsonLd(options: {
|
|
33
|
+
headline: string
|
|
34
|
+
description?: string
|
|
35
|
+
author: string | { name: string; url?: string }
|
|
36
|
+
datePublished: Date | string
|
|
37
|
+
dateModified?: Date | string
|
|
38
|
+
image?: string | string[]
|
|
39
|
+
publisher?: {
|
|
40
|
+
name: string
|
|
41
|
+
logo?: string
|
|
42
|
+
}
|
|
43
|
+
}): JsonLd {
|
|
44
|
+
const author = typeof options.author === 'string'
|
|
45
|
+
? { '@type': 'Person', name: options.author }
|
|
46
|
+
: { '@type': 'Person', name: options.author.name, url: options.author.url }
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
'@context': 'https://schema.org',
|
|
50
|
+
'@type': 'Article',
|
|
51
|
+
headline: options.headline,
|
|
52
|
+
description: options.description,
|
|
53
|
+
author,
|
|
54
|
+
datePublished: options.datePublished instanceof Date
|
|
55
|
+
? options.datePublished.toISOString()
|
|
56
|
+
: options.datePublished,
|
|
57
|
+
dateModified: options.dateModified instanceof Date
|
|
58
|
+
? options.dateModified.toISOString()
|
|
59
|
+
: options.dateModified,
|
|
60
|
+
image: options.image,
|
|
61
|
+
publisher: options.publisher
|
|
62
|
+
? {
|
|
63
|
+
'@type': 'Organization',
|
|
64
|
+
name: options.publisher.name,
|
|
65
|
+
logo: options.publisher.logo
|
|
66
|
+
? { '@type': 'ImageObject', url: options.publisher.logo }
|
|
67
|
+
: undefined,
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* WebSite JSON-LD 생성 헬퍼
|
|
75
|
+
*/
|
|
76
|
+
export function createWebSiteJsonLd(options: {
|
|
77
|
+
name: string
|
|
78
|
+
url: string
|
|
79
|
+
description?: string
|
|
80
|
+
potentialAction?: {
|
|
81
|
+
searchUrl: string
|
|
82
|
+
queryInput: string
|
|
83
|
+
}
|
|
84
|
+
}): JsonLd {
|
|
85
|
+
return {
|
|
86
|
+
'@context': 'https://schema.org',
|
|
87
|
+
'@type': 'WebSite',
|
|
88
|
+
name: options.name,
|
|
89
|
+
url: options.url,
|
|
90
|
+
description: options.description,
|
|
91
|
+
potentialAction: options.potentialAction
|
|
92
|
+
? {
|
|
93
|
+
'@type': 'SearchAction',
|
|
94
|
+
target: {
|
|
95
|
+
'@type': 'EntryPoint',
|
|
96
|
+
urlTemplate: options.potentialAction.searchUrl,
|
|
97
|
+
},
|
|
98
|
+
'query-input': options.potentialAction.queryInput,
|
|
99
|
+
}
|
|
100
|
+
: undefined,
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Organization JSON-LD 생성 헬퍼
|
|
106
|
+
*/
|
|
107
|
+
export function createOrganizationJsonLd(options: {
|
|
108
|
+
name: string
|
|
109
|
+
url: string
|
|
110
|
+
logo?: string
|
|
111
|
+
description?: string
|
|
112
|
+
sameAs?: string[]
|
|
113
|
+
contactPoint?: {
|
|
114
|
+
telephone?: string
|
|
115
|
+
contactType?: string
|
|
116
|
+
email?: string
|
|
117
|
+
}
|
|
118
|
+
}): JsonLd {
|
|
119
|
+
return {
|
|
120
|
+
'@context': 'https://schema.org',
|
|
121
|
+
'@type': 'Organization',
|
|
122
|
+
name: options.name,
|
|
123
|
+
url: options.url,
|
|
124
|
+
logo: options.logo,
|
|
125
|
+
description: options.description,
|
|
126
|
+
sameAs: options.sameAs,
|
|
127
|
+
contactPoint: options.contactPoint
|
|
128
|
+
? {
|
|
129
|
+
'@type': 'ContactPoint',
|
|
130
|
+
...options.contactPoint,
|
|
131
|
+
}
|
|
132
|
+
: undefined,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* BreadcrumbList JSON-LD 생성 헬퍼
|
|
138
|
+
*/
|
|
139
|
+
export function createBreadcrumbJsonLd(
|
|
140
|
+
items: Array<{ name: string; url: string }>
|
|
141
|
+
): JsonLd {
|
|
142
|
+
return {
|
|
143
|
+
'@context': 'https://schema.org',
|
|
144
|
+
'@type': 'BreadcrumbList',
|
|
145
|
+
itemListElement: items.map((item, index) => ({
|
|
146
|
+
'@type': 'ListItem',
|
|
147
|
+
position: index + 1,
|
|
148
|
+
name: item.name,
|
|
149
|
+
item: item.url,
|
|
150
|
+
})),
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* FAQPage JSON-LD 생성 헬퍼
|
|
156
|
+
*/
|
|
157
|
+
export function createFAQJsonLd(
|
|
158
|
+
questions: Array<{ question: string; answer: string }>
|
|
159
|
+
): JsonLd {
|
|
160
|
+
return {
|
|
161
|
+
'@context': 'https://schema.org',
|
|
162
|
+
'@type': 'FAQPage',
|
|
163
|
+
mainEntity: questions.map(q => ({
|
|
164
|
+
'@type': 'Question',
|
|
165
|
+
name: q.question,
|
|
166
|
+
acceptedAnswer: {
|
|
167
|
+
'@type': 'Answer',
|
|
168
|
+
text: q.answer,
|
|
169
|
+
},
|
|
170
|
+
})),
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Product JSON-LD 생성 헬퍼
|
|
176
|
+
*/
|
|
177
|
+
export function createProductJsonLd(options: {
|
|
178
|
+
name: string
|
|
179
|
+
description?: string
|
|
180
|
+
image?: string | string[]
|
|
181
|
+
brand?: string
|
|
182
|
+
sku?: string
|
|
183
|
+
offers?: {
|
|
184
|
+
price: number
|
|
185
|
+
priceCurrency: string
|
|
186
|
+
availability?: 'InStock' | 'OutOfStock' | 'PreOrder'
|
|
187
|
+
url?: string
|
|
188
|
+
}
|
|
189
|
+
aggregateRating?: {
|
|
190
|
+
ratingValue: number
|
|
191
|
+
reviewCount: number
|
|
192
|
+
}
|
|
193
|
+
}): JsonLd {
|
|
194
|
+
return {
|
|
195
|
+
'@context': 'https://schema.org',
|
|
196
|
+
'@type': 'Product',
|
|
197
|
+
name: options.name,
|
|
198
|
+
description: options.description,
|
|
199
|
+
image: options.image,
|
|
200
|
+
brand: options.brand
|
|
201
|
+
? { '@type': 'Brand', name: options.brand }
|
|
202
|
+
: undefined,
|
|
203
|
+
sku: options.sku,
|
|
204
|
+
offers: options.offers
|
|
205
|
+
? {
|
|
206
|
+
'@type': 'Offer',
|
|
207
|
+
price: options.offers.price,
|
|
208
|
+
priceCurrency: options.offers.priceCurrency,
|
|
209
|
+
availability: options.offers.availability
|
|
210
|
+
? `https://schema.org/${options.offers.availability}`
|
|
211
|
+
: undefined,
|
|
212
|
+
url: options.offers.url,
|
|
213
|
+
}
|
|
214
|
+
: undefined,
|
|
215
|
+
aggregateRating: options.aggregateRating
|
|
216
|
+
? {
|
|
217
|
+
'@type': 'AggregateRating',
|
|
218
|
+
ratingValue: options.aggregateRating.ratingValue,
|
|
219
|
+
reviewCount: options.aggregateRating.reviewCount,
|
|
220
|
+
}
|
|
221
|
+
: undefined,
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* LocalBusiness JSON-LD 생성 헬퍼 (지역 비즈니스)
|
|
227
|
+
*/
|
|
228
|
+
export function createLocalBusinessJsonLd(options: {
|
|
229
|
+
name: string
|
|
230
|
+
description?: string
|
|
231
|
+
url?: string
|
|
232
|
+
telephone?: string
|
|
233
|
+
email?: string
|
|
234
|
+
address: {
|
|
235
|
+
streetAddress: string
|
|
236
|
+
addressLocality: string
|
|
237
|
+
addressRegion?: string
|
|
238
|
+
postalCode: string
|
|
239
|
+
addressCountry: string
|
|
240
|
+
}
|
|
241
|
+
geo?: {
|
|
242
|
+
latitude: number
|
|
243
|
+
longitude: number
|
|
244
|
+
}
|
|
245
|
+
openingHours?: string[]
|
|
246
|
+
priceRange?: string
|
|
247
|
+
image?: string | string[]
|
|
248
|
+
aggregateRating?: {
|
|
249
|
+
ratingValue: number
|
|
250
|
+
reviewCount: number
|
|
251
|
+
}
|
|
252
|
+
}): JsonLd {
|
|
253
|
+
return {
|
|
254
|
+
'@context': 'https://schema.org',
|
|
255
|
+
'@type': 'LocalBusiness',
|
|
256
|
+
name: options.name,
|
|
257
|
+
description: options.description,
|
|
258
|
+
url: options.url,
|
|
259
|
+
telephone: options.telephone,
|
|
260
|
+
email: options.email,
|
|
261
|
+
address: {
|
|
262
|
+
'@type': 'PostalAddress',
|
|
263
|
+
...options.address,
|
|
264
|
+
},
|
|
265
|
+
geo: options.geo
|
|
266
|
+
? {
|
|
267
|
+
'@type': 'GeoCoordinates',
|
|
268
|
+
latitude: options.geo.latitude,
|
|
269
|
+
longitude: options.geo.longitude,
|
|
270
|
+
}
|
|
271
|
+
: undefined,
|
|
272
|
+
openingHoursSpecification: options.openingHours,
|
|
273
|
+
priceRange: options.priceRange,
|
|
274
|
+
image: options.image,
|
|
275
|
+
aggregateRating: options.aggregateRating
|
|
276
|
+
? {
|
|
277
|
+
'@type': 'AggregateRating',
|
|
278
|
+
ratingValue: options.aggregateRating.ratingValue,
|
|
279
|
+
reviewCount: options.aggregateRating.reviewCount,
|
|
280
|
+
}
|
|
281
|
+
: undefined,
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* VideoObject JSON-LD 생성 헬퍼
|
|
287
|
+
*/
|
|
288
|
+
export function createVideoJsonLd(options: {
|
|
289
|
+
name: string
|
|
290
|
+
description: string
|
|
291
|
+
thumbnailUrl: string | string[]
|
|
292
|
+
uploadDate: Date | string
|
|
293
|
+
duration?: string // ISO 8601 format (e.g., "PT1M30S")
|
|
294
|
+
contentUrl?: string
|
|
295
|
+
embedUrl?: string
|
|
296
|
+
interactionCount?: number
|
|
297
|
+
}): JsonLd {
|
|
298
|
+
return {
|
|
299
|
+
'@context': 'https://schema.org',
|
|
300
|
+
'@type': 'VideoObject',
|
|
301
|
+
name: options.name,
|
|
302
|
+
description: options.description,
|
|
303
|
+
thumbnailUrl: options.thumbnailUrl,
|
|
304
|
+
uploadDate: options.uploadDate instanceof Date
|
|
305
|
+
? options.uploadDate.toISOString()
|
|
306
|
+
: options.uploadDate,
|
|
307
|
+
duration: options.duration,
|
|
308
|
+
contentUrl: options.contentUrl,
|
|
309
|
+
embedUrl: options.embedUrl,
|
|
310
|
+
interactionStatistic: options.interactionCount
|
|
311
|
+
? {
|
|
312
|
+
'@type': 'InteractionCounter',
|
|
313
|
+
interactionType: { '@type': 'WatchAction' },
|
|
314
|
+
userInteractionCount: options.interactionCount,
|
|
315
|
+
}
|
|
316
|
+
: undefined,
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Review JSON-LD 생성 헬퍼
|
|
322
|
+
*/
|
|
323
|
+
export function createReviewJsonLd(options: {
|
|
324
|
+
itemReviewed: {
|
|
325
|
+
type: string
|
|
326
|
+
name: string
|
|
327
|
+
}
|
|
328
|
+
author: string | { name: string; url?: string }
|
|
329
|
+
reviewRating: {
|
|
330
|
+
ratingValue: number
|
|
331
|
+
bestRating?: number
|
|
332
|
+
worstRating?: number
|
|
333
|
+
}
|
|
334
|
+
reviewBody?: string
|
|
335
|
+
datePublished?: Date | string
|
|
336
|
+
}): JsonLd {
|
|
337
|
+
const author = typeof options.author === 'string'
|
|
338
|
+
? { '@type': 'Person', name: options.author }
|
|
339
|
+
: { '@type': 'Person', name: options.author.name, url: options.author.url }
|
|
340
|
+
|
|
341
|
+
return {
|
|
342
|
+
'@context': 'https://schema.org',
|
|
343
|
+
'@type': 'Review',
|
|
344
|
+
itemReviewed: {
|
|
345
|
+
'@type': options.itemReviewed.type,
|
|
346
|
+
name: options.itemReviewed.name,
|
|
347
|
+
},
|
|
348
|
+
author,
|
|
349
|
+
reviewRating: {
|
|
350
|
+
'@type': 'Rating',
|
|
351
|
+
ratingValue: options.reviewRating.ratingValue,
|
|
352
|
+
bestRating: options.reviewRating.bestRating || 5,
|
|
353
|
+
worstRating: options.reviewRating.worstRating || 1,
|
|
354
|
+
},
|
|
355
|
+
reviewBody: options.reviewBody,
|
|
356
|
+
datePublished: options.datePublished instanceof Date
|
|
357
|
+
? options.datePublished.toISOString()
|
|
358
|
+
: options.datePublished,
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Course JSON-LD 생성 헬퍼 (교육 콘텐츠)
|
|
364
|
+
*/
|
|
365
|
+
export function createCourseJsonLd(options: {
|
|
366
|
+
name: string
|
|
367
|
+
description: string
|
|
368
|
+
provider: {
|
|
369
|
+
name: string
|
|
370
|
+
url?: string
|
|
371
|
+
}
|
|
372
|
+
url?: string
|
|
373
|
+
image?: string
|
|
374
|
+
aggregateRating?: {
|
|
375
|
+
ratingValue: number
|
|
376
|
+
reviewCount: number
|
|
377
|
+
}
|
|
378
|
+
offers?: {
|
|
379
|
+
price: number
|
|
380
|
+
priceCurrency: string
|
|
381
|
+
}
|
|
382
|
+
}): JsonLd {
|
|
383
|
+
return {
|
|
384
|
+
'@context': 'https://schema.org',
|
|
385
|
+
'@type': 'Course',
|
|
386
|
+
name: options.name,
|
|
387
|
+
description: options.description,
|
|
388
|
+
provider: {
|
|
389
|
+
'@type': 'Organization',
|
|
390
|
+
name: options.provider.name,
|
|
391
|
+
url: options.provider.url,
|
|
392
|
+
},
|
|
393
|
+
url: options.url,
|
|
394
|
+
image: options.image,
|
|
395
|
+
aggregateRating: options.aggregateRating
|
|
396
|
+
? {
|
|
397
|
+
'@type': 'AggregateRating',
|
|
398
|
+
ratingValue: options.aggregateRating.ratingValue,
|
|
399
|
+
reviewCount: options.aggregateRating.reviewCount,
|
|
400
|
+
}
|
|
401
|
+
: undefined,
|
|
402
|
+
offers: options.offers
|
|
403
|
+
? {
|
|
404
|
+
'@type': 'Offer',
|
|
405
|
+
price: options.offers.price,
|
|
406
|
+
priceCurrency: options.offers.priceCurrency,
|
|
407
|
+
}
|
|
408
|
+
: undefined,
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Event JSON-LD 생성 헬퍼
|
|
414
|
+
*/
|
|
415
|
+
export function createEventJsonLd(options: {
|
|
416
|
+
name: string
|
|
417
|
+
description?: string
|
|
418
|
+
startDate: Date | string
|
|
419
|
+
endDate?: Date | string
|
|
420
|
+
location: {
|
|
421
|
+
name: string
|
|
422
|
+
address: string
|
|
423
|
+
} | {
|
|
424
|
+
type: 'VirtualLocation'
|
|
425
|
+
url: string
|
|
426
|
+
}
|
|
427
|
+
image?: string
|
|
428
|
+
organizer?: {
|
|
429
|
+
name: string
|
|
430
|
+
url?: string
|
|
431
|
+
}
|
|
432
|
+
offers?: {
|
|
433
|
+
price: number
|
|
434
|
+
priceCurrency: string
|
|
435
|
+
availability?: 'InStock' | 'SoldOut' | 'PreOrder'
|
|
436
|
+
validFrom?: Date | string
|
|
437
|
+
url?: string
|
|
438
|
+
}
|
|
439
|
+
eventStatus?: 'EventScheduled' | 'EventCancelled' | 'EventPostponed' | 'EventRescheduled'
|
|
440
|
+
eventAttendanceMode?: 'OfflineEventAttendanceMode' | 'OnlineEventAttendanceMode' | 'MixedEventAttendanceMode'
|
|
441
|
+
}): JsonLd {
|
|
442
|
+
const location = 'type' in options.location && options.location.type === 'VirtualLocation'
|
|
443
|
+
? {
|
|
444
|
+
'@type': 'VirtualLocation',
|
|
445
|
+
url: options.location.url,
|
|
446
|
+
}
|
|
447
|
+
: {
|
|
448
|
+
'@type': 'Place',
|
|
449
|
+
name: (options.location as { name: string; address: string }).name,
|
|
450
|
+
address: (options.location as { name: string; address: string }).address,
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
'@context': 'https://schema.org',
|
|
455
|
+
'@type': 'Event',
|
|
456
|
+
name: options.name,
|
|
457
|
+
description: options.description,
|
|
458
|
+
startDate: options.startDate instanceof Date
|
|
459
|
+
? options.startDate.toISOString()
|
|
460
|
+
: options.startDate,
|
|
461
|
+
endDate: options.endDate instanceof Date
|
|
462
|
+
? options.endDate.toISOString()
|
|
463
|
+
: options.endDate,
|
|
464
|
+
location,
|
|
465
|
+
image: options.image,
|
|
466
|
+
organizer: options.organizer
|
|
467
|
+
? {
|
|
468
|
+
'@type': 'Organization',
|
|
469
|
+
name: options.organizer.name,
|
|
470
|
+
url: options.organizer.url,
|
|
471
|
+
}
|
|
472
|
+
: undefined,
|
|
473
|
+
offers: options.offers
|
|
474
|
+
? {
|
|
475
|
+
'@type': 'Offer',
|
|
476
|
+
price: options.offers.price,
|
|
477
|
+
priceCurrency: options.offers.priceCurrency,
|
|
478
|
+
availability: options.offers.availability
|
|
479
|
+
? `https://schema.org/${options.offers.availability}`
|
|
480
|
+
: undefined,
|
|
481
|
+
validFrom: options.offers.validFrom instanceof Date
|
|
482
|
+
? options.offers.validFrom.toISOString()
|
|
483
|
+
: options.offers.validFrom,
|
|
484
|
+
url: options.offers.url,
|
|
485
|
+
}
|
|
486
|
+
: undefined,
|
|
487
|
+
eventStatus: options.eventStatus
|
|
488
|
+
? `https://schema.org/${options.eventStatus}`
|
|
489
|
+
: undefined,
|
|
490
|
+
eventAttendanceMode: options.eventAttendanceMode
|
|
491
|
+
? `https://schema.org/${options.eventAttendanceMode}`
|
|
492
|
+
: undefined,
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* SoftwareApplication JSON-LD 생성 헬퍼
|
|
498
|
+
*/
|
|
499
|
+
export function createSoftwareAppJsonLd(options: {
|
|
500
|
+
name: string
|
|
501
|
+
description?: string
|
|
502
|
+
applicationCategory?: string
|
|
503
|
+
operatingSystem?: string
|
|
504
|
+
offers?: {
|
|
505
|
+
price: number
|
|
506
|
+
priceCurrency: string
|
|
507
|
+
}
|
|
508
|
+
aggregateRating?: {
|
|
509
|
+
ratingValue: number
|
|
510
|
+
ratingCount: number
|
|
511
|
+
}
|
|
512
|
+
downloadUrl?: string
|
|
513
|
+
screenshot?: string | string[]
|
|
514
|
+
}): JsonLd {
|
|
515
|
+
return {
|
|
516
|
+
'@context': 'https://schema.org',
|
|
517
|
+
'@type': 'SoftwareApplication',
|
|
518
|
+
name: options.name,
|
|
519
|
+
description: options.description,
|
|
520
|
+
applicationCategory: options.applicationCategory,
|
|
521
|
+
operatingSystem: options.operatingSystem,
|
|
522
|
+
offers: options.offers
|
|
523
|
+
? {
|
|
524
|
+
'@type': 'Offer',
|
|
525
|
+
price: options.offers.price,
|
|
526
|
+
priceCurrency: options.offers.priceCurrency,
|
|
527
|
+
}
|
|
528
|
+
: undefined,
|
|
529
|
+
aggregateRating: options.aggregateRating
|
|
530
|
+
? {
|
|
531
|
+
'@type': 'AggregateRating',
|
|
532
|
+
ratingValue: options.aggregateRating.ratingValue,
|
|
533
|
+
ratingCount: options.aggregateRating.ratingCount,
|
|
534
|
+
}
|
|
535
|
+
: undefined,
|
|
536
|
+
downloadUrl: options.downloadUrl,
|
|
537
|
+
screenshot: options.screenshot,
|
|
538
|
+
}
|
|
539
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mandu SEO - Open Graph Meta Tags Rendering
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ResolvedMetadata, ResolvedOpenGraph } from '../types'
|
|
6
|
+
import { urlToString } from '../resolve/url'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* HTML 이스케이프
|
|
10
|
+
*/
|
|
11
|
+
function escapeHtml(str: string): string {
|
|
12
|
+
return str
|
|
13
|
+
.replace(/&/g, '&')
|
|
14
|
+
.replace(/</g, '<')
|
|
15
|
+
.replace(/>/g, '>')
|
|
16
|
+
.replace(/"/g, '"')
|
|
17
|
+
.replace(/'/g, ''')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* OG 메타 태그 생성 헬퍼
|
|
22
|
+
*/
|
|
23
|
+
function og(property: string, content: string | number): string {
|
|
24
|
+
return `<meta property="og:${property}" content="${escapeHtml(String(content))}" />`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Open Graph 메타 태그 렌더링
|
|
29
|
+
*/
|
|
30
|
+
export function renderOpenGraph(metadata: ResolvedMetadata): string {
|
|
31
|
+
const openGraph = metadata.openGraph
|
|
32
|
+
if (!openGraph) return ''
|
|
33
|
+
|
|
34
|
+
const tags: string[] = []
|
|
35
|
+
|
|
36
|
+
// Basic OG tags
|
|
37
|
+
if (openGraph.type) {
|
|
38
|
+
tags.push(og('type', openGraph.type))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// title - fallback to metadata.title
|
|
42
|
+
const title = openGraph.title || metadata.title?.absolute
|
|
43
|
+
if (title) {
|
|
44
|
+
tags.push(og('title', title))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// description - fallback to metadata.description
|
|
48
|
+
const description = openGraph.description || metadata.description
|
|
49
|
+
if (description) {
|
|
50
|
+
tags.push(og('description', description))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (openGraph.url) {
|
|
54
|
+
tags.push(og('url', openGraph.url.href))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (openGraph.siteName) {
|
|
58
|
+
tags.push(og('site_name', openGraph.siteName))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (openGraph.locale) {
|
|
62
|
+
tags.push(og('locale', openGraph.locale))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (openGraph.determiner) {
|
|
66
|
+
tags.push(og('determiner', openGraph.determiner))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Images
|
|
70
|
+
if (openGraph.images) {
|
|
71
|
+
for (const image of openGraph.images) {
|
|
72
|
+
tags.push(og('image', urlToString(image.url)))
|
|
73
|
+
if (image.secureUrl) {
|
|
74
|
+
tags.push(og('image:secure_url', urlToString(image.secureUrl)))
|
|
75
|
+
}
|
|
76
|
+
if (image.type) {
|
|
77
|
+
tags.push(og('image:type', image.type))
|
|
78
|
+
}
|
|
79
|
+
if (image.width) {
|
|
80
|
+
tags.push(og('image:width', image.width))
|
|
81
|
+
}
|
|
82
|
+
if (image.height) {
|
|
83
|
+
tags.push(og('image:height', image.height))
|
|
84
|
+
}
|
|
85
|
+
if (image.alt) {
|
|
86
|
+
tags.push(og('image:alt', image.alt))
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Videos
|
|
92
|
+
if (openGraph.videos) {
|
|
93
|
+
for (const video of openGraph.videos) {
|
|
94
|
+
tags.push(og('video', urlToString(video.url)))
|
|
95
|
+
if (video.secureUrl) {
|
|
96
|
+
tags.push(og('video:secure_url', urlToString(video.secureUrl)))
|
|
97
|
+
}
|
|
98
|
+
if (video.type) {
|
|
99
|
+
tags.push(og('video:type', video.type))
|
|
100
|
+
}
|
|
101
|
+
if (video.width) {
|
|
102
|
+
tags.push(og('video:width', video.width))
|
|
103
|
+
}
|
|
104
|
+
if (video.height) {
|
|
105
|
+
tags.push(og('video:height', video.height))
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Audio
|
|
111
|
+
if (openGraph.audio) {
|
|
112
|
+
for (const audio of openGraph.audio) {
|
|
113
|
+
tags.push(og('audio', urlToString(audio.url)))
|
|
114
|
+
if (audio.secureUrl) {
|
|
115
|
+
tags.push(og('audio:secure_url', urlToString(audio.secureUrl)))
|
|
116
|
+
}
|
|
117
|
+
if (audio.type) {
|
|
118
|
+
tags.push(og('audio:type', audio.type))
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Article specific
|
|
124
|
+
if (openGraph.article) {
|
|
125
|
+
const article = openGraph.article
|
|
126
|
+
if (article.publishedTime) {
|
|
127
|
+
tags.push(og('article:published_time', article.publishedTime))
|
|
128
|
+
}
|
|
129
|
+
if (article.modifiedTime) {
|
|
130
|
+
tags.push(og('article:modified_time', article.modifiedTime))
|
|
131
|
+
}
|
|
132
|
+
if (article.expirationTime) {
|
|
133
|
+
tags.push(og('article:expiration_time', article.expirationTime))
|
|
134
|
+
}
|
|
135
|
+
if (article.section) {
|
|
136
|
+
tags.push(og('article:section', article.section))
|
|
137
|
+
}
|
|
138
|
+
if (article.authors) {
|
|
139
|
+
const authors = Array.isArray(article.authors) ? article.authors : [article.authors]
|
|
140
|
+
for (const author of authors) {
|
|
141
|
+
tags.push(og('article:author', author))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (article.tags) {
|
|
145
|
+
for (const tag of article.tags) {
|
|
146
|
+
tags.push(og('article:tag', tag))
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Profile specific
|
|
152
|
+
if (openGraph.profile) {
|
|
153
|
+
const profile = openGraph.profile
|
|
154
|
+
if (profile.firstName) {
|
|
155
|
+
tags.push(og('profile:first_name', profile.firstName))
|
|
156
|
+
}
|
|
157
|
+
if (profile.lastName) {
|
|
158
|
+
tags.push(og('profile:last_name', profile.lastName))
|
|
159
|
+
}
|
|
160
|
+
if (profile.username) {
|
|
161
|
+
tags.push(og('profile:username', profile.username))
|
|
162
|
+
}
|
|
163
|
+
if (profile.gender) {
|
|
164
|
+
tags.push(og('profile:gender', profile.gender))
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Book specific
|
|
169
|
+
if (openGraph.book) {
|
|
170
|
+
const book = openGraph.book
|
|
171
|
+
if (book.isbn) {
|
|
172
|
+
tags.push(og('book:isbn', book.isbn))
|
|
173
|
+
}
|
|
174
|
+
if (book.releaseDate) {
|
|
175
|
+
tags.push(og('book:release_date', book.releaseDate))
|
|
176
|
+
}
|
|
177
|
+
if (book.authors) {
|
|
178
|
+
const authors = Array.isArray(book.authors) ? book.authors : [book.authors]
|
|
179
|
+
for (const author of authors) {
|
|
180
|
+
tags.push(og('book:author', author))
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (book.tags) {
|
|
184
|
+
for (const tag of book.tags) {
|
|
185
|
+
tags.push(og('book:tag', tag))
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return tags.join('\n')
|
|
191
|
+
}
|