@mandujs/core 0.13.0 → 0.13.1

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.
Files changed (155) hide show
  1. package/README.ko.md +4 -4
  2. package/README.md +653 -653
  3. package/package.json +1 -1
  4. package/src/bundler/build.ts +91 -91
  5. package/src/bundler/css.ts +302 -302
  6. package/src/client/Link.tsx +227 -227
  7. package/src/client/globals.ts +44 -44
  8. package/src/client/hooks.ts +267 -267
  9. package/src/client/index.ts +5 -5
  10. package/src/client/island.ts +8 -8
  11. package/src/client/router.ts +435 -435
  12. package/src/client/runtime.ts +23 -23
  13. package/src/client/serialize.ts +404 -404
  14. package/src/client/window-state.ts +101 -101
  15. package/src/config/mandu.ts +9 -0
  16. package/src/config/validate.ts +12 -0
  17. package/src/config/watcher.ts +311 -311
  18. package/src/constants.ts +40 -40
  19. package/src/content/content-layer.ts +314 -314
  20. package/src/content/content.test.ts +433 -433
  21. package/src/content/data-store.ts +245 -245
  22. package/src/content/digest.ts +133 -133
  23. package/src/content/index.ts +164 -164
  24. package/src/content/loader-context.ts +172 -172
  25. package/src/content/loaders/api.ts +216 -216
  26. package/src/content/loaders/file.ts +169 -169
  27. package/src/content/loaders/glob.ts +252 -252
  28. package/src/content/loaders/index.ts +34 -34
  29. package/src/content/loaders/types.ts +137 -137
  30. package/src/content/meta-store.ts +209 -209
  31. package/src/content/types.ts +282 -282
  32. package/src/content/watcher.ts +135 -135
  33. package/src/contract/client-safe.test.ts +42 -42
  34. package/src/contract/client-safe.ts +114 -114
  35. package/src/contract/client.ts +16 -16
  36. package/src/contract/define.ts +459 -459
  37. package/src/contract/handler.ts +10 -10
  38. package/src/contract/normalize.test.ts +276 -276
  39. package/src/contract/normalize.ts +404 -404
  40. package/src/contract/registry.test.ts +206 -206
  41. package/src/contract/registry.ts +568 -568
  42. package/src/contract/schema.ts +48 -48
  43. package/src/contract/types.ts +58 -58
  44. package/src/contract/validator.ts +32 -32
  45. package/src/devtools/ai/context-builder.ts +375 -375
  46. package/src/devtools/ai/index.ts +25 -25
  47. package/src/devtools/ai/mcp-connector.ts +465 -465
  48. package/src/devtools/client/catchers/error-catcher.ts +327 -327
  49. package/src/devtools/client/catchers/index.ts +18 -18
  50. package/src/devtools/client/catchers/network-proxy.ts +363 -363
  51. package/src/devtools/client/components/index.ts +39 -39
  52. package/src/devtools/client/components/kitchen-root.tsx +362 -362
  53. package/src/devtools/client/components/mandu-character.tsx +241 -241
  54. package/src/devtools/client/components/overlay.tsx +368 -368
  55. package/src/devtools/client/components/panel/errors-panel.tsx +259 -259
  56. package/src/devtools/client/components/panel/guard-panel.tsx +244 -244
  57. package/src/devtools/client/components/panel/index.ts +32 -32
  58. package/src/devtools/client/components/panel/islands-panel.tsx +304 -304
  59. package/src/devtools/client/components/panel/network-panel.tsx +292 -292
  60. package/src/devtools/client/components/panel/panel-container.tsx +259 -259
  61. package/src/devtools/client/filters/context-filters.ts +282 -282
  62. package/src/devtools/client/filters/index.ts +16 -16
  63. package/src/devtools/client/index.ts +63 -63
  64. package/src/devtools/client/persistence.ts +335 -335
  65. package/src/devtools/client/state-manager.ts +478 -478
  66. package/src/devtools/design-tokens.ts +263 -263
  67. package/src/devtools/hook/create-hook.ts +207 -207
  68. package/src/devtools/hook/index.ts +13 -13
  69. package/src/devtools/index.ts +439 -439
  70. package/src/devtools/init.ts +266 -266
  71. package/src/devtools/protocol.ts +237 -237
  72. package/src/devtools/server/index.ts +17 -17
  73. package/src/devtools/server/source-context.ts +444 -444
  74. package/src/devtools/types.ts +319 -319
  75. package/src/devtools/worker/index.ts +25 -25
  76. package/src/devtools/worker/redaction-worker.ts +222 -222
  77. package/src/devtools/worker/worker-manager.ts +409 -409
  78. package/src/error/domains.ts +265 -265
  79. package/src/error/result.ts +46 -46
  80. package/src/error/types.ts +6 -6
  81. package/src/errors/extractor.ts +409 -409
  82. package/src/errors/index.ts +19 -19
  83. package/src/filling/auth.ts +308 -308
  84. package/src/filling/context.ts +24 -1
  85. package/src/filling/deps.ts +238 -238
  86. package/src/filling/index.ts +2 -0
  87. package/src/filling/sse.test.ts +168 -0
  88. package/src/filling/sse.ts +162 -0
  89. package/src/generator/index.ts +3 -3
  90. package/src/guard/analyzer.ts +360 -360
  91. package/src/guard/ast-analyzer.ts +806 -806
  92. package/src/guard/contract-guard.ts +9 -9
  93. package/src/guard/file-type.test.ts +24 -24
  94. package/src/guard/presets/atomic.ts +70 -70
  95. package/src/guard/presets/clean.ts +77 -77
  96. package/src/guard/presets/fsd.ts +79 -79
  97. package/src/guard/presets/hexagonal.ts +68 -68
  98. package/src/guard/presets/index.ts +291 -291
  99. package/src/guard/reporter.ts +445 -445
  100. package/src/guard/rules.ts +12 -12
  101. package/src/guard/statistics.ts +578 -578
  102. package/src/guard/suggestions.ts +358 -358
  103. package/src/guard/types.ts +348 -348
  104. package/src/guard/validator.ts +834 -834
  105. package/src/guard/watcher.ts +404 -404
  106. package/src/index.ts +6 -1
  107. package/src/intent/index.ts +310 -310
  108. package/src/island/index.ts +304 -304
  109. package/src/logging/index.ts +22 -22
  110. package/src/logging/transports.ts +365 -365
  111. package/src/plugins/index.ts +38 -38
  112. package/src/plugins/registry.ts +377 -377
  113. package/src/plugins/types.ts +363 -363
  114. package/src/report/index.ts +1 -1
  115. package/src/router/fs-patterns.ts +387 -387
  116. package/src/router/fs-scanner.ts +497 -497
  117. package/src/runtime/boundary.tsx +232 -232
  118. package/src/runtime/compose.ts +222 -222
  119. package/src/runtime/escape.ts +44 -0
  120. package/src/runtime/lifecycle.ts +381 -381
  121. package/src/runtime/logger.test.ts +345 -345
  122. package/src/runtime/logger.ts +677 -677
  123. package/src/runtime/router.test.ts +476 -476
  124. package/src/runtime/router.ts +105 -105
  125. package/src/runtime/security.ts +155 -155
  126. package/src/runtime/server.ts +257 -0
  127. package/src/runtime/session-key.ts +328 -328
  128. package/src/runtime/ssr.ts +16 -21
  129. package/src/runtime/streaming-ssr.ts +24 -33
  130. package/src/runtime/trace.ts +144 -144
  131. package/src/seo/index.ts +214 -214
  132. package/src/seo/integration/ssr.ts +307 -307
  133. package/src/seo/render/basic.ts +427 -427
  134. package/src/seo/render/index.ts +143 -143
  135. package/src/seo/render/jsonld.ts +539 -539
  136. package/src/seo/render/opengraph.ts +191 -191
  137. package/src/seo/render/robots.ts +116 -116
  138. package/src/seo/render/sitemap.ts +137 -137
  139. package/src/seo/render/twitter.ts +126 -126
  140. package/src/seo/resolve/index.ts +353 -353
  141. package/src/seo/resolve/opengraph.ts +143 -143
  142. package/src/seo/resolve/robots.ts +73 -73
  143. package/src/seo/resolve/title.ts +94 -94
  144. package/src/seo/resolve/twitter.ts +73 -73
  145. package/src/seo/resolve/url.ts +97 -97
  146. package/src/seo/routes/index.ts +290 -290
  147. package/src/seo/types.ts +575 -575
  148. package/src/slot/validator.ts +39 -39
  149. package/src/spec/index.ts +3 -3
  150. package/src/spec/load.ts +76 -76
  151. package/src/spec/lock.ts +56 -56
  152. package/src/utils/bun.ts +8 -8
  153. package/src/utils/lru-cache.ts +75 -75
  154. package/src/utils/safe-io.ts +188 -188
  155. package/src/utils/string-safe.ts +298 -298
@@ -1,539 +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
- }
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
+ }