@contentrain/wp-import 0.13.0 → 0.14.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/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +40 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -160,7 +160,7 @@ interface RawToContentrainOptions {
|
|
|
160
160
|
*/
|
|
161
161
|
includeEmails?: boolean;
|
|
162
162
|
}
|
|
163
|
-
declare function rawToContentrain(
|
|
163
|
+
declare function rawToContentrain(input: RawIR, opts?: RawToContentrainOptions): ContentrainResult;
|
|
164
164
|
//#endregion
|
|
165
165
|
//#region src/comments.d.ts
|
|
166
166
|
/**
|
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;;;;UClHzD,QAAA;EACf,KAAA;EACA,IAAA;EFPuB;EESvB,IAAA;EFLc;EEOd,IAAA;EFVc;;;;EEed,MAAA;AAAA;AAAA,UAkBe,YAAA;EACf,cAAA;EACA,aAAA;EFhCc;EEkCd,UAAA,EAAY,QAAA;EACZ,cAAA;E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AyFf,cAAA,CAAe,CAAA,WAAY,iBAAA;;;;;;;;cCrE9B,KAAA,GAAS,CAAA;;cAGT,KAAA,GAAS,CAAA;;cAcT,KAAA,GAAS,CAAA;;;;;;;;ALCtB;;cK8Ba,UAAA,EAAU,MAAA;;;;;;;cASV,iBAAA;AAAA,cACA,UAAA,GAAc,IAAA;;cAGd,WAAA,EAAW,MAAA;;cAOX,UAAA,GAAc,CAAA;AAAA,cAGd,OAAA,GAAW,CAAA;;AJxFxB;;;;;cIsGa,WAAA,GAAe,GAAA;;;;UCrGX,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
|
@@ -2198,7 +2198,32 @@ function relationOver(targets) {
|
|
|
2198
2198
|
}
|
|
2199
2199
|
/** Post, term, user or attachment ids of an ACF reference value: ids, numeric strings or `{ ID }` objects. */
|
|
2200
2200
|
const idsOf = (v) => (Array.isArray(v) ? v : [v]).map((x) => typeof x === "number" ? x : typeof x === "string" && /^\d+$/.test(x) ? Number(x) : x && typeof x === "object" ? Number(x.ID ?? x.id ?? x.term_id) : NaN).filter((n) => Number.isSafeInteger(n) && n > 0);
|
|
2201
|
-
|
|
2201
|
+
/** Yoast's and Rank Math's primary category (a term id in post meta); undefined when neither is set. */
|
|
2202
|
+
const PRIMARY_CATEGORY_META = ["_yoast_wpseo_primary_category", "rank_math_primary_category"];
|
|
2203
|
+
function primaryCategoryId(p) {
|
|
2204
|
+
for (const key of PRIMARY_CATEGORY_META) {
|
|
2205
|
+
const v = p.meta[key];
|
|
2206
|
+
const id = typeof v === "number" ? v : typeof v === "string" && /^\d+$/.test(v) ? Number(v) : NaN;
|
|
2207
|
+
if (Number.isSafeInteger(id) && id > 0) return id;
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
/**
|
|
2211
|
+
* The page-type mapping the WordPress readers apply (`pageTypeOf`: Elementor's `e-landing-page` → `page`), applied again
|
|
2212
|
+
* here so a RawIR from any producer — a Bridge export, a hand-built fixture — gets it too, not only one read by
|
|
2213
|
+
* `parseWxr` / `fetchRestRawIR`. Idempotent: an already-mapped RawIR comes back as the same object.
|
|
2214
|
+
*/
|
|
2215
|
+
function withPageTypes(raw) {
|
|
2216
|
+
const postNeeds = raw.posts.some((p) => pageTypeOf(p.type) !== p.type);
|
|
2217
|
+
const commentNeeds = (raw.comments ?? []).some((c) => c.post_type !== void 0 && pageTypeOf(c.post_type) !== c.post_type);
|
|
2218
|
+
if (!postNeeds && !commentNeeds) return raw;
|
|
2219
|
+
return {
|
|
2220
|
+
...raw,
|
|
2221
|
+
posts: postNeeds ? raw.posts.map((p) => pageTypeOf(p.type) === p.type ? p : Object.assign({}, p, { type: pageTypeOf(p.type) })) : raw.posts,
|
|
2222
|
+
...raw.comments && commentNeeds ? { comments: raw.comments.map((c) => c.post_type === void 0 || pageTypeOf(c.post_type) === c.post_type ? c : Object.assign({}, c, { post_type: pageTypeOf(c.post_type) })) } : {}
|
|
2223
|
+
};
|
|
2224
|
+
}
|
|
2225
|
+
function rawToContentrain(input, opts) {
|
|
2226
|
+
const raw = withPageTypes(input);
|
|
2202
2227
|
const updatedBy = opts?.updatedBy ?? "@contentrain/wp-import";
|
|
2203
2228
|
const includeEmails = opts?.includeEmails === true;
|
|
2204
2229
|
const locale = normLocale(raw.site.language) || "en";
|
|
@@ -2771,6 +2796,12 @@ function rawToContentrain(raw, opts) {
|
|
|
2771
2796
|
label: "Sticky",
|
|
2772
2797
|
order: o += 10
|
|
2773
2798
|
};
|
|
2799
|
+
if (taxes.includes("category") && typeItems.some((p) => primaryCategoryId(p) !== void 0)) fields.primary_category = {
|
|
2800
|
+
type: "relation",
|
|
2801
|
+
model: taxModelId("category"),
|
|
2802
|
+
label: "Primary category",
|
|
2803
|
+
order: o += 10
|
|
2804
|
+
};
|
|
2774
2805
|
if (typeItems.some((p) => typeof p.meta._wp_page_template === "string" && p.meta._wp_page_template !== "default")) fields.template = {
|
|
2775
2806
|
type: "string",
|
|
2776
2807
|
label: "Page template",
|
|
@@ -2866,6 +2897,14 @@ function rawToContentrain(raw, opts) {
|
|
|
2866
2897
|
}
|
|
2867
2898
|
if (fields.menu_order && p.menu_order) e.menu_order = p.menu_order;
|
|
2868
2899
|
if (fields.sticky) e.sticky = p.sticky ?? false;
|
|
2900
|
+
if (fields.primary_category) {
|
|
2901
|
+
const termWpId = primaryCategoryId(p);
|
|
2902
|
+
const term = termWpId === void 0 ? void 0 : termById.get(termWpId);
|
|
2903
|
+
const ref = term && term.taxonomy === "category" ? termId("category", term.slug) : void 0;
|
|
2904
|
+
const assigned = ref !== void 0 && Array.isArray(e[taxModelId("category")]) && e[taxModelId("category")].includes(ref);
|
|
2905
|
+
if (ref && assigned && contents[taxModelId("category")]?.[ref]) e.primary_category = ref;
|
|
2906
|
+
else if (termWpId !== void 0) report.dropped_relations++;
|
|
2907
|
+
}
|
|
2869
2908
|
if (fields.template && typeof p.meta._wp_page_template === "string" && p.meta._wp_page_template !== "default") e.template = p.meta._wp_page_template;
|
|
2870
2909
|
if (fields.format) {
|
|
2871
2910
|
const f = p.terms.find((t) => t.taxonomy === "post_format");
|