@jxsuite/parser 0.22.1 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/ContentEntry.class.json +5 -0
- package/src/content.js +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jxsuite/parser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"description": "Jx markdown parser and external class integration",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@happy-dom/global-registrator": "^20.9.0",
|
|
51
|
-
"@jxsuite/runtime": "^0.
|
|
51
|
+
"@jxsuite/runtime": "^0.23.1",
|
|
52
52
|
"@types/hast": "^3.0.4"
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"identifier": "id",
|
|
18
18
|
"type": { "type": "string" },
|
|
19
19
|
"description": "Entry ID to fetch"
|
|
20
|
+
},
|
|
21
|
+
"field": {
|
|
22
|
+
"identifier": "field",
|
|
23
|
+
"type": { "type": "string", "default": "id" },
|
|
24
|
+
"description": "Field to match against — defaults to 'id' (the entry slug). Set to a frontmatter field name (e.g. 'sku') to match by data field instead."
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
|
package/src/content.js
CHANGED
|
@@ -119,6 +119,7 @@ export function findEntry(entries, id) {
|
|
|
119
119
|
* @typedef {{
|
|
120
120
|
* contentType?: string;
|
|
121
121
|
* id?: unknown;
|
|
122
|
+
* field?: string;
|
|
122
123
|
* _project?: { contentTypes?: Map<string, ContentLoaderEntry[]>; [k: string]: unknown };
|
|
123
124
|
* _document?: { route?: { _pathParams?: Record<string, string> }; [k: string]: unknown };
|
|
124
125
|
* [k: string]: unknown;
|
|
@@ -146,7 +147,7 @@ export class ContentEntry {
|
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
resolve() {
|
|
149
|
-
const { contentType, id, _project, _document } = this.config;
|
|
150
|
+
const { contentType, id, field, _project, _document } = this.config;
|
|
150
151
|
const entries = _project?.contentTypes?.get(contentType ?? "");
|
|
151
152
|
if (!entries) return null;
|
|
152
153
|
|
|
@@ -161,6 +162,9 @@ export class ContentEntry {
|
|
|
161
162
|
}
|
|
162
163
|
if (!resolvedId) return null;
|
|
163
164
|
|
|
165
|
+
if (field && field !== "id") {
|
|
166
|
+
return entries.find((e) => e.data[field] === resolvedId) ?? null;
|
|
167
|
+
}
|
|
164
168
|
return findEntry(entries, /** @type {string} */ (resolvedId));
|
|
165
169
|
}
|
|
166
170
|
}
|