@contentrain/wp-import 0.11.24 → 0.11.26
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/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +38 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -114,6 +114,10 @@ interface ImportReport {
|
|
|
114
114
|
acf_outside_choices: Record<string, number>;
|
|
115
115
|
/** ACF date-times written without a zone because the source named none (`timezone_string` / `gmt_offset`). */
|
|
116
116
|
acf_datetime_unzoned: number;
|
|
117
|
+
/** ACF image/file values that were an attachment id the export does not hold, left out (`field: count`). */
|
|
118
|
+
acf_media_unknown: Record<string, number>;
|
|
119
|
+
/** Self-closing (server-rendered) Gutenberg blocks dropped from post bodies with nothing to keep: `block name: count`. */
|
|
120
|
+
blocks_dynamic_dropped: Record<string, number>;
|
|
117
121
|
skipped_types: string[];
|
|
118
122
|
dropped_relations: number;
|
|
119
123
|
models: Record<string, {
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/wxr.ts","../src/rest.ts","../src/contentrain.ts","../src/comments.ts","../src/php-unserialize.ts","../src/core.ts","../src/delta.ts"],"mappings":";;;;UA2BiB,QAAA;EACf,UAAA;IAAc,QAAA;IAAkB,OAAA;IAAiB,MAAA;IAAgB,IAAA;EAAA;EACjE,UAAA;EACA,gBAAA;EACA,MAAA,EAAQ,MAAA;AAAA;AAAA,UAGO,cAAA;EACf,GAAA,EAAK,KAAA;EACL,KAAA,EAAO,QAAA;AAAA;AAAA,iBAiBa,QAAA,CAAS,KAAA,WAAgB,QAAA,EAAU,IAAA;EAAS,IAAA;AAAA,IAAkB,OAAA,CAAQ,cAAA;;;UCnC3E,iBAAA;EACf,MAAA;;EAEA,SAAA,UAAmB,KAAA;EDMI;;;;;;;;ECGvB,IAAA;IAAS,IAAA;IAAc,WAAA;EAAA;EACvB,OAAA;EDAc;AAGhB;;;;ECGE,WAAA;EDFK;;;;ECOL,QAAA;EACA,IAAA;AAAA;AAAA,UAGe,gBAAA;EACf,GAAA,EAAK,KAAA;EACL,QAAA;EDKkF;;;;;;;;ECIlF,UAAA;IAAc,MAAA;IAA0C,SAAA;EAAA;;;AAvC1D;;;;;;;;;;EAoDE,IAAA;AAAA;AAAA,iBA4EoB,cAAA,CAAe,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,gBAAA;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/wxr.ts","../src/rest.ts","../src/contentrain.ts","../src/comments.ts","../src/php-unserialize.ts","../src/core.ts","../src/delta.ts"],"mappings":";;;;UA2BiB,QAAA;EACf,UAAA;IAAc,QAAA;IAAkB,OAAA;IAAiB,MAAA;IAAgB,IAAA;EAAA;EACjE,UAAA;EACA,gBAAA;EACA,MAAA,EAAQ,MAAA;AAAA;AAAA,UAGO,cAAA;EACf,GAAA,EAAK,KAAA;EACL,KAAA,EAAO,QAAA;AAAA;AAAA,iBAiBa,QAAA,CAAS,KAAA,WAAgB,QAAA,EAAU,IAAA;EAAS,IAAA;AAAA,IAAkB,OAAA,CAAQ,cAAA;;;UCnC3E,iBAAA;EACf,MAAA;;EAEA,SAAA,UAAmB,KAAA;EDMI;;;;;;;;ECGvB,IAAA;IAAS,IAAA;IAAc,WAAA;EAAA;EACvB,OAAA;EDAc;AAGhB;;;;ECGE,WAAA;EDFK;;;;ECOL,QAAA;EACA,IAAA;AAAA;AAAA,UAGe,gBAAA;EACf,GAAA,EAAK,KAAA;EACL,QAAA;EDKkF;;;;;;;;ECIlF,UAAA;IAAc,MAAA;IAA0C,SAAA;EAAA;;;AAvC1D;;;;;;;;;;EAoDE,IAAA;AAAA;AAAA,iBA4EoB,cAAA,CAAe,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,gBAAA;;;;UCnHzD,QAA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AA,CAAe,GAAA;;iBAyFf,cAAA,CAAe,CAAA,WAAY,iBAAA;;;;;;;;cCrE9B,KAAA,GAAS,CAAA;;cAGT,KAAA,GAAS,CAAA;;cAcT,KAAA,GAAS,CAAA;;;;;;;;ALCtB;;cK8Ba,UAAA,EAAU,MAAA;;cAIV,WAAA,EAAW,MAAA;;cAOX,UAAA,GAAc,CAAA;AAAA,cAGd,OAAA,GAAW,CAAA;;;;;;;cAcX,WAAA,GAAe,GAAA;;;;UC5FX,UAAA;EACf,KAAA,EAAO,MAAA;EACP,gBAAA,EAAkB,cAAA;AAAA;AAAA,UAGH,oBAAA;ENOD;EMLd,KAAA,EAAO,eAAA;ENEO;EMAd,KAAA,EAAO,UAAA;ENA0C;EMEjD,QAAA,GAAW,UAAA;ENDX;;;;;EMOA,UAAA;ENFe;;;;EMOf,SAAA;AAAA;AAAA,cAGW,kBAAA;AAAA,cACA,iBAAA;;;ANQb;;;;;;;;;;iBM8NgB,eAAA,CAAgB,KAAA,EAAO,oBAAA,GAAuB,eAAA;;iBAkC9C,uBAAA,CAAwB,IAAA,EAAM,eAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -931,7 +931,16 @@ function acfValue(def, value, ctx = {}) {
|
|
|
931
931
|
switch (def.type) {
|
|
932
932
|
case "image":
|
|
933
933
|
case "file":
|
|
934
|
-
case "video":
|
|
934
|
+
case "video": {
|
|
935
|
+
if (isAttachment(value)) return value.url;
|
|
936
|
+
const id = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value.trim()) ? Number(value) : null;
|
|
937
|
+
if (id !== null) {
|
|
938
|
+
const url = ctx.mediaUrl?.(id);
|
|
939
|
+
if (!url) ctx.unknownMedia?.(value);
|
|
940
|
+
return url;
|
|
941
|
+
}
|
|
942
|
+
return typeof value === "string" ? value : void 0;
|
|
943
|
+
}
|
|
935
944
|
case "date": return ymd(value) ?? (typeof value === "string" ? value : void 0);
|
|
936
945
|
case "datetime": {
|
|
937
946
|
const local = dt(value);
|
|
@@ -2115,6 +2124,24 @@ async function fetchRestRawIR(options) {
|
|
|
2115
2124
|
};
|
|
2116
2125
|
}
|
|
2117
2126
|
//#endregion
|
|
2127
|
+
//#region src/blocks.ts
|
|
2128
|
+
/**
|
|
2129
|
+
* A post body without Gutenberg's block delimiters (`<!-- wp:paragraph -->`, `<!-- /wp:paragraph -->`,
|
|
2130
|
+
* `<!-- wp:image {...} /-->`). Only the delimiters go (with the line break that ends them); the markup
|
|
2131
|
+
* inside every block stays, and so does any other comment. Block attributes are read from the delimiters
|
|
2132
|
+
* before this (menus, navigation), never from the stored body.
|
|
2133
|
+
*
|
|
2134
|
+
* A self-closing block (`<!-- wp:latest-posts /-->`, `<!-- wp:block {"ref":12} /-->`) holds no markup: WordPress
|
|
2135
|
+
* renders it on the server, so nothing of it survives. `onDynamic` hears its name (as written, `core/` omitted)
|
|
2136
|
+
* so the loss can be reported.
|
|
2137
|
+
*/
|
|
2138
|
+
function stripBlockDelimiters(content, onDynamic) {
|
|
2139
|
+
return content.replace(new RegExp(`${BLOCK_TOKEN.source}\\r?\\n?`, "g"), (_all, closer, ns, local, _json, selfClose) => {
|
|
2140
|
+
if (selfClose && !closer) onDynamic?.(`${ns ?? ""}${local}`);
|
|
2141
|
+
return "";
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
//#endregion
|
|
2118
2145
|
//#region src/contentrain.ts
|
|
2119
2146
|
const utf8Length = (s) => new TextEncoder().encode(s).length;
|
|
2120
2147
|
/** `s` cut on a code-point boundary to at most `max` UTF-8 bytes, without a trailing hyphen. */
|
|
@@ -2197,6 +2224,8 @@ function rawToContentrain(raw, opts) {
|
|
|
2197
2224
|
acf_options_renamed: {},
|
|
2198
2225
|
acf_outside_choices: {},
|
|
2199
2226
|
acf_datetime_unzoned: 0,
|
|
2227
|
+
acf_media_unknown: {},
|
|
2228
|
+
blocks_dynamic_dropped: {},
|
|
2200
2229
|
skipped_types: [],
|
|
2201
2230
|
dropped_relations: 0,
|
|
2202
2231
|
models: {},
|
|
@@ -2289,6 +2318,7 @@ function rawToContentrain(raw, opts) {
|
|
|
2289
2318
|
ref: hexId(identityOwner.get(key) === canonical ? key : `${mid}:wp:${canonical}`)
|
|
2290
2319
|
});
|
|
2291
2320
|
}
|
|
2321
|
+
const attachmentUrl = new Map(raw.attachments.map((a) => [a.id, a.url]));
|
|
2292
2322
|
const mediaRef = (id) => raw.attachments.some((a) => a.id === id) ? hexId(`media:${id}`) : null;
|
|
2293
2323
|
const termById = new Map(raw.terms.map((t) => [t.id, t]));
|
|
2294
2324
|
const authorById = new Map(raw.authors.filter((a) => a.id !== null).map((a) => [a.id, a]));
|
|
@@ -2410,6 +2440,10 @@ function rawToContentrain(raw, opts) {
|
|
|
2410
2440
|
},
|
|
2411
2441
|
unzoned: () => {
|
|
2412
2442
|
report.acf_datetime_unzoned++;
|
|
2443
|
+
},
|
|
2444
|
+
mediaUrl: (id) => attachmentUrl.get(id) ?? void 0,
|
|
2445
|
+
unknownMedia: () => {
|
|
2446
|
+
report.acf_media_unknown[k] = (report.acf_media_unknown[k] ?? 0) + 1;
|
|
2413
2447
|
}
|
|
2414
2448
|
};
|
|
2415
2449
|
return plan.def ? acfValue(plan.def, plan.kind === "address" ? addressOf(value) : acfRows(acfScrub(value)), ctx) : acfRefs(plan, value);
|
|
@@ -2801,7 +2835,9 @@ function rawToContentrain(raw, opts) {
|
|
|
2801
2835
|
wp_id: p.id
|
|
2802
2836
|
};
|
|
2803
2837
|
if (fields.excerpt) e.excerpt = strip(p.excerpt);
|
|
2804
|
-
if (fields.body) e.body = p.content
|
|
2838
|
+
if (fields.body) e.body = stripBlockDelimiters(p.content, (name) => {
|
|
2839
|
+
report.blocks_dynamic_dropped[name] = (report.blocks_dynamic_dropped[name] ?? 0) + 1;
|
|
2840
|
+
});
|
|
2805
2841
|
if (fields.published_at && p.date) e.published_at = p.date;
|
|
2806
2842
|
if (p.modified) e.modified_at = p.modified;
|
|
2807
2843
|
if (p.link) e.link = p.link;
|