@mandujs/core 0.12.1 → 0.13.0

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