schemaorg-kit 1.1.1 → 1.3.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 +23 -13
- package/dist/index.d.mts +6629 -1652
- package/dist/index.d.ts +6629 -1652
- package/dist/index.js +214 -50
- package/dist/index.mjs +213 -50
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,33 +87,42 @@ console.log(article.toScript());
|
|
|
87
87
|
|
|
88
88
|
## `@graph` Support
|
|
89
89
|
|
|
90
|
-
Use `createGraph` to output multiple schema nodes in a single `<script>` tag
|
|
90
|
+
Use `createGraph` to output multiple schema nodes in a single `<script>` tag. Use `SchemaIds` for consistent `@id` cross-references:
|
|
91
91
|
|
|
92
92
|
```typescript
|
|
93
93
|
import {
|
|
94
|
+
SchemaIds,
|
|
94
95
|
createGraph,
|
|
96
|
+
createOrganization,
|
|
97
|
+
createWebSite,
|
|
95
98
|
createWebPage,
|
|
96
|
-
createArticle,
|
|
97
|
-
createPerson,
|
|
98
99
|
} from "schemaorg-kit";
|
|
99
100
|
|
|
101
|
+
const ids = new SchemaIds("https://example.com");
|
|
102
|
+
|
|
100
103
|
const graph = createGraph([
|
|
101
|
-
|
|
102
|
-
"@id":
|
|
103
|
-
|
|
104
|
+
createOrganization({
|
|
105
|
+
"@id": ids.organization(),
|
|
106
|
+
name: "Acme Corp",
|
|
107
|
+
url: "https://example.com",
|
|
104
108
|
}),
|
|
105
|
-
|
|
106
|
-
"@id":
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
createWebSite({
|
|
110
|
+
"@id": ids.website(),
|
|
111
|
+
name: "Acme",
|
|
112
|
+
url: "https://example.com",
|
|
113
|
+
publisher: ids.ref("organization"), // { "@id": "https://example.com/#organization" }
|
|
114
|
+
}),
|
|
115
|
+
createWebPage({
|
|
116
|
+
"@id": ids.webpage(),
|
|
117
|
+
url: "https://example.com",
|
|
110
118
|
}),
|
|
111
|
-
createPerson({ "@id": "https://example.com/about#person", name: "Jane Doe" }),
|
|
112
119
|
]);
|
|
113
120
|
|
|
114
121
|
console.log(graph.toScript());
|
|
115
122
|
```
|
|
116
123
|
|
|
124
|
+
`SchemaIds` provides well-known methods (`organization()`, `website()`, `webpage()`, `person()`, etc.), `custom()` for arbitrary fragments, `forPath()` for page-scoped IDs, and `ref()` for cross-reference objects.
|
|
125
|
+
|
|
117
126
|
## Unified Factory
|
|
118
127
|
|
|
119
128
|
As an alternative to named imports, use the `schema()` factory with any registered type name:
|
|
@@ -280,7 +289,8 @@ src/
|
|
|
280
289
|
├── core/
|
|
281
290
|
│ ├── base.ts # SchemaNode<T> class + makeFactory()
|
|
282
291
|
│ ├── registry.ts # Unified schema() factory + REGISTRY
|
|
283
|
-
│
|
|
292
|
+
│ ├── graph.ts # SchemaGraph + createGraph()
|
|
293
|
+
│ └── ids.ts # SchemaIds + SchemaId (cross-reference helpers)
|
|
284
294
|
├── types/
|
|
285
295
|
│ ├── shared/ # Reusable building blocks
|
|
286
296
|
│ │ ├── Offer.ts # Offer, AggregateOffer, MerchantReturnPolicy, UnitPriceSpecification, ItemCondition
|