@crawl-me-maybe/schema 0.1.0 → 0.2.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.
- package/README.md +302 -1
- package/dist/build.d.ts +2 -0
- package/dist/builders/aggregate-offer.d.ts +3 -0
- package/dist/builders/brand.d.ts +3 -0
- package/dist/builders/course-instance.d.ts +3 -0
- package/dist/builders/geo-coordinates.d.ts +3 -0
- package/dist/builders/how-to-step.d.ts +3 -0
- package/dist/builders/index.d.ts +16 -0
- package/dist/builders/merchant-return-policy.d.ts +3 -0
- package/dist/builders/monetary-amount.d.ts +3 -0
- package/dist/builders/nutrition-information.d.ts +3 -0
- package/dist/builders/offer-shipping-details.d.ts +3 -0
- package/dist/builders/offer.d.ts +3 -0
- package/dist/builders/organization.d.ts +3 -0
- package/dist/builders/person.d.ts +3 -0
- package/dist/builders/place.d.ts +3 -0
- package/dist/builders/postal-address.d.ts +3 -0
- package/dist/builders/quantitative-value.d.ts +3 -0
- package/dist/builders/schedule.d.ts +3 -0
- package/dist/identity-ref.d.ts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +123 -262
- package/dist/index.js.map +26 -13
- package/dist/utils/datetime.d.ts +11 -0
- package/dist/utils/image.d.ts +8 -1
- package/dist/utils/url.d.ts +1 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
<img width="1590" height="408" alt="schema-thumb" src="https://github.com/user-attachments/assets/3afe5640-0396-48cd-abb9-8bfcae3ca7fc" />
|
|
2
|
+
<br/>
|
|
3
|
+
|
|
1
4
|
# @crawl-me-maybe/schema
|
|
2
5
|
|
|
3
6
|
Schema markup should be generated from your content model, not rebuilt beside it. If editors update the content, the schema should update with it.
|
|
@@ -12,6 +15,11 @@ Schema markup should be generated from your content model, not rebuilt beside it
|
|
|
12
15
|
- [`mainEntity`](#mainentity)
|
|
13
16
|
- [`@id` and de-duplication](#id-and-de-duplication)
|
|
14
17
|
- [Rendering the graph](#rendering-the-graph)
|
|
18
|
+
- [Localized pages](#localized-pages)
|
|
19
|
+
- [Nesting entities](#nesting-entities)
|
|
20
|
+
- [Dates and durations](#dates-and-durations)
|
|
21
|
+
- [Helpers](#helpers)
|
|
22
|
+
- [Empty values](#empty-values)
|
|
15
23
|
- [Supported schemas](#supported-schemas)
|
|
16
24
|
- [With Sanity](#with-sanity)
|
|
17
25
|
- [Core exports](#core-exports)
|
|
@@ -33,8 +41,11 @@ yarn add @crawl-me-maybe/schema
|
|
|
33
41
|
- `buildSchemaMarkup` emits a JSON-LD graph for identity, `WebSite`, and `WebPage`
|
|
34
42
|
- Typed builders for common Schema.org nodes, backed by `schema-dts`
|
|
35
43
|
- Entity de-duping by `@id` when nested nodes reference the same entity
|
|
36
|
-
- Identity roots for `Person`, `Organization`, and `LocalBusiness`
|
|
44
|
+
- Identity roots for `Person`, `Organization`, and `LocalBusiness`, linkable from any page via `identityRef`
|
|
37
45
|
- Utility builders for breadcrumbs, FAQ pages, products, articles, events, and more
|
|
46
|
+
- Nested builders for offers, course instances, schedules, places, people, and more
|
|
47
|
+
- Cleans the graph for you: nested `@context` and empty values (`null`, `""`, `[]`) are dropped
|
|
48
|
+
- Small helpers for ISO 8601 durations and dates, and absolute URLs
|
|
38
49
|
|
|
39
50
|
## Why this exists
|
|
40
51
|
|
|
@@ -133,6 +144,10 @@ If multiple nodes reference the same entity, give them the same `@id`. The libra
|
|
|
133
144
|
|
|
134
145
|
In most cases, `buildSchemaMarkup` handles page-level identity, `WebSite`, and `WebPage` IDs for you. You'll mainly care about `@id` when composing custom or nested entities manually.
|
|
135
146
|
|
|
147
|
+
A nested node with both `@type` and `@id` is hoisted to its own top-level node in the graph, and replaced where it was nested with an `{ "@id": ... }` reference. To link to the site identity, use [`identityRef`](#identityref).
|
|
148
|
+
|
|
149
|
+
Generated IDs ignore trailing slashes on `siteUrl`, so `https://example.com` and `https://example.com/` produce the same IDs.
|
|
150
|
+
|
|
136
151
|
---
|
|
137
152
|
|
|
138
153
|
## Rendering the graph
|
|
@@ -149,6 +164,229 @@ In most cases, `buildSchemaMarkup` handles page-level identity, `WebSite`, and `
|
|
|
149
164
|
|
|
150
165
|
---
|
|
151
166
|
|
|
167
|
+
## Localized pages
|
|
168
|
+
|
|
169
|
+
Pass `inLanguage` to set the language of the current page. It is emitted on the `WebPage` node only.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
buildSchemaMarkup({
|
|
173
|
+
// ...
|
|
174
|
+
siteUrl: "https://example.com",
|
|
175
|
+
pageUrl: "https://example.com/fr/a-propos",
|
|
176
|
+
pageTitle: "À propos",
|
|
177
|
+
inLanguage: "fr",
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
- Pass the language of the content that is actually rendered. If a `/fr/...` route falls back to English content, pass `"en"`.
|
|
182
|
+
- Use a BCP 47 tag with hyphens (`fr-CA`, not `fr_CA`). Never pass `x-default`; it is an hreflang value, not a language.
|
|
183
|
+
- Keep `siteUrl` as the root origin for every locale (`https://example.com`, not `https://example.com/fr`) so all locales share one `WebSite` `@id`.
|
|
184
|
+
- Nested entities don't inherit it and don't need it. Set `inLanguage` on an entity only when its language differs from the page.
|
|
185
|
+
- `inLanguage` does not replace hreflang. Localized alternates still come from your sitemap or `<link rel="alternate" hreflang>` tags.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Nesting entities
|
|
190
|
+
|
|
191
|
+
Nested values like a course's offers or instances need their own `@type`. Use a nested builder where one exists, or a plain object with `"@type"` for anything else:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import {
|
|
195
|
+
buildCourse,
|
|
196
|
+
buildCourseInstance,
|
|
197
|
+
buildOffer,
|
|
198
|
+
buildSchedule,
|
|
199
|
+
identityRef,
|
|
200
|
+
toIsoDate,
|
|
201
|
+
toIsoDuration,
|
|
202
|
+
} from "@crawl-me-maybe/schema";
|
|
203
|
+
|
|
204
|
+
const mainEntity = buildCourse({
|
|
205
|
+
name: course.title,
|
|
206
|
+
description: course.summary,
|
|
207
|
+
provider: identityRef,
|
|
208
|
+
offers: [
|
|
209
|
+
buildOffer({
|
|
210
|
+
category: "Paid",
|
|
211
|
+
price: course.price,
|
|
212
|
+
priceCurrency: "USD",
|
|
213
|
+
}),
|
|
214
|
+
],
|
|
215
|
+
hasCourseInstance: [
|
|
216
|
+
buildCourseInstance({
|
|
217
|
+
courseMode: "Online",
|
|
218
|
+
courseWorkload: toIsoDuration({ hours: course.totalHours }),
|
|
219
|
+
courseSchedule: buildSchedule({
|
|
220
|
+
duration: toIsoDuration({ minutes: course.sessionMinutes }),
|
|
221
|
+
repeatFrequency: "P1W",
|
|
222
|
+
startDate: toIsoDate(course.startsAt),
|
|
223
|
+
}),
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
// No builder for this type — a plain object with "@type" works too.
|
|
227
|
+
audience: { "@type": "EducationalAudience", educationalRole: "student" },
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
- Builders add their own `@context`. When nested, `buildSchemaMarkup` strips it, so only top-level nodes carry `@context`.
|
|
232
|
+
- There is no automatic `@type` inference. Many properties accept more than one type (`author` can be a `Person` or `Organization`), and `@type` is what gives you accurate autocomplete from `schema-dts`.
|
|
233
|
+
- The graph cleanup (nested `@context`, [empty values](#empty-values), and `identityRef`) only happens inside `buildSchemaMarkup`. If you serialize a builder's output yourself, it's emitted as-is.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Dates and durations
|
|
238
|
+
|
|
239
|
+
Schema.org expects ISO 8601 for dates and durations, but `schema-dts` types them as plain `string`, so nothing catches `"3 hours"` at compile time.
|
|
240
|
+
|
|
241
|
+
| Format | Common fields |
|
|
242
|
+
|---|---|
|
|
243
|
+
| Duration (`PT1H30M`) | `Recipe.prepTime` / `cookTime` / `totalTime`, `VideoObject.duration`, `Movie.duration`, `Schedule.duration` / `repeatFrequency`, `CourseInstance.courseWorkload` |
|
|
244
|
+
| Date / date-time (`2026-09-28`, `2026-09-28T13:00:00-06:00`) | `Article.datePublished` / `dateModified`, `Event.startDate` / `endDate`, `JobPosting.datePosted` / `validThrough`, `VideoObject.uploadDate`, `Offer.validFrom` / `validThrough` / `priceValidUntil`, `Schedule.startDate` / `endDate` |
|
|
245
|
+
|
|
246
|
+
### `toIsoDuration(parts)`
|
|
247
|
+
|
|
248
|
+
Takes an object of named parts, so the unit is always explicit:
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
toIsoDuration({ hours: 1, minutes: 30 }); // "PT1H30M"
|
|
252
|
+
toIsoDuration({ seconds: video.duration }); // "PT183S"
|
|
253
|
+
toIsoDuration({ minutes: recipe.cookMinutes }); // "PT45M"
|
|
254
|
+
toIsoDuration({ weeks: 1 }); // "P1W"
|
|
255
|
+
toIsoDuration({ months: 1 }); // "P1M"
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
- Accepts `years`, `months`, `weeks`, `days`, `hours`, `minutes`, and `seconds`.
|
|
259
|
+
- Parts are emitted as given, without carrying over — `{ minutes: 90 }` is `"PT90M"`, which is valid ISO 8601.
|
|
260
|
+
- Zero parts are omitted; all zeros gives `"PT0S"`.
|
|
261
|
+
- Throws on negative or non-finite values, fractional values other than `seconds`, and `weeks` combined with other parts.
|
|
262
|
+
|
|
263
|
+
### `toIsoDate(value)`
|
|
264
|
+
|
|
265
|
+
Accepts a `Date` or an ISO 8601 string:
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
toIsoDate(new Date()); // "2026-09-28T19:17:00.000Z"
|
|
269
|
+
toIsoDate("2026-09-28T19:17:00.000Z"); // unchanged (Sanity datetime)
|
|
270
|
+
toIsoDate("2026-09-28T13:00:00-06:00"); // unchanged, offset kept
|
|
271
|
+
toIsoDate("2026-09-28T13:00+0600"); // "2026-09-28T13:00+06:00"
|
|
272
|
+
toIsoDate("2026-09-28"); // unchanged
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
- `Date` objects are converted to UTC with `toISOString()`.
|
|
276
|
+
- Valid ISO strings are returned as written, so an editor's local time and offset survive. `+hhmm` offsets are rewritten to `+hh:mm`.
|
|
277
|
+
- Date-times without an offset are passed through unchanged — the helper can't safely guess a timezone.
|
|
278
|
+
- Anything else throws.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Helpers
|
|
283
|
+
|
|
284
|
+
### `identityRef`
|
|
285
|
+
|
|
286
|
+
Page- and component-level code usually doesn't have the global identity config handy. Use `identityRef` anywhere an entity is expected, and `buildSchemaMarkup` resolves it to the `@id` of the identity node it emits:
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
// Page or component level
|
|
290
|
+
const mainEntity = buildCourse({
|
|
291
|
+
name: course.title,
|
|
292
|
+
provider: identityRef,
|
|
293
|
+
publisher: identityRef,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
// App level
|
|
297
|
+
buildSchemaMarkup({
|
|
298
|
+
identity: { type: "organization", name: siteName },
|
|
299
|
+
siteUrl,
|
|
300
|
+
siteName,
|
|
301
|
+
pageUrl,
|
|
302
|
+
pageTitle,
|
|
303
|
+
mainEntity,
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Prefer this over inlining `{ "@type": "Organization", name: siteName, url: siteUrl }`. Without an `@id`, the inline version is a second organization that search engines can't link to your site identity.
|
|
308
|
+
|
|
309
|
+
`identityRef` is a plain object (`{ "@id": "@identity" }`), so it survives being serialized across a server/client or loader boundary. It only resolves inside `buildSchemaMarkup`.
|
|
310
|
+
|
|
311
|
+
### Reusing other entities
|
|
312
|
+
|
|
313
|
+
For entities that appear in several places, like an instructor across courses, give them a stable `@id`. They're hoisted to top-level nodes and de-duplicated:
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
const instructor = buildPerson({
|
|
317
|
+
"@id": `${siteUrl}#instructor-jane`,
|
|
318
|
+
name: "Jane Doe",
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
buildCourse({
|
|
322
|
+
name: "Intro",
|
|
323
|
+
hasCourseInstance: [
|
|
324
|
+
buildCourseInstance({ courseMode: "Online", instructor: [instructor] }),
|
|
325
|
+
],
|
|
326
|
+
});
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### `toAbsoluteUrl(value, siteUrl)`
|
|
330
|
+
|
|
331
|
+
Search engines expect absolute URLs for `url`, `image`, and breadcrumb `item` values. CMS content usually gives you slugs or relative paths:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
toAbsoluteUrl("/blog/post", "https://example.com"); // "https://example.com/blog/post"
|
|
335
|
+
toAbsoluteUrl("blog/post", "https://example.com/"); // "https://example.com/blog/post"
|
|
336
|
+
toAbsoluteUrl("/a", "https://example.com/docs"); // "https://example.com/docs/a"
|
|
337
|
+
toAbsoluteUrl("https://cdn.sanity.io/x.jpg", siteUrl); // unchanged
|
|
338
|
+
toAbsoluteUrl("//cdn.example.com/x.jpg", "https://example.com"); // "https://cdn.example.com/x.jpg"
|
|
339
|
+
toAbsoluteUrl(null, siteUrl); // undefined
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Relative values are joined to `siteUrl`, keeping any base path. Empty input returns `undefined`, so the field is dropped from the graph.
|
|
343
|
+
|
|
344
|
+
### `buildImageObject(input)`
|
|
345
|
+
|
|
346
|
+
Turns a URL string or an object into an `ImageObject`, typed so it can be passed straight to any `image` or `logo` field. Returns `undefined` for empty input.
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
buildImageObject("https://example.com/logo.png");
|
|
350
|
+
buildImageObject({ url: image.url, width: 1200, height: 630 });
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
The output always includes `contentUrl` alongside `url`, with the same value. Google's [image metadata](https://developers.google.com/search/docs/appearance/structured-data/image-license-metadata) feature requires `contentUrl`, and other uses such as logos read `url`.
|
|
354
|
+
|
|
355
|
+
To show license and credit details in Google Images, add any of the image metadata fields:
|
|
356
|
+
|
|
357
|
+
```ts
|
|
358
|
+
buildImageObject({
|
|
359
|
+
url: image.url,
|
|
360
|
+
caption: image.alt,
|
|
361
|
+
creditText: "Acme Photography",
|
|
362
|
+
copyrightNotice: "© 2026 Acme",
|
|
363
|
+
license: "https://example.com/image-license",
|
|
364
|
+
acquireLicensePage: "https://example.com/licensing",
|
|
365
|
+
creator: identityRef,
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
`creator` accepts `identityRef`, `buildPerson(...)`, `buildOrganization(...)`, or an `{ "@id" }` reference.
|
|
370
|
+
|
|
371
|
+
### Portable Text
|
|
372
|
+
|
|
373
|
+
For descriptions stored as Portable Text, convert to a plain string first — for example with `toPlainText` from [`@portabletext/toolkit`](https://github.com/portabletext/toolkit). This package has no Sanity dependency.
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## Empty values
|
|
378
|
+
|
|
379
|
+
`buildSchemaMarkup` drops values that carry no information before serializing:
|
|
380
|
+
|
|
381
|
+
- `null` and `undefined`
|
|
382
|
+
- empty or whitespace-only strings
|
|
383
|
+
- empty arrays (after removing empty items)
|
|
384
|
+
- objects with nothing besides `@type`
|
|
385
|
+
|
|
386
|
+
`0` and `false` are kept. GROQ returns `null` for unset fields, so projections don't need `coalesce()` just to keep `null` out of the markup.
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
152
390
|
## Supported schemas
|
|
153
391
|
|
|
154
392
|
Builders are exported from the package root.
|
|
@@ -197,8 +435,67 @@ Site identity (`Organization`, `Person`, or `LocalBusiness`) is emitted by `buil
|
|
|
197
435
|
| `buildDiscussionForumPosting` | `DiscussionForumPosting` |
|
|
198
436
|
| `buildItemList` | `ItemList` |
|
|
199
437
|
|
|
438
|
+
### Nested values
|
|
439
|
+
|
|
440
|
+
Building blocks for properties like `offers`, `hasCourseInstance`, `location`, or `author`. See [Nesting entities](#nesting-entities).
|
|
441
|
+
|
|
442
|
+
| Builder | Schema.org type | Typical parent properties |
|
|
443
|
+
|---|---|---|
|
|
444
|
+
| `buildOffer` | `Offer` | `offers` on Product, Course, Event, SoftwareApplication |
|
|
445
|
+
| `buildAggregateOffer` | `AggregateOffer` | `offers` with a price range (`lowPrice`, `highPrice`, `offerCount`) |
|
|
446
|
+
| `buildMonetaryAmount` | `MonetaryAmount` | `baseSalary` on JobPosting |
|
|
447
|
+
| `buildQuantitativeValue` | `QuantitativeValue` | `value` in MonetaryAmount, product dimensions |
|
|
448
|
+
| `buildBrand` | `Brand` | `brand` on Product |
|
|
449
|
+
| `buildCourseInstance` | `CourseInstance` | `hasCourseInstance` on Course |
|
|
450
|
+
| `buildSchedule` | `Schedule` | `courseSchedule`, `eventSchedule` |
|
|
451
|
+
| `buildPlace` | `Place` | `location` on Event, `jobLocation` on JobPosting |
|
|
452
|
+
| `buildPostalAddress` | `PostalAddress` | `address` on Place, Organization, LocalBusiness |
|
|
453
|
+
| `buildGeoCoordinates` | `GeoCoordinates` | `geo` on Place, LocalBusiness |
|
|
454
|
+
| `buildPerson` | `Person` | `author`, `actor`, `director`, `instructor` on CourseInstance |
|
|
455
|
+
| `buildOrganization` | `Organization` | `hiringOrganization`, `organizer`, `productionCompany` |
|
|
456
|
+
| `buildHowToStep` | `HowToStep` | `recipeInstructions` on Recipe |
|
|
457
|
+
| `buildNutritionInformation` | `NutritionInformation` | `nutrition` on Recipe |
|
|
458
|
+
| `buildOfferShippingDetails` | `OfferShippingDetails` | `shippingDetails` on Offer |
|
|
459
|
+
| `buildMerchantReturnPolicy` | `MerchantReturnPolicy` | `hasMerchantReturnPolicy` on Offer or Organization |
|
|
460
|
+
|
|
461
|
+
`buildPerson` and `buildOrganization` are for other people and organizations on the page. For the site owner, use `identity` on `buildSchemaMarkup` and link to it with [`identityRef`](#identityref).
|
|
462
|
+
|
|
463
|
+
**Product merchant listing example:**
|
|
464
|
+
|
|
465
|
+
```ts
|
|
466
|
+
buildProduct({
|
|
467
|
+
name: product.title,
|
|
468
|
+
image: buildImageObject(product.imageUrl),
|
|
469
|
+
offers: [
|
|
470
|
+
buildOffer({
|
|
471
|
+
price: product.price,
|
|
472
|
+
priceCurrency: "USD",
|
|
473
|
+
availability: "InStock",
|
|
474
|
+
shippingDetails: buildOfferShippingDetails({
|
|
475
|
+
shippingRate: buildMonetaryAmount({ value: 0, currency: "USD" }),
|
|
476
|
+
shippingDestination: { "@type": "DefinedRegion", addressCountry: "US" },
|
|
477
|
+
deliveryTime: {
|
|
478
|
+
"@type": "ShippingDeliveryTime",
|
|
479
|
+
handlingTime: { "@type": "QuantitativeValue", minValue: 0, maxValue: 1, unitCode: "DAY" },
|
|
480
|
+
transitTime: { "@type": "QuantitativeValue", minValue: 1, maxValue: 5, unitCode: "DAY" },
|
|
481
|
+
},
|
|
482
|
+
}),
|
|
483
|
+
hasMerchantReturnPolicy: buildMerchantReturnPolicy({
|
|
484
|
+
applicableCountry: "US",
|
|
485
|
+
returnPolicyCategory: "MerchantReturnFiniteReturnWindow",
|
|
486
|
+
merchantReturnDays: 30,
|
|
487
|
+
returnMethod: "ReturnByMail",
|
|
488
|
+
returnFees: "FreeReturn",
|
|
489
|
+
}),
|
|
490
|
+
}),
|
|
491
|
+
],
|
|
492
|
+
});
|
|
493
|
+
```
|
|
494
|
+
|
|
200
495
|
See Google's [structured data gallery](https://developers.google.com/search/docs/appearance/structured-data/search-gallery) for which schema types are eligible for rich results.
|
|
201
496
|
|
|
497
|
+
> Google no longer lists FAQ or Course info rich results. `buildFAQPage`, and `offers` / `hasCourseInstance` on a Course, still produce valid Schema.org markup but won't earn a rich result. Google's Course list only needs `name`, `description`, and `provider` on each `Course`, plus an `ItemList` for the carousel.
|
|
498
|
+
|
|
202
499
|
---
|
|
203
500
|
|
|
204
501
|
## With Sanity
|
|
@@ -259,6 +556,10 @@ Pick the `build*` helper that matches your document type (`buildProduct`, `build
|
|
|
259
556
|
|
|
260
557
|
- `buildSchemaMarkup` — builds the page-level JSON-LD graph
|
|
261
558
|
- `build*` schema builders — typed builders for individual Schema.org nodes
|
|
559
|
+
- `identityRef` — reference to the site identity, resolved by `buildSchemaMarkup`
|
|
560
|
+
- `toIsoDuration`, `toIsoDate`, `DurationParts` — ISO 8601 duration and date helpers
|
|
561
|
+
- `toAbsoluteUrl` — resolves slugs and relative paths against `siteUrl`
|
|
562
|
+
- `buildImageObject`, `ImageInput` — `ImageObject` helper
|
|
262
563
|
- `BuilderInput` — input helper type for builder functions
|
|
263
564
|
- `BuildSchemaMarkupInput` — input type for `buildSchemaMarkup`
|
|
264
565
|
- `Identity`, `PersonIdentity`, `OrganizationIdentity`, `LocalBusinessIdentity` — supported site identity roots
|
package/dist/build.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type BuildSchemaMarkupInput = {
|
|
|
9
9
|
pageUrl: string;
|
|
10
10
|
pageTitle: string;
|
|
11
11
|
pageDescription?: string;
|
|
12
|
+
/** BCP 47 language tag for the page content, e.g. `"fr"` or `"fr-CA"`. */
|
|
13
|
+
inLanguage?: string;
|
|
12
14
|
breadcrumb?: WithContext<BreadcrumbList>;
|
|
13
15
|
mainEntity?: Thing | SchemaNode;
|
|
14
16
|
};
|
package/dist/builders/index.d.ts
CHANGED
|
@@ -1,25 +1,41 @@
|
|
|
1
1
|
export * from "./about-page";
|
|
2
|
+
export * from "./aggregate-offer";
|
|
2
3
|
export * from "./aggregate-rating";
|
|
3
4
|
export * from "./answer";
|
|
4
5
|
export * from "./article";
|
|
6
|
+
export * from "./brand";
|
|
5
7
|
export * from "./breadcrumb-list";
|
|
6
8
|
export * from "./comment";
|
|
7
9
|
export * from "./contact-page";
|
|
8
10
|
export * from "./course";
|
|
11
|
+
export * from "./course-instance";
|
|
9
12
|
export * from "./dataset";
|
|
10
13
|
export * from "./discussion-forum-posting";
|
|
11
14
|
export * from "./event";
|
|
12
15
|
export * from "./faq";
|
|
16
|
+
export * from "./geo-coordinates";
|
|
17
|
+
export * from "./how-to-step";
|
|
13
18
|
export * from "./item-list";
|
|
14
19
|
export * from "./job-posting";
|
|
15
20
|
export * from "./local-business";
|
|
21
|
+
export * from "./merchant-return-policy";
|
|
22
|
+
export * from "./monetary-amount";
|
|
16
23
|
export * from "./movie";
|
|
24
|
+
export * from "./nutrition-information";
|
|
25
|
+
export * from "./offer";
|
|
26
|
+
export * from "./offer-shipping-details";
|
|
27
|
+
export * from "./organization";
|
|
28
|
+
export * from "./person";
|
|
29
|
+
export * from "./place";
|
|
30
|
+
export * from "./postal-address";
|
|
17
31
|
export * from "./product";
|
|
18
32
|
export * from "./profile-page";
|
|
19
33
|
export * from "./qa-page";
|
|
34
|
+
export * from "./quantitative-value";
|
|
20
35
|
export * from "./question";
|
|
21
36
|
export * from "./recipe";
|
|
22
37
|
export * from "./review";
|
|
38
|
+
export * from "./schedule";
|
|
23
39
|
export * from "./software-application";
|
|
24
40
|
export * from "./vacation-rental";
|
|
25
41
|
export * from "./video-object";
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,7 @@ export type { BuildSchemaMarkupInput, Identity, LocalBusinessIdentity, Organizat
|
|
|
2
2
|
export { buildSchemaMarkup } from "./build";
|
|
3
3
|
export * from "./builders";
|
|
4
4
|
export type { BuilderInput } from "./define-builder";
|
|
5
|
+
export { identityRef } from "./identity-ref";
|
|
6
|
+
export { type DurationParts, toIsoDate, toIsoDuration } from "./utils/datetime";
|
|
7
|
+
export { buildImageObject, type ImageInput } from "./utils/image";
|
|
8
|
+
export { toAbsoluteUrl } from "./utils/url";
|
package/dist/index.js
CHANGED
|
@@ -1,237 +1,3 @@
|
|
|
1
|
-
// src/builders/fragments.ts
|
|
2
|
-
function normalizeId(name) {
|
|
3
|
-
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
4
|
-
}
|
|
5
|
-
function createSchemaId({
|
|
6
|
-
kind,
|
|
7
|
-
name,
|
|
8
|
-
baseUrl = "",
|
|
9
|
-
explicitId
|
|
10
|
-
}) {
|
|
11
|
-
if (explicitId) {
|
|
12
|
-
return explicitId.startsWith("http") ? explicitId : `${baseUrl}${explicitId}`;
|
|
13
|
-
}
|
|
14
|
-
return `${baseUrl}#${kind}-${normalizeId(name)}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/utils/image.ts
|
|
18
|
-
function buildImageObject(input) {
|
|
19
|
-
if (!input) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (typeof input === "string") {
|
|
23
|
-
return {
|
|
24
|
-
"@type": "ImageObject",
|
|
25
|
-
url: input
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
return {
|
|
29
|
-
"@type": "ImageObject",
|
|
30
|
-
url: input.url,
|
|
31
|
-
width: input.width,
|
|
32
|
-
height: input.height
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// src/build.ts
|
|
37
|
-
var TYPE_PRIORITY = [
|
|
38
|
-
"Organization",
|
|
39
|
-
"Person",
|
|
40
|
-
"LocalBusiness",
|
|
41
|
-
"WebSite",
|
|
42
|
-
"WebPage",
|
|
43
|
-
"ProfilePage",
|
|
44
|
-
"QAPage",
|
|
45
|
-
"BreadcrumbList",
|
|
46
|
-
"Article",
|
|
47
|
-
"Course",
|
|
48
|
-
"Dataset",
|
|
49
|
-
"DiscussionForumPosting",
|
|
50
|
-
"JobPosting",
|
|
51
|
-
"Movie",
|
|
52
|
-
"Product",
|
|
53
|
-
"Recipe",
|
|
54
|
-
"SoftwareApplication",
|
|
55
|
-
"VacationRental",
|
|
56
|
-
"VideoObject",
|
|
57
|
-
"Event",
|
|
58
|
-
"ItemList",
|
|
59
|
-
"Question",
|
|
60
|
-
"Answer",
|
|
61
|
-
"Review",
|
|
62
|
-
"Comment",
|
|
63
|
-
"AggregateRating"
|
|
64
|
-
];
|
|
65
|
-
var typeWeight = new Map(TYPE_PRIORITY.map((type, index) => [type, index]));
|
|
66
|
-
var hasObjectShape = (value) => {
|
|
67
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
68
|
-
};
|
|
69
|
-
var hasType = (value) => {
|
|
70
|
-
return typeof value["@type"] === "string";
|
|
71
|
-
};
|
|
72
|
-
var hasId = (value) => {
|
|
73
|
-
return typeof value["@id"] === "string" && value["@id"].length > 0;
|
|
74
|
-
};
|
|
75
|
-
var ensureContext = (node) => {
|
|
76
|
-
if (hasType(node) && node["@context"] === undefined) {
|
|
77
|
-
return {
|
|
78
|
-
"@context": "https://schema.org",
|
|
79
|
-
...node
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return node;
|
|
83
|
-
};
|
|
84
|
-
var assembleNodes = (nodes) => {
|
|
85
|
-
const collected = [];
|
|
86
|
-
const seenIds = new Set;
|
|
87
|
-
const processingIds = new Set;
|
|
88
|
-
let orderCounter = 0;
|
|
89
|
-
const addNode = (node) => {
|
|
90
|
-
const normalized = ensureContext(node);
|
|
91
|
-
if (hasId(normalized)) {
|
|
92
|
-
if (seenIds.has(normalized["@id"]))
|
|
93
|
-
return;
|
|
94
|
-
seenIds.add(normalized["@id"]);
|
|
95
|
-
}
|
|
96
|
-
collected.push({
|
|
97
|
-
node: normalized,
|
|
98
|
-
order: orderCounter++
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
const processValue = (value, isRoot = false) => {
|
|
102
|
-
if (Array.isArray(value)) {
|
|
103
|
-
return value.map((item) => processValue(item, false));
|
|
104
|
-
}
|
|
105
|
-
if (!hasObjectShape(value))
|
|
106
|
-
return value;
|
|
107
|
-
if (!isRoot && hasType(value) && hasId(value)) {
|
|
108
|
-
registerEntity(value);
|
|
109
|
-
return { "@id": value["@id"] };
|
|
110
|
-
}
|
|
111
|
-
const output = {};
|
|
112
|
-
for (const [key, child] of Object.entries(value)) {
|
|
113
|
-
output[key] = processValue(child, false);
|
|
114
|
-
}
|
|
115
|
-
return output;
|
|
116
|
-
};
|
|
117
|
-
const registerEntity = (entity) => {
|
|
118
|
-
const id = entity["@id"];
|
|
119
|
-
if (seenIds.has(id) || processingIds.has(id))
|
|
120
|
-
return;
|
|
121
|
-
processingIds.add(id);
|
|
122
|
-
const processedEntity = processValue(entity, true);
|
|
123
|
-
if (hasObjectShape(processedEntity)) {
|
|
124
|
-
addNode(processedEntity);
|
|
125
|
-
}
|
|
126
|
-
processingIds.delete(id);
|
|
127
|
-
};
|
|
128
|
-
for (const node of nodes) {
|
|
129
|
-
if (!node)
|
|
130
|
-
continue;
|
|
131
|
-
const processed = processValue(node, true);
|
|
132
|
-
if (!hasObjectShape(processed))
|
|
133
|
-
continue;
|
|
134
|
-
addNode(processed);
|
|
135
|
-
}
|
|
136
|
-
const ranked = collected.sort((a, b) => {
|
|
137
|
-
const aType = hasType(a.node) ? a.node["@type"] : "";
|
|
138
|
-
const bType = hasType(b.node) ? b.node["@type"] : "";
|
|
139
|
-
const aWeight = typeWeight.get(aType) ?? Number.MAX_SAFE_INTEGER;
|
|
140
|
-
const bWeight = typeWeight.get(bType) ?? Number.MAX_SAFE_INTEGER;
|
|
141
|
-
if (aWeight !== bWeight)
|
|
142
|
-
return aWeight - bWeight;
|
|
143
|
-
return a.order - b.order;
|
|
144
|
-
});
|
|
145
|
-
return ranked.map(({ node }) => JSON.stringify(node));
|
|
146
|
-
};
|
|
147
|
-
var buildIdentityNodes = (identity, siteUrl) => {
|
|
148
|
-
switch (identity.type) {
|
|
149
|
-
case "person": {
|
|
150
|
-
const id = createSchemaId({
|
|
151
|
-
kind: "person",
|
|
152
|
-
name: identity.name,
|
|
153
|
-
baseUrl: siteUrl
|
|
154
|
-
});
|
|
155
|
-
return {
|
|
156
|
-
node: {
|
|
157
|
-
"@type": "Person",
|
|
158
|
-
"@id": id,
|
|
159
|
-
name: identity.name,
|
|
160
|
-
description: identity.description,
|
|
161
|
-
image: buildImageObject(identity.image),
|
|
162
|
-
sameAs: identity.sameAs,
|
|
163
|
-
url: siteUrl
|
|
164
|
-
},
|
|
165
|
-
ref: { "@id": id }
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
case "organization": {
|
|
169
|
-
const id = createSchemaId({
|
|
170
|
-
kind: "organization",
|
|
171
|
-
name: identity.name,
|
|
172
|
-
baseUrl: siteUrl
|
|
173
|
-
});
|
|
174
|
-
return {
|
|
175
|
-
node: {
|
|
176
|
-
"@type": "Organization",
|
|
177
|
-
"@id": id,
|
|
178
|
-
name: identity.name,
|
|
179
|
-
description: identity.description,
|
|
180
|
-
logo: buildImageObject(identity.logo),
|
|
181
|
-
sameAs: identity.sameAs,
|
|
182
|
-
url: siteUrl
|
|
183
|
-
},
|
|
184
|
-
ref: { "@id": id }
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
case "localBusiness": {
|
|
188
|
-
const id = createSchemaId({
|
|
189
|
-
kind: "local-business",
|
|
190
|
-
name: identity.name,
|
|
191
|
-
baseUrl: siteUrl
|
|
192
|
-
});
|
|
193
|
-
return {
|
|
194
|
-
node: {
|
|
195
|
-
"@type": "LocalBusiness",
|
|
196
|
-
"@id": id,
|
|
197
|
-
name: identity.name,
|
|
198
|
-
description: identity.description,
|
|
199
|
-
logo: buildImageObject(identity.logo),
|
|
200
|
-
telephone: identity.phone,
|
|
201
|
-
email: identity.email,
|
|
202
|
-
address: identity.address,
|
|
203
|
-
openingHoursSpecification: identity.openingHours,
|
|
204
|
-
sameAs: identity.sameAs,
|
|
205
|
-
url: siteUrl
|
|
206
|
-
},
|
|
207
|
-
ref: { "@id": id }
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
var buildSchemaMarkup = (input) => {
|
|
213
|
-
const { node: identityNode, ref: identityRef } = buildIdentityNodes(input.identity, input.siteUrl);
|
|
214
|
-
const websiteId = `${input.siteUrl}#website`;
|
|
215
|
-
const websiteNode = {
|
|
216
|
-
"@type": "WebSite",
|
|
217
|
-
"@id": websiteId,
|
|
218
|
-
name: input.siteName,
|
|
219
|
-
url: input.siteUrl,
|
|
220
|
-
description: input.siteDescription,
|
|
221
|
-
publisher: identityRef
|
|
222
|
-
};
|
|
223
|
-
const webpageNode = {
|
|
224
|
-
"@type": "WebPage",
|
|
225
|
-
"@id": `${input.pageUrl}#webpage`,
|
|
226
|
-
url: input.pageUrl,
|
|
227
|
-
name: input.pageTitle,
|
|
228
|
-
description: input.pageDescription,
|
|
229
|
-
isPartOf: { "@id": websiteId },
|
|
230
|
-
breadcrumb: input.breadcrumb,
|
|
231
|
-
mainEntity: input.mainEntity
|
|
232
|
-
};
|
|
233
|
-
return assembleNodes([identityNode, websiteNode, webpageNode]);
|
|
234
|
-
};
|
|
235
1
|
// src/define-builder.ts
|
|
236
2
|
function defineBuilder(type) {
|
|
237
3
|
return (input) => ({
|
|
@@ -243,12 +9,22 @@ function defineBuilder(type) {
|
|
|
243
9
|
|
|
244
10
|
// src/builders/about-page.ts
|
|
245
11
|
var buildAboutPage = defineBuilder("AboutPage");
|
|
12
|
+
|
|
13
|
+
// src/builders/aggregate-offer.ts
|
|
14
|
+
var buildAggregateOffer = defineBuilder("AggregateOffer");
|
|
15
|
+
|
|
246
16
|
// src/builders/aggregate-rating.ts
|
|
247
17
|
var buildAggregateRating = defineBuilder("AggregateRating");
|
|
18
|
+
|
|
248
19
|
// src/builders/answer.ts
|
|
249
20
|
var buildAnswer = defineBuilder("Answer");
|
|
21
|
+
|
|
250
22
|
// src/builders/article.ts
|
|
251
23
|
var buildArticle = defineBuilder("Article");
|
|
24
|
+
|
|
25
|
+
// src/builders/brand.ts
|
|
26
|
+
var buildBrand = defineBuilder("Brand");
|
|
27
|
+
|
|
252
28
|
// src/builders/internal/slug-to-title.ts
|
|
253
29
|
function slugToTitle(segment) {
|
|
254
30
|
const decoded = decodeURIComponent(segment || "");
|
|
@@ -304,80 +80,165 @@ function buildBreadcrumbListSchema({
|
|
|
304
80
|
itemListElement: toListItems(finalItems)
|
|
305
81
|
};
|
|
306
82
|
}
|
|
83
|
+
|
|
307
84
|
// src/builders/comment.ts
|
|
308
85
|
var buildComment = defineBuilder("Comment");
|
|
86
|
+
|
|
309
87
|
// src/builders/contact-page.ts
|
|
310
88
|
var buildContactPage = defineBuilder("ContactPage");
|
|
89
|
+
|
|
311
90
|
// src/builders/course.ts
|
|
312
91
|
var buildCourse = defineBuilder("Course");
|
|
92
|
+
|
|
93
|
+
// src/builders/course-instance.ts
|
|
94
|
+
var buildCourseInstance = defineBuilder("CourseInstance");
|
|
95
|
+
|
|
313
96
|
// src/builders/dataset.ts
|
|
314
97
|
var buildDataset = defineBuilder("Dataset");
|
|
98
|
+
|
|
315
99
|
// src/builders/discussion-forum-posting.ts
|
|
316
100
|
var buildDiscussionForumPosting = defineBuilder("DiscussionForumPosting");
|
|
101
|
+
|
|
317
102
|
// src/builders/event.ts
|
|
318
103
|
var buildEvent = defineBuilder("Event");
|
|
104
|
+
|
|
319
105
|
// src/builders/faq.ts
|
|
320
106
|
var buildFAQPage = defineBuilder("FAQPage");
|
|
107
|
+
|
|
108
|
+
// src/builders/geo-coordinates.ts
|
|
109
|
+
var buildGeoCoordinates = defineBuilder("GeoCoordinates");
|
|
110
|
+
|
|
111
|
+
// src/builders/how-to-step.ts
|
|
112
|
+
var buildHowToStep = defineBuilder("HowToStep");
|
|
113
|
+
|
|
321
114
|
// src/builders/item-list.ts
|
|
322
115
|
var buildItemList = defineBuilder("ItemList");
|
|
116
|
+
|
|
323
117
|
// src/builders/job-posting.ts
|
|
324
118
|
var buildJobPosting = defineBuilder("JobPosting");
|
|
119
|
+
|
|
325
120
|
// src/builders/local-business.ts
|
|
326
121
|
var buildLocalBusiness = defineBuilder("LocalBusiness");
|
|
122
|
+
|
|
123
|
+
// src/builders/merchant-return-policy.ts
|
|
124
|
+
var buildMerchantReturnPolicy = defineBuilder("MerchantReturnPolicy");
|
|
125
|
+
|
|
126
|
+
// src/builders/monetary-amount.ts
|
|
127
|
+
var buildMonetaryAmount = defineBuilder("MonetaryAmount");
|
|
128
|
+
|
|
327
129
|
// src/builders/movie.ts
|
|
328
130
|
var buildMovie = defineBuilder("Movie");
|
|
131
|
+
|
|
132
|
+
// src/builders/nutrition-information.ts
|
|
133
|
+
var buildNutritionInformation = defineBuilder("NutritionInformation");
|
|
134
|
+
|
|
135
|
+
// src/builders/offer.ts
|
|
136
|
+
var buildOffer = defineBuilder("Offer");
|
|
137
|
+
|
|
138
|
+
// src/builders/offer-shipping-details.ts
|
|
139
|
+
var buildOfferShippingDetails = defineBuilder("OfferShippingDetails");
|
|
140
|
+
|
|
141
|
+
// src/builders/organization.ts
|
|
142
|
+
var buildOrganization = defineBuilder("Organization");
|
|
143
|
+
|
|
144
|
+
// src/builders/person.ts
|
|
145
|
+
var buildPerson = defineBuilder("Person");
|
|
146
|
+
|
|
147
|
+
// src/builders/place.ts
|
|
148
|
+
var buildPlace = defineBuilder("Place");
|
|
149
|
+
|
|
150
|
+
// src/builders/postal-address.ts
|
|
151
|
+
var buildPostalAddress = defineBuilder("PostalAddress");
|
|
152
|
+
|
|
329
153
|
// src/builders/product.ts
|
|
330
154
|
var buildProduct = defineBuilder("Product");
|
|
155
|
+
|
|
331
156
|
// src/builders/profile-page.ts
|
|
332
157
|
var buildProfilePage = defineBuilder("ProfilePage");
|
|
158
|
+
|
|
333
159
|
// src/builders/qa-page.ts
|
|
334
160
|
var buildQAPage = defineBuilder("QAPage");
|
|
161
|
+
|
|
162
|
+
// src/builders/quantitative-value.ts
|
|
163
|
+
var buildQuantitativeValue = defineBuilder("QuantitativeValue");
|
|
164
|
+
|
|
335
165
|
// src/builders/question.ts
|
|
336
166
|
var buildQuestion = defineBuilder("Question");
|
|
167
|
+
|
|
337
168
|
// src/builders/recipe.ts
|
|
338
169
|
var buildRecipe = defineBuilder("Recipe");
|
|
170
|
+
|
|
339
171
|
// src/builders/review.ts
|
|
340
172
|
var buildReview = defineBuilder("Review");
|
|
173
|
+
|
|
174
|
+
// src/builders/schedule.ts
|
|
175
|
+
var buildSchedule = defineBuilder("Schedule");
|
|
176
|
+
|
|
341
177
|
// src/builders/software-application.ts
|
|
342
178
|
var buildSoftwareApplication = defineBuilder("SoftwareApplication");
|
|
179
|
+
|
|
343
180
|
// src/builders/vacation-rental.ts
|
|
344
181
|
var buildVacationRental = defineBuilder("VacationRental");
|
|
182
|
+
|
|
345
183
|
// src/builders/video-object.ts
|
|
346
184
|
var buildVideoObject = defineBuilder("VideoObject");
|
|
185
|
+
|
|
347
186
|
// src/builders/webpage.ts
|
|
348
187
|
var buildWebPage = defineBuilder("WebPage");
|
|
188
|
+
|
|
349
189
|
// src/builders/website.ts
|
|
350
190
|
var buildWebSite = defineBuilder("WebSite");
|
|
351
191
|
export {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
buildVideoObject,
|
|
355
|
-
buildVacationRental,
|
|
356
|
-
buildSoftwareApplication,
|
|
357
|
-
buildSchemaMarkup,
|
|
358
|
-
buildReview,
|
|
359
|
-
buildRecipe,
|
|
360
|
-
buildQuestion,
|
|
361
|
-
buildQAPage,
|
|
362
|
-
buildProfilePage,
|
|
363
|
-
buildProduct,
|
|
364
|
-
buildMovie,
|
|
365
|
-
buildLocalBusiness,
|
|
366
|
-
buildJobPosting,
|
|
367
|
-
buildItemList,
|
|
368
|
-
buildFAQPage,
|
|
369
|
-
buildEvent,
|
|
370
|
-
buildDiscussionForumPosting,
|
|
371
|
-
buildDataset,
|
|
372
|
-
buildCourse,
|
|
373
|
-
buildContactPage,
|
|
374
|
-
buildComment,
|
|
375
|
-
buildBreadcrumbListSchema,
|
|
376
|
-
buildArticle,
|
|
377
|
-
buildAnswer,
|
|
192
|
+
buildAboutPage,
|
|
193
|
+
buildAggregateOffer,
|
|
378
194
|
buildAggregateRating,
|
|
379
|
-
|
|
195
|
+
buildAnswer,
|
|
196
|
+
buildArticle,
|
|
197
|
+
buildBrand,
|
|
198
|
+
buildBreadcrumbListSchema,
|
|
199
|
+
buildComment,
|
|
200
|
+
buildContactPage,
|
|
201
|
+
buildCourse,
|
|
202
|
+
buildCourseInstance,
|
|
203
|
+
buildDataset,
|
|
204
|
+
buildDiscussionForumPosting,
|
|
205
|
+
buildEvent,
|
|
206
|
+
buildFAQPage,
|
|
207
|
+
buildGeoCoordinates,
|
|
208
|
+
buildHowToStep,
|
|
209
|
+
buildImageObject,
|
|
210
|
+
buildItemList,
|
|
211
|
+
buildJobPosting,
|
|
212
|
+
buildLocalBusiness,
|
|
213
|
+
buildMerchantReturnPolicy,
|
|
214
|
+
buildMonetaryAmount,
|
|
215
|
+
buildMovie,
|
|
216
|
+
buildNutritionInformation,
|
|
217
|
+
buildOffer,
|
|
218
|
+
buildOfferShippingDetails,
|
|
219
|
+
buildOrganization,
|
|
220
|
+
buildPerson,
|
|
221
|
+
buildPlace,
|
|
222
|
+
buildPostalAddress,
|
|
223
|
+
buildProduct,
|
|
224
|
+
buildProfilePage,
|
|
225
|
+
buildQAPage,
|
|
226
|
+
buildQuantitativeValue,
|
|
227
|
+
buildQuestion,
|
|
228
|
+
buildRecipe,
|
|
229
|
+
buildReview,
|
|
230
|
+
buildSchedule,
|
|
231
|
+
buildSchemaMarkup,
|
|
232
|
+
buildSoftwareApplication,
|
|
233
|
+
buildVacationRental,
|
|
234
|
+
buildVideoObject,
|
|
235
|
+
buildWebPage,
|
|
236
|
+
buildWebSite,
|
|
237
|
+
identityRef,
|
|
238
|
+
toAbsoluteUrl,
|
|
239
|
+
toIsoDate,
|
|
240
|
+
toIsoDuration
|
|
380
241
|
};
|
|
381
242
|
|
|
382
|
-
//# debugId=
|
|
243
|
+
//# debugId=AC1EB3C8028F80A664756E2164756E21
|
|
383
244
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,41 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
3
|
+
"sources": ["../src/define-builder.ts", "../src/builders/about-page.ts", "../src/builders/aggregate-offer.ts", "../src/builders/aggregate-rating.ts", "../src/builders/answer.ts", "../src/builders/article.ts", "../src/builders/brand.ts", "../src/builders/internal/slug-to-title.ts", "../src/builders/breadcrumb-list.ts", "../src/builders/comment.ts", "../src/builders/contact-page.ts", "../src/builders/course.ts", "../src/builders/course-instance.ts", "../src/builders/dataset.ts", "../src/builders/discussion-forum-posting.ts", "../src/builders/event.ts", "../src/builders/faq.ts", "../src/builders/geo-coordinates.ts", "../src/builders/how-to-step.ts", "../src/builders/item-list.ts", "../src/builders/job-posting.ts", "../src/builders/local-business.ts", "../src/builders/merchant-return-policy.ts", "../src/builders/monetary-amount.ts", "../src/builders/movie.ts", "../src/builders/nutrition-information.ts", "../src/builders/offer.ts", "../src/builders/offer-shipping-details.ts", "../src/builders/organization.ts", "../src/builders/person.ts", "../src/builders/place.ts", "../src/builders/postal-address.ts", "../src/builders/product.ts", "../src/builders/profile-page.ts", "../src/builders/qa-page.ts", "../src/builders/quantitative-value.ts", "../src/builders/question.ts", "../src/builders/recipe.ts", "../src/builders/review.ts", "../src/builders/schedule.ts", "../src/builders/software-application.ts", "../src/builders/vacation-rental.ts", "../src/builders/video-object.ts", "../src/builders/webpage.ts", "../src/builders/website.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"type IdReference = { \"@id\": string };\n\ntype SchemaIdOptions = {\n\tkind: string;\n\tname: string;\n\tbaseUrl?: string;\n\texplicitId?: string;\n};\n\nexport function normalizeId(name: string): string {\n\treturn name\n\t\t.toLowerCase()\n\t\t.replace(/[^a-z0-9]+/g, \"-\")\n\t\t.replace(/^-|-$/g, \"\");\n}\n\nexport function createSchemaId({\n\tkind,\n\tname,\n\tbaseUrl = \"\",\n\texplicitId,\n}: SchemaIdOptions): string {\n\tif (explicitId) {\n\t\treturn explicitId.startsWith(\"http\")\n\t\t\t? explicitId\n\t\t\t: `${baseUrl}${explicitId}`;\n\t}\n\n\treturn `${baseUrl}#${kind}-${normalizeId(name)}`;\n}\n\nexport function asIdReference(id: string): IdReference {\n\treturn { \"@id\": id };\n}\n",
|
|
6
|
-
"type ImageObjectInput = {\n\turl: string;\n\twidth?: number;\n\theight?: number;\n};\n\nexport type ImageInput = string | ImageObjectInput;\n\nexport function buildImageObject(\n\tinput?: ImageInput,\n): Record<string, unknown> | undefined {\n\tif (!input) {\n\t\treturn undefined;\n\t}\n\n\tif (typeof input === \"string\") {\n\t\treturn {\n\t\t\t\"@type\": \"ImageObject\",\n\t\t\turl: input,\n\t\t};\n\t}\n\n\treturn {\n\t\t\"@type\": \"ImageObject\",\n\t\turl: input.url,\n\t\twidth: input.width,\n\t\theight: input.height,\n\t};\n}\n",
|
|
7
|
-
"import type {\n\tBreadcrumbList,\n\tOpeningHoursSpecification,\n\tPostalAddress,\n\tThing,\n\tWithContext,\n} from \"schema-dts\";\nimport { createSchemaId } from \"./builders/fragments\";\nimport { buildImageObject, type ImageInput } from \"./utils/image\";\n\ntype SchemaNode = Record<string, unknown>;\n\nexport type BuildSchemaMarkupInput = {\n\tidentity: Identity;\n\tsiteUrl: string;\n\tsiteName: string;\n\tsiteDescription?: string;\n\tpageUrl: string;\n\tpageTitle: string;\n\tpageDescription?: string;\n\tbreadcrumb?: WithContext<BreadcrumbList>;\n\tmainEntity?: Thing | SchemaNode;\n};\n\nexport type PersonIdentity = {\n\ttype: \"person\";\n\tname: string;\n\tdescription?: string;\n\timage?: ImageInput;\n\tsameAs?: string[];\n};\n\nexport type OrganizationIdentity = {\n\ttype: \"organization\";\n\tname: string;\n\tdescription?: string;\n\tlogo?: ImageInput;\n\tsameAs?: string[];\n};\n\nexport type LocalBusinessIdentity = {\n\ttype: \"localBusiness\";\n\tname: string;\n\tdescription?: string;\n\tlogo?: ImageInput;\n\tphone?: string;\n\temail?: string;\n\taddress?: PostalAddress;\n\topeningHours?: OpeningHoursSpecification[];\n\tsameAs?: string[];\n};\n\nexport type Identity =\n\t| PersonIdentity\n\t| OrganizationIdentity\n\t| LocalBusinessIdentity;\n\nconst TYPE_PRIORITY = [\n\t\"Organization\",\n\t\"Person\",\n\t\"LocalBusiness\",\n\t\"WebSite\",\n\t\"WebPage\",\n\t\"ProfilePage\",\n\t\"QAPage\",\n\t\"BreadcrumbList\",\n\t\"Article\",\n\t\"Course\",\n\t\"Dataset\",\n\t\"DiscussionForumPosting\",\n\t\"JobPosting\",\n\t\"Movie\",\n\t\"Product\",\n\t\"Recipe\",\n\t\"SoftwareApplication\",\n\t\"VacationRental\",\n\t\"VideoObject\",\n\t\"Event\",\n\t\"ItemList\",\n\t\"Question\",\n\t\"Answer\",\n\t\"Review\",\n\t\"Comment\",\n\t\"AggregateRating\",\n] as const;\n\nconst typeWeight = new Map<string, number>(\n\tTYPE_PRIORITY.map((type, index) => [type, index]),\n);\n\nconst hasObjectShape = (value: unknown): value is SchemaNode => {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n};\n\nconst hasType = (value: SchemaNode): value is SchemaNode & { \"@type\": string } => {\n\treturn typeof value[\"@type\"] === \"string\";\n};\n\nconst hasId = (value: SchemaNode): value is SchemaNode & { \"@id\": string } => {\n\treturn typeof value[\"@id\"] === \"string\" && value[\"@id\"].length > 0;\n};\n\nconst ensureContext = (node: SchemaNode): SchemaNode => {\n\tif (hasType(node) && node[\"@context\"] === undefined) {\n\t\treturn {\n\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t...node,\n\t\t};\n\t}\n\n\treturn node;\n};\n\ntype RankedNode = {\n\tnode: SchemaNode;\n\torder: number;\n};\n\nconst assembleNodes = (nodes: Array<Thing | SchemaNode | undefined>): string[] => {\n\tconst collected: RankedNode[] = [];\n\tconst seenIds = new Set<string>();\n\tconst processingIds = new Set<string>();\n\tlet orderCounter = 0;\n\n\tconst addNode = (node: SchemaNode) => {\n\t\tconst normalized = ensureContext(node);\n\t\tif (hasId(normalized)) {\n\t\t\tif (seenIds.has(normalized[\"@id\"])) return;\n\t\t\tseenIds.add(normalized[\"@id\"]);\n\t\t}\n\n\t\tcollected.push({\n\t\t\tnode: normalized,\n\t\t\torder: orderCounter++,\n\t\t});\n\t};\n\n\tconst processValue = (value: unknown, isRoot = false): unknown => {\n\t\tif (Array.isArray(value)) {\n\t\t\treturn value.map((item) => processValue(item, false));\n\t\t}\n\n\t\tif (!hasObjectShape(value)) return value;\n\n\t\tif (!isRoot && hasType(value) && hasId(value)) {\n\t\t\tregisterEntity(value);\n\t\t\treturn { \"@id\": value[\"@id\"] };\n\t\t}\n\n\t\tconst output: SchemaNode = {};\n\t\tfor (const [key, child] of Object.entries(value)) {\n\t\t\toutput[key] = processValue(child, false);\n\t\t}\n\t\treturn output;\n\t};\n\n\tconst registerEntity = (entity: SchemaNode & { \"@id\": string }) => {\n\t\tconst id = entity[\"@id\"];\n\t\tif (seenIds.has(id) || processingIds.has(id)) return;\n\n\t\tprocessingIds.add(id);\n\t\tconst processedEntity = processValue(entity, true);\n\t\tif (hasObjectShape(processedEntity)) {\n\t\t\taddNode(processedEntity);\n\t\t}\n\t\tprocessingIds.delete(id);\n\t};\n\n\tfor (const node of nodes) {\n\t\tif (!node) continue;\n\t\tconst processed = processValue(node, true);\n\t\tif (!hasObjectShape(processed)) continue;\n\t\taddNode(processed);\n\t}\n\n\tconst ranked = collected.sort((a, b) => {\n\t\tconst aType = hasType(a.node) ? a.node[\"@type\"] : \"\";\n\t\tconst bType = hasType(b.node) ? b.node[\"@type\"] : \"\";\n\t\tconst aWeight = typeWeight.get(aType) ?? Number.MAX_SAFE_INTEGER;\n\t\tconst bWeight = typeWeight.get(bType) ?? Number.MAX_SAFE_INTEGER;\n\n\t\tif (aWeight !== bWeight) return aWeight - bWeight;\n\t\treturn a.order - b.order;\n\t});\n\n\treturn ranked.map(({ node }) => JSON.stringify(node));\n};\n\nconst buildIdentityNodes = (\n\tidentity: Identity,\n\tsiteUrl: string,\n): { node: SchemaNode; ref: { \"@id\": string } } => {\n\tswitch (identity.type) {\n\t\tcase \"person\": {\n\t\t\tconst id = createSchemaId({\n\t\t\t\tkind: \"person\",\n\t\t\t\tname: identity.name,\n\t\t\t\tbaseUrl: siteUrl,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tnode: {\n\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\"@id\": id,\n\t\t\t\t\tname: identity.name,\n\t\t\t\t\tdescription: identity.description,\n\t\t\t\t\timage: buildImageObject(identity.image),\n\t\t\t\t\tsameAs: identity.sameAs,\n\t\t\t\t\turl: siteUrl,\n\t\t\t\t},\n\t\t\t\tref: { \"@id\": id },\n\t\t\t};\n\t\t}\n\t\tcase \"organization\": {\n\t\t\tconst id = createSchemaId({\n\t\t\t\tkind: \"organization\",\n\t\t\t\tname: identity.name,\n\t\t\t\tbaseUrl: siteUrl,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tnode: {\n\t\t\t\t\t\"@type\": \"Organization\",\n\t\t\t\t\t\"@id\": id,\n\t\t\t\t\tname: identity.name,\n\t\t\t\t\tdescription: identity.description,\n\t\t\t\t\tlogo: buildImageObject(identity.logo),\n\t\t\t\t\tsameAs: identity.sameAs,\n\t\t\t\t\turl: siteUrl,\n\t\t\t\t},\n\t\t\t\tref: { \"@id\": id },\n\t\t\t};\n\t\t}\n\t\tcase \"localBusiness\": {\n\t\t\tconst id = createSchemaId({\n\t\t\t\tkind: \"local-business\",\n\t\t\t\tname: identity.name,\n\t\t\t\tbaseUrl: siteUrl,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tnode: {\n\t\t\t\t\t\"@type\": \"LocalBusiness\",\n\t\t\t\t\t\"@id\": id,\n\t\t\t\t\tname: identity.name,\n\t\t\t\t\tdescription: identity.description,\n\t\t\t\t\tlogo: buildImageObject(identity.logo),\n\t\t\t\t\ttelephone: identity.phone,\n\t\t\t\t\temail: identity.email,\n\t\t\t\t\taddress: identity.address,\n\t\t\t\t\topeningHoursSpecification: identity.openingHours,\n\t\t\t\t\tsameAs: identity.sameAs,\n\t\t\t\t\turl: siteUrl,\n\t\t\t\t},\n\t\t\t\tref: { \"@id\": id },\n\t\t\t};\n\t\t}\n\t}\n};\n\nexport const buildSchemaMarkup = (input: BuildSchemaMarkupInput): string[] => {\n\tconst { node: identityNode, ref: identityRef } = buildIdentityNodes(\n\t\tinput.identity,\n\t\tinput.siteUrl,\n\t);\n\tconst websiteId = `${input.siteUrl}#website`;\n\n\tconst websiteNode: SchemaNode = {\n\t\t\"@type\": \"WebSite\",\n\t\t\"@id\": websiteId,\n\t\tname: input.siteName,\n\t\turl: input.siteUrl,\n\t\tdescription: input.siteDescription,\n\t\tpublisher: identityRef,\n\t};\n\n\tconst webpageNode: SchemaNode = {\n\t\t\"@type\": \"WebPage\",\n\t\t\"@id\": `${input.pageUrl}#webpage`,\n\t\turl: input.pageUrl,\n\t\tname: input.pageTitle,\n\t\tdescription: input.pageDescription,\n\t\tisPartOf: { \"@id\": websiteId },\n\t\tbreadcrumb: input.breadcrumb,\n\t\tmainEntity: input.mainEntity,\n\t};\n\n\treturn assembleNodes([identityNode, websiteNode, webpageNode]);\n};\n",
|
|
8
5
|
"import type { Thing, WithContext } from \"schema-dts\";\n\ntype Simplify<T> = { [K in keyof T]: T[K] } & {};\n\nexport type BuilderInput<T extends Thing> = Simplify<\n\tOmit<T, \"@type\" | \"@context\">\n>;\n\nexport type SchemaBuilder<T extends Thing> = (\n\tinput: BuilderInput<T>,\n) => WithContext<T>;\n\nexport function defineBuilder<T extends Thing>(type: string): SchemaBuilder<T> {\n\treturn (input: BuilderInput<T>) =>\n\t\t({\n\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\"@type\": type,\n\t\t\t...input,\n\t\t}) as unknown as WithContext<T>;\n}\n",
|
|
9
6
|
"import type { AboutPage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildAboutPage: SchemaBuilder<AboutPage> =\n\tdefineBuilder<AboutPage>(\"AboutPage\");\n",
|
|
7
|
+
"import type { AggregateOffer } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildAggregateOffer: SchemaBuilder<AggregateOffer> =\n\tdefineBuilder<AggregateOffer>(\"AggregateOffer\");\n",
|
|
10
8
|
"import type { AggregateRating } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildAggregateRating: SchemaBuilder<AggregateRating> =\n\tdefineBuilder<AggregateRating>(\"AggregateRating\");\n",
|
|
11
|
-
"import type { Answer } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildAnswer: SchemaBuilder<Answer>
|
|
9
|
+
"import type { Answer } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildAnswer: SchemaBuilder<Answer> =\n\tdefineBuilder<Answer>(\"Answer\");\n",
|
|
12
10
|
"import type { Article } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildArticle: SchemaBuilder<Article> =\n\tdefineBuilder<Article>(\"Article\");\n",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
11
|
+
"import type { Brand } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildBrand: SchemaBuilder<Brand> = defineBuilder<Brand>(\"Brand\");\n",
|
|
12
|
+
"export function slugToTitle(segment: string): string {\n\tconst decoded = decodeURIComponent(segment || \"\");\n\tconst normalized = decoded.replace(/[-_]+/g, \" \").replace(/\\s+/g, \" \").trim();\n\n\tif (!normalized) return \"\";\n\n\treturn normalized.replace(/\\b\\w/g, (char) => char.toUpperCase());\n}\n",
|
|
13
|
+
"import type { BreadcrumbList, ListItem, WithContext } from \"schema-dts\";\nimport { slugToTitle } from \"./internal/slug-to-title\";\n\nexport type BreadcrumbItemInput = {\n\ttitle: string;\n\turl: string;\n};\n\nexport type BuildBreadcrumbListSchemaInput = {\n\tpagePath: string;\n\tpageTitle: string;\n\titems?: BreadcrumbItemInput[];\n};\n\nfunction normalizePath(path: string): string {\n\tif (!path) return \"/\";\n\tconst withoutHash = path.split(\"#\")[0];\n\tconst withoutQuery = withoutHash.split(\"?\")[0];\n\tconst prefixed = withoutQuery.startsWith(\"/\")\n\t\t? withoutQuery\n\t\t: `/${withoutQuery}`;\n\treturn prefixed.replace(/\\/+$/, \"\") || \"/\";\n}\n\nfunction createDerivedParentItems(pagePath: string): BreadcrumbItemInput[] {\n\tconst normalized = normalizePath(pagePath);\n\tconst segments = normalized.split(\"/\").filter(Boolean);\n\n\tif (segments.length <= 1) return [];\n\n\treturn segments.slice(0, -1).map((segment, index) => ({\n\t\ttitle: slugToTitle(segment),\n\t\turl: `/${segments.slice(0, index + 1).join(\"/\")}`,\n\t}));\n}\n\nfunction toListItems(items: BreadcrumbItemInput[]): ListItem[] {\n\treturn items.map((item, index) => ({\n\t\t\"@type\": \"ListItem\",\n\t\tposition: index + 1,\n\t\tname: item.title,\n\t\titem: item.url,\n\t}));\n}\n\nexport function buildBreadcrumbListSchema({\n\tpagePath,\n\tpageTitle,\n\titems,\n}: BuildBreadcrumbListSchemaInput): WithContext<BreadcrumbList> {\n\tconst parentItems = items?.length\n\t\t? items\n\t\t: createDerivedParentItems(pagePath);\n\tconst finalItems = [\n\t\t...parentItems,\n\t\t{\n\t\t\ttitle: pageTitle,\n\t\t\turl: normalizePath(pagePath),\n\t\t},\n\t];\n\n\treturn {\n\t\t\"@context\": \"https://schema.org\",\n\t\t\"@type\": \"BreadcrumbList\",\n\t\titemListElement: toListItems(finalItems),\n\t};\n}\n",
|
|
15
14
|
"import type { Comment } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildComment: SchemaBuilder<Comment> =\n\tdefineBuilder<Comment>(\"Comment\");\n",
|
|
16
15
|
"import type { ContactPage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildContactPage: SchemaBuilder<ContactPage> =\n\tdefineBuilder<ContactPage>(\"ContactPage\");\n",
|
|
17
|
-
"import type { Course } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildCourse: SchemaBuilder<Course>
|
|
16
|
+
"import type { Course } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildCourse: SchemaBuilder<Course> =\n\tdefineBuilder<Course>(\"Course\");\n",
|
|
17
|
+
"import type { CourseInstance } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildCourseInstance: SchemaBuilder<CourseInstance> =\n\tdefineBuilder<CourseInstance>(\"CourseInstance\");\n",
|
|
18
18
|
"import type { Dataset } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildDataset: SchemaBuilder<Dataset> =\n\tdefineBuilder<Dataset>(\"Dataset\");\n",
|
|
19
19
|
"import type { DiscussionForumPosting } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildDiscussionForumPosting: SchemaBuilder<DiscussionForumPosting> =\n\tdefineBuilder<DiscussionForumPosting>(\"DiscussionForumPosting\");\n",
|
|
20
20
|
"import type { Event } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildEvent: SchemaBuilder<Event> = defineBuilder<Event>(\"Event\");\n",
|
|
21
21
|
"import type { FAQPage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildFAQPage: SchemaBuilder<FAQPage> =\n\tdefineBuilder<FAQPage>(\"FAQPage\");\n",
|
|
22
|
+
"import type { GeoCoordinates } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildGeoCoordinates: SchemaBuilder<GeoCoordinates> =\n\tdefineBuilder<GeoCoordinates>(\"GeoCoordinates\");\n",
|
|
23
|
+
"import type { HowToStep } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildHowToStep: SchemaBuilder<HowToStep> =\n\tdefineBuilder<HowToStep>(\"HowToStep\");\n",
|
|
22
24
|
"import type { ItemList } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildItemList: SchemaBuilder<ItemList> =\n\tdefineBuilder<ItemList>(\"ItemList\");\n",
|
|
23
25
|
"import type { JobPosting } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildJobPosting: SchemaBuilder<JobPosting> =\n\tdefineBuilder<JobPosting>(\"JobPosting\");\n",
|
|
24
26
|
"import type { LocalBusiness } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildLocalBusiness: SchemaBuilder<LocalBusiness> =\n\tdefineBuilder<LocalBusiness>(\"LocalBusiness\");\n",
|
|
27
|
+
"import type { MerchantReturnPolicy } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildMerchantReturnPolicy: SchemaBuilder<MerchantReturnPolicy> =\n\tdefineBuilder<MerchantReturnPolicy>(\"MerchantReturnPolicy\");\n",
|
|
28
|
+
"import type { MonetaryAmount } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildMonetaryAmount: SchemaBuilder<MonetaryAmount> =\n\tdefineBuilder<MonetaryAmount>(\"MonetaryAmount\");\n",
|
|
25
29
|
"import type { Movie } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildMovie: SchemaBuilder<Movie> = defineBuilder<Movie>(\"Movie\");\n",
|
|
30
|
+
"import type { NutritionInformation } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildNutritionInformation: SchemaBuilder<NutritionInformation> =\n\tdefineBuilder<NutritionInformation>(\"NutritionInformation\");\n",
|
|
31
|
+
"import type { Offer } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildOffer: SchemaBuilder<Offer> = defineBuilder<Offer>(\"Offer\");\n",
|
|
32
|
+
"import type { OfferShippingDetails } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildOfferShippingDetails: SchemaBuilder<OfferShippingDetails> =\n\tdefineBuilder<OfferShippingDetails>(\"OfferShippingDetails\");\n",
|
|
33
|
+
"import type { Organization } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildOrganization: SchemaBuilder<Organization> =\n\tdefineBuilder<Organization>(\"Organization\");\n",
|
|
34
|
+
"import type { Person } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildPerson: SchemaBuilder<Person> =\n\tdefineBuilder<Person>(\"Person\");\n",
|
|
35
|
+
"import type { Place } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildPlace: SchemaBuilder<Place> = defineBuilder<Place>(\"Place\");\n",
|
|
36
|
+
"import type { PostalAddress } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildPostalAddress: SchemaBuilder<PostalAddress> =\n\tdefineBuilder<PostalAddress>(\"PostalAddress\");\n",
|
|
26
37
|
"import type { Product } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildProduct: SchemaBuilder<Product> =\n\tdefineBuilder<Product>(\"Product\");\n",
|
|
27
38
|
"import type { ProfilePage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildProfilePage: SchemaBuilder<ProfilePage> =\n\tdefineBuilder<ProfilePage>(\"ProfilePage\");\n",
|
|
28
|
-
"import type { QAPage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildQAPage: SchemaBuilder<QAPage>
|
|
39
|
+
"import type { QAPage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildQAPage: SchemaBuilder<QAPage> =\n\tdefineBuilder<QAPage>(\"QAPage\");\n",
|
|
40
|
+
"import type { QuantitativeValue } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildQuantitativeValue: SchemaBuilder<QuantitativeValue> =\n\tdefineBuilder<QuantitativeValue>(\"QuantitativeValue\");\n",
|
|
29
41
|
"import type { Question } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildQuestion: SchemaBuilder<Question> =\n\tdefineBuilder<Question>(\"Question\");\n",
|
|
30
|
-
"import type { Recipe } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildRecipe: SchemaBuilder<Recipe>
|
|
31
|
-
"import type { Review } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildReview: SchemaBuilder<Review>
|
|
42
|
+
"import type { Recipe } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildRecipe: SchemaBuilder<Recipe> =\n\tdefineBuilder<Recipe>(\"Recipe\");\n",
|
|
43
|
+
"import type { Review } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildReview: SchemaBuilder<Review> =\n\tdefineBuilder<Review>(\"Review\");\n",
|
|
44
|
+
"import type { Schedule } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildSchedule: SchemaBuilder<Schedule> =\n\tdefineBuilder<Schedule>(\"Schedule\");\n",
|
|
32
45
|
"import type { SoftwareApplication } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildSoftwareApplication: SchemaBuilder<SoftwareApplication> =\n\tdefineBuilder<SoftwareApplication>(\"SoftwareApplication\");\n",
|
|
33
46
|
"import type { VacationRental } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildVacationRental: SchemaBuilder<VacationRental> =\n\tdefineBuilder<VacationRental>(\"VacationRental\");\n",
|
|
34
47
|
"import type { VideoObject } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildVideoObject: SchemaBuilder<VideoObject> =\n\tdefineBuilder<VideoObject>(\"VideoObject\");\n",
|
|
35
48
|
"import type { WebPage } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildWebPage: SchemaBuilder<WebPage> =\n\tdefineBuilder<WebPage>(\"WebPage\");\n",
|
|
36
49
|
"import type { WebSite } from \"schema-dts\";\nimport { defineBuilder, type SchemaBuilder } from \"../define-builder\";\n\nexport const buildWebSite: SchemaBuilder<WebSite> =\n\tdefineBuilder<WebSite>(\"WebSite\");\n"
|
|
37
50
|
],
|
|
38
|
-
"mappings": ";
|
|
39
|
-
"debugId": "
|
|
51
|
+
"mappings": ";AAYO,SAAS,aAA8B,CAAC,MAAgC;AAAA,EAC9E,OAAO,CAAC,WACN;AAAA,IACA,YAAY;AAAA,IACZ,SAAS;AAAA,OACN;AAAA,EACJ;AAAA;;;ACfK,IAAM,iBACZ,cAAyB,WAAW;;;ACD9B,IAAM,sBACZ,cAA8B,gBAAgB;;;ACDxC,IAAM,uBACZ,cAA+B,iBAAiB;;;ACD1C,IAAM,cACZ,cAAsB,QAAQ;;;ACDxB,IAAM,eACZ,cAAuB,SAAS;;;ACD1B,IAAM,aAAmC,cAAqB,OAAO;;;ACHrE,SAAS,WAAW,CAAC,SAAyB;AAAA,EACpD,MAAM,UAAU,mBAAmB,WAAW,EAAE;AAAA,EAChD,MAAM,aAAa,QAAQ,QAAQ,UAAU,GAAG,EAAE,QAAQ,QAAQ,GAAG,EAAE,KAAK;AAAA,EAE5E,IAAI,CAAC;AAAA,IAAY,OAAO;AAAA,EAExB,OAAO,WAAW,QAAQ,SAAS,CAAC,SAAS,KAAK,YAAY,CAAC;AAAA;;;ACQhE,SAAS,aAAa,CAAC,MAAsB;AAAA,EAC5C,IAAI,CAAC;AAAA,IAAM,OAAO;AAAA,EAClB,MAAM,cAAc,KAAK,MAAM,GAAG,EAAE;AAAA,EACpC,MAAM,eAAe,YAAY,MAAM,GAAG,EAAE;AAAA,EAC5C,MAAM,WAAW,aAAa,WAAW,GAAG,IACzC,eACA,IAAI;AAAA,EACP,OAAO,SAAS,QAAQ,QAAQ,EAAE,KAAK;AAAA;AAGxC,SAAS,wBAAwB,CAAC,UAAyC;AAAA,EAC1E,MAAM,aAAa,cAAc,QAAQ;AAAA,EACzC,MAAM,WAAW,WAAW,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,EAErD,IAAI,SAAS,UAAU;AAAA,IAAG,OAAO,CAAC;AAAA,EAElC,OAAO,SAAS,MAAM,GAAG,EAAE,EAAE,IAAI,CAAC,SAAS,WAAW;AAAA,IACrD,OAAO,YAAY,OAAO;AAAA,IAC1B,KAAK,IAAI,SAAS,MAAM,GAAG,QAAQ,CAAC,EAAE,KAAK,GAAG;AAAA,EAC/C,EAAE;AAAA;AAGH,SAAS,WAAW,CAAC,OAA0C;AAAA,EAC9D,OAAO,MAAM,IAAI,CAAC,MAAM,WAAW;AAAA,IAClC,SAAS;AAAA,IACT,UAAU,QAAQ;AAAA,IAClB,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,EACZ,EAAE;AAAA;AAGI,SAAS,yBAAyB;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,GAC+D;AAAA,EAC/D,MAAM,cAAc,OAAO,SACxB,QACA,yBAAyB,QAAQ;AAAA,EACpC,MAAM,aAAa;AAAA,IAClB,GAAG;AAAA,IACH;AAAA,MACC,OAAO;AAAA,MACP,KAAK,cAAc,QAAQ;AAAA,IAC5B;AAAA,EACD;AAAA,EAEA,OAAO;AAAA,IACN,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,iBAAiB,YAAY,UAAU;AAAA,EACxC;AAAA;;;AC9DM,IAAM,eACZ,cAAuB,SAAS;;;ACD1B,IAAM,mBACZ,cAA2B,aAAa;;;ACDlC,IAAM,cACZ,cAAsB,QAAQ;;;ACDxB,IAAM,sBACZ,cAA8B,gBAAgB;;;ACDxC,IAAM,eACZ,cAAuB,SAAS;;;ACD1B,IAAM,8BACZ,cAAsC,wBAAwB;;;ACDxD,IAAM,aAAmC,cAAqB,OAAO;;;ACArE,IAAM,eACZ,cAAuB,SAAS;;;ACD1B,IAAM,sBACZ,cAA8B,gBAAgB;;;ACDxC,IAAM,iBACZ,cAAyB,WAAW;;;ACD9B,IAAM,gBACZ,cAAwB,UAAU;;;ACD5B,IAAM,kBACZ,cAA0B,YAAY;;;ACDhC,IAAM,qBACZ,cAA6B,eAAe;;;ACDtC,IAAM,4BACZ,cAAoC,sBAAsB;;;ACDpD,IAAM,sBACZ,cAA8B,gBAAgB;;;ACDxC,IAAM,aAAmC,cAAqB,OAAO;;;ACArE,IAAM,4BACZ,cAAoC,sBAAsB;;;ACDpD,IAAM,aAAmC,cAAqB,OAAO;;;ACArE,IAAM,4BACZ,cAAoC,sBAAsB;;;ACDpD,IAAM,oBACZ,cAA4B,cAAc;;;ACDpC,IAAM,cACZ,cAAsB,QAAQ;;;ACDxB,IAAM,aAAmC,cAAqB,OAAO;;;ACArE,IAAM,qBACZ,cAA6B,eAAe;;;ACDtC,IAAM,eACZ,cAAuB,SAAS;;;ACD1B,IAAM,mBACZ,cAA2B,aAAa;;;ACDlC,IAAM,cACZ,cAAsB,QAAQ;;;ACDxB,IAAM,yBACZ,cAAiC,mBAAmB;;;ACD9C,IAAM,gBACZ,cAAwB,UAAU;;;ACD5B,IAAM,cACZ,cAAsB,QAAQ;;;ACDxB,IAAM,cACZ,cAAsB,QAAQ;;;ACDxB,IAAM,gBACZ,cAAwB,UAAU;;;ACD5B,IAAM,2BACZ,cAAmC,qBAAqB;;;ACDlD,IAAM,sBACZ,cAA8B,gBAAgB;;;ACDxC,IAAM,mBACZ,cAA2B,aAAa;;;ACDlC,IAAM,eACZ,cAAuB,SAAS;;;ACD1B,IAAM,eACZ,cAAuB,SAAS;",
|
|
52
|
+
"debugId": "AC1EB3C8028F80A664756E2164756E21",
|
|
40
53
|
"names": []
|
|
41
54
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type DurationParts = {
|
|
2
|
+
years?: number;
|
|
3
|
+
months?: number;
|
|
4
|
+
weeks?: number;
|
|
5
|
+
days?: number;
|
|
6
|
+
hours?: number;
|
|
7
|
+
minutes?: number;
|
|
8
|
+
seconds?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function toIsoDuration(parts: DurationParts): string;
|
|
11
|
+
export declare function toIsoDate(value: Date | string): string;
|
package/dist/utils/image.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
+
import type { IdReference, ImageObjectLeaf, Organization, Person } from "schema-dts";
|
|
1
2
|
type ImageObjectInput = {
|
|
2
3
|
url: string;
|
|
3
4
|
width?: number;
|
|
4
5
|
height?: number;
|
|
6
|
+
caption?: string;
|
|
7
|
+
creditText?: string;
|
|
8
|
+
copyrightNotice?: string;
|
|
9
|
+
license?: string;
|
|
10
|
+
acquireLicensePage?: string;
|
|
11
|
+
creator?: Person | Organization | IdReference;
|
|
5
12
|
};
|
|
6
13
|
export type ImageInput = string | ImageObjectInput;
|
|
7
|
-
export declare function buildImageObject(input?: ImageInput):
|
|
14
|
+
export declare function buildImageObject(input?: ImageInput): ImageObjectLeaf | undefined;
|
|
8
15
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toAbsoluteUrl(value: string | null | undefined, siteUrl: string): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawl-me-maybe/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"sideEffects": false,
|
|
4
5
|
"type": "module",
|
|
5
6
|
"author": "Nathan Nye <nathan@nye.dev> (https://nye.dev)",
|
|
6
7
|
"license": "MIT",
|
|
@@ -21,10 +22,11 @@
|
|
|
21
22
|
"scripts": {
|
|
22
23
|
"lint": "biome check .",
|
|
23
24
|
"fix": "biome check --write .",
|
|
24
|
-
"build": "rm -rf dist && bun build src/index.ts --outdir dist --format esm --sourcemap --external schema-dts && tsc -p tsconfig.json --declaration --emitDeclarationOnly --declarationDir dist --rootDir src"
|
|
25
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --format esm --sourcemap --external schema-dts && tsc -p tsconfig.json --declaration --emitDeclarationOnly --declarationDir dist --rootDir src",
|
|
26
|
+
"prepublishOnly": "bun run build"
|
|
25
27
|
},
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"schema-dts": "^
|
|
29
|
+
"schema-dts": "^2.0.0"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {}
|
|
30
32
|
}
|