@projectdochelp/s3te 3.4.0 → 3.4.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectdochelp/s3te",
3
- "version": "3.4.0",
3
+ "version": "3.4.3",
4
4
  "description": "CLI, render core, AWS adapter, and testkit for S3TemplateEngine projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -106,7 +106,27 @@ function serializeStructuredValue(value) {
106
106
  return null;
107
107
  }
108
108
 
109
+ function maybeParseStructuredString(value) {
110
+ if (typeof value !== "string") {
111
+ return value;
112
+ }
113
+
114
+ const trimmed = value.trim();
115
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
116
+ return value;
117
+ }
118
+
119
+ try {
120
+ return JSON.parse(trimmed);
121
+ } catch {
122
+ return value;
123
+ }
124
+ }
125
+
109
126
  function toSimpleValue(value) {
127
+ const normalizedValue = maybeParseStructuredString(value);
128
+
129
+ value = normalizedValue;
110
130
  if (value == null) {
111
131
  return null;
112
132
  }
@@ -7,6 +7,12 @@ function normalizeKey(value) {
7
7
  return String(value).replace(/\\/g, "/");
8
8
  }
9
9
 
10
+ function matchesProjectRelativeRoot(key, root) {
11
+ const normalizedKey = normalizeKey(key);
12
+ const normalizedRoot = normalizeKey(root);
13
+ return normalizedKey === normalizedRoot || normalizedKey.startsWith(`${normalizedRoot}/`);
14
+ }
15
+
10
16
  function normalizeLocale(value) {
11
17
  return String(value).trim().toLowerCase();
12
18
  }
@@ -122,6 +128,15 @@ export class FileSystemTemplateRepository {
122
128
  resolveKey(key) {
123
129
  const normalized = normalizeKey(key);
124
130
 
131
+ for (const variantConfig of Object.values(this.config.variants)) {
132
+ if (
133
+ matchesProjectRelativeRoot(normalized, variantConfig.sourceDir)
134
+ || matchesProjectRelativeRoot(normalized, variantConfig.partDir)
135
+ ) {
136
+ return path.join(this.projectDir, normalized);
137
+ }
138
+ }
139
+
125
140
  for (const [variantName, variantConfig] of Object.entries(this.config.variants)) {
126
141
  if (normalized === variantName || normalized.startsWith(`${variantName}/`)) {
127
142
  const suffix = normalized === variantName ? "" : normalized.slice(variantName.length + 1);
@@ -22,6 +22,23 @@ function legacyAttributeValueToPlain(attribute) {
22
22
  return undefined;
23
23
  }
24
24
 
25
+ function maybeParseStructuredString(value) {
26
+ if (typeof value !== "string") {
27
+ return value;
28
+ }
29
+
30
+ const trimmed = value.trim();
31
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
32
+ return value;
33
+ }
34
+
35
+ try {
36
+ return JSON.parse(trimmed);
37
+ } catch {
38
+ return value;
39
+ }
40
+ }
41
+
25
42
  function readComparableValue(item, field) {
26
43
  if (field === "__typename") {
27
44
  return item.model;
@@ -159,12 +176,14 @@ export function readContentField(item, field, language) {
159
176
  }
160
177
 
161
178
  export function serializeContentValue(value) {
162
- if (value == null) {
179
+ const normalizedValue = maybeParseStructuredString(value);
180
+
181
+ if (normalizedValue == null) {
163
182
  return "";
164
183
  }
165
184
 
166
- if (Array.isArray(value)) {
167
- return value.map((entry) => {
185
+ if (Array.isArray(normalizedValue)) {
186
+ return normalizedValue.map((entry) => {
168
187
  const text = typeof entry === "string" && entry.includes("-")
169
188
  ? entry.slice(entry.lastIndexOf("-") + 1)
170
189
  : String(entry);
@@ -172,5 +191,14 @@ export function serializeContentValue(value) {
172
191
  }).join("");
173
192
  }
174
193
 
175
- return String(value);
194
+ if (normalizedValue && typeof normalizedValue === "object") {
195
+ if (typeof normalizedValue.html === "string") {
196
+ return normalizedValue.html;
197
+ }
198
+ if (typeof normalizedValue.text === "string") {
199
+ return normalizedValue.text;
200
+ }
201
+ }
202
+
203
+ return String(normalizedValue);
176
204
  }