domma-cms 1.39.0 → 1.41.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/CHANGELOG.md +14 -0
- package/CLAUDE.md +8 -0
- package/admin/css/admin.css +1 -1
- package/admin/dist/domma/domma-tools.css +3 -3
- package/admin/dist/domma/domma-tools.min.js +4 -4
- package/admin/js/app.js +1 -1
- package/admin/js/lib/themes.js +1 -1
- package/admin/js/lib/wordpress-import-arrange.js +1 -1
- package/admin/js/templates/docs/usage-tools.html +18 -3
- package/admin/js/templates/wordpress-import.html +23 -5
- package/admin/js/views/wordpress-import.js +10 -10
- package/docs/DommaFeatures.md +7 -0
- package/package.json +2 -2
- package/server/routes/api/wordpress-import.js +62 -3
- package/server/server.js +1 -1
- package/server/services/themeSettings.js +16 -7
- package/server/services/tools.js +1 -1
- package/server/services/wpImport/crawl.js +619 -0
- package/server/services/wpImport/index.js +53 -8
- package/server/services/wpImport/plan.js +5 -3
- package/server/services/wpImport/platforms.js +186 -0
- package/server/services/wpImport/wxr.js +6 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{apiRequest as
|
|
1
|
+
import{apiRequest as $,getToken as Mo}from"../api.js";import{addBannerAction as To}from"../lib/plugin-chrome.js";import{helpPopovers as Rt}from"../lib/help-popover.js";import{onceClosed as Eo,openMenuAt as B,sidebarCount as q,viewLifetime as $o}from"../lib/tool-kit.js";import{SHAPES as qt,whileLoading as At}from"../lib/loading.js";import{fmtDateTime as So}from"../lib/dates.js";import{applyChoice as Lo,chooseAllPeople as It,choosePerson as Po,choiceItems as Nt,cleanOptions as Ee,counts as Ot,customTypeRows as Co,homeCard as Ro,inviteNote as qo,peopleSummary as Ao,personMenuItems as Io,personRow as No,reportPersonRow as Oo,defaultOptions as Ke,draftKey as Bo,draftQuestion as Do,historyRow as Uo,internalTypeRows as Ho,isDirty as _o,kindTabs as zo,liveDrafts as Bt,optionsSnapshot as Dt,PLAN_FILTERS as Ut,planMatches as Ht,planRow as jo,planTiles as _t,productSummary as Wo,progressPercent as Fo,progressText as Ko,REPORT_FILTERS as zt,reportMatches as jt,reportRow as Zo,stagedRow as Vo,typeMenuItems as Jo,widgetAreaRows as Yo,widgetsFileText as Go,withDraft as Wt,withFooterChoice as Qo,withListPage as Xo,withTypeChoice as es}from"../lib/wordpress-import-arrange.js";const Ft=/^#\/wordpress-import\/?(\?.*)?$/,X="#/wordpress-import",y="/import/wordpress",$e=400,ts=`
|
|
2
2
|
<div class="wpx-row" data-id="{{id}}" tabindex="0">
|
|
3
3
|
<span class="wpx-main"><strong>{{title}}</strong><small>{{meta}}</small></span>
|
|
4
4
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
5
5
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{title}}" title="Actions">\u22EE</button>
|
|
6
|
-
</div>`,
|
|
6
|
+
</div>`,Kt=`
|
|
7
7
|
<div class="wpx-row" data-key="{{key}}" tabindex="0">
|
|
8
8
|
<span class="wpx-main">
|
|
9
9
|
<strong>{{title}}</strong>
|
|
@@ -14,17 +14,17 @@ import{apiRequest as R,getToken as uo}from"../api.js";import{addBannerAction as
|
|
|
14
14
|
</span>
|
|
15
15
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillCls">{{pill}}</span></span>
|
|
16
16
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{title}}" title="Actions">\u22EE</button>
|
|
17
|
-
</div>`,
|
|
17
|
+
</div>`,Zt=`
|
|
18
18
|
<div class="wpx-row" data-from="{{from}}" tabindex="0">
|
|
19
19
|
<span class="wpx-main"><span class="wpx-where">{{from}} \u2192 {{to}}</span><span class="wpx-reason" data-bind-hidden="!reason">{{reason}}</span></span>
|
|
20
20
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
21
21
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{from}}" title="Actions">\u22EE</button>
|
|
22
|
-
</div>`,
|
|
22
|
+
</div>`,as=`
|
|
23
23
|
<div class="wpx-row" data-id="{{id}}" tabindex="0">
|
|
24
24
|
<span class="wpx-main"><strong>{{title}}</strong><small>{{meta}}</small><span class="wpx-reason">{{summary}}</span></span>
|
|
25
25
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
26
26
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{title}}" title="Actions">\u22EE</button>
|
|
27
|
-
</div>`,
|
|
27
|
+
</div>`,os=`
|
|
28
28
|
<div class="wpx-row wpx-type-row" data-type="{{type}}" tabindex="0">
|
|
29
29
|
<span class="wpx-main">
|
|
30
30
|
<strong>{{label}}</strong>
|
|
@@ -42,7 +42,7 @@ import{apiRequest as R,getToken as uo}from"../api.js";import{addBannerAction as
|
|
|
42
42
|
</span>
|
|
43
43
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
44
44
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{label}}" title="Actions">\u22EE</button>
|
|
45
|
-
</div>`,
|
|
45
|
+
</div>`,ss=`
|
|
46
46
|
<div class="wpx-row wpx-person" data-key="{{key}}" tabindex="0">
|
|
47
47
|
<span class="wpx-main">
|
|
48
48
|
<strong>{{name}}</strong>
|
|
@@ -57,12 +57,12 @@ import{apiRequest as R,getToken as uo}from"../api.js";import{addBannerAction as
|
|
|
57
57
|
</span>
|
|
58
58
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
59
59
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{name}}" title="Actions">\u22EE</button>
|
|
60
|
-
</div>`,
|
|
60
|
+
</div>`,ns=`
|
|
61
61
|
<div class="wpx-row" data-key="{{key}}" tabindex="0">
|
|
62
62
|
<span class="wpx-main"><strong>{{name}}</strong><small>{{meta}}</small><span class="wpx-reason" data-bind-hidden="!reason">{{reason}}</span></span>
|
|
63
63
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
64
64
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{name}}" title="Actions">\u22EE</button>
|
|
65
|
-
</div>`,
|
|
65
|
+
</div>`,rs=`
|
|
66
66
|
<div class="wpx-row wpx-widget-row" data-area="{{area}}" tabindex="0">
|
|
67
67
|
<span class="wpx-main">
|
|
68
68
|
<strong>{{label}}</strong>
|
|
@@ -76,7 +76,7 @@ import{apiRequest as R,getToken as uo}from"../api.js";import{addBannerAction as
|
|
|
76
76
|
</span>
|
|
77
77
|
<span class="wpx-chips"><span class="wpx-chip" data-bind-class="pillClass">{{pill}}</span></span>
|
|
78
78
|
<button type="button" class="wpx-kebab" aria-label="Actions for {{label}}" title="Actions">\u22EE</button>
|
|
79
|
-
</div>`,zt='<div class="wpx-tile"><strong>{{value}}</strong><small>{{label}} <span data-bind-hidden="!sub">{{sub}}</span></small></div>',ze='<p class="wpx-alert"><span>{{text}}</span></p>',jt="<li>{{text}}</li>",Go='<div class="wpx-fact"><dt>{{label}}</dt><dd>{{value}}</dd></div>',je='<button type="button" data-on-click="$root.pickSeg($data)" data-bind-class="cls">{{label}} <b>{{count}}</b></button>',b=vo(Ht);function We(u,l,p){return new Promise((g,T)=>{const v=new XMLHttpRequest,A=new FormData;A.append("file",l),v.open("POST",`/api${u}`);const w=uo();w&&v.setRequestHeader("Authorization",`Bearer ${w}`),v.upload.onprogress=m=>{m.lengthComputable&&p(m.loaded/m.total)},v.onload=()=>{let m=null;try{m=JSON.parse(v.responseText)}catch{}v.status>=200&&v.status<300?g(m):T(new Error(m?.error||`The upload failed (${v.status}).`))},v.onerror=()=>T(new Error("The upload failed - the connection dropped.")),v.send(A),b.add(()=>{v.readyState!==4&&v.abort()})})}const Me=u=>u>=1048576?`${Math.round(u/1048576)} MB`:`${Math.max(1,Math.round(u/1024))} KB`,G=u=>String(u??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function Jo(u){const l=document.createElement("template");return l.innerHTML=u.trim(),l.content.firstElementChild}async function Te(u,l){const p=E.confirm(u,l);let g=null;try{g=[...document.querySelectorAll(".dm-dialog-overlay")].at(-1)??null}catch{}const T=b.add(()=>{if(!g)return;const v=g;g=null;try{v.querySelector(".dm-dialog-cancel")?.click(),v.remove()}catch{}});try{return await p}finally{g=null,T()}}function Fe(u){navigator.clipboard?.writeText(u).then(()=>E.toast("Copied.",{type:"success"}),()=>E.toast(u,{type:"info",duration:8e3}))}function U(u,l,p,g){const T=E.contextMenu(u,{cursor:"glyph",match:l,inherit:!1,density:"compact",items:p});b.add(()=>T?.destroy?.());const v=w=>{const m=w.target.closest(l);if(!m||!u.contains(m))return;const d=w.target.closest(".wpx-kebab");if(d){B(d);return}g?.(m)},A=w=>{const m=w.target.closest(l);m&&(w.key==="F10"&&w.shiftKey?(w.preventDefault(),B(m)):w.key==="Enter"&&w.target===m&&g&&(w.preventDefault(),w.stopPropagation(),g(m)))};u.addEventListener("click",v),u.addEventListener("keydown",A),b.add(()=>{u.removeEventListener("click",v),u.removeEventListener("keydown",A)})}export const wordpressImportView={templateUrl:"/admin/js/templates/wordpress-import.html",async onMount(u){b.reset();const l=u.get(0).querySelector(".wpx")||u.get(0),p=()=>Ht.test(location.hash)&&l.isConnected;let g="";try{g=S.get("auth_user")?.id||""}catch{}const T=$o(g),v=()=>{try{return T?S.get(T):null}catch{return null}},A=e=>{try{T&&S.set(T,e)}catch{}},w=l.querySelector(".wpx-loading");let m;try{m=await St(w,R(`${P}/status`),$t.rows)}catch(e){if(!l.isConnected)return;w&&(w.hidden=!0);const t=l.querySelector(".wpx-failed");t&&(t.textContent=`Could not load the importer: ${e.message||e}. Reload the page to try again.`,t.hidden=!1);return}if(!p())return;w&&(w.hidden=!0),l.querySelector(".wpx-body").hidden=!1;const d=M.observable(m.staged||[]),_=M.observable(m.history||[]),J=M.observable(m.blog||{available:!1}),Ke=M.observable(m.shop||{available:!1}),z=m.limits||{},Ze=m.people?.defaultRole||"",y=M.observable(m.running||null),h=M.observable(""),f=M.observable(null),pe=M.observable(!1),Ee=M.observable(!1),$e=M.observable(""),i=M.observable(_e(J.peek().available)),j=M.observable("all"),D=M.observable(""),Q=M.observable(""),ce=M.observable(""),X=M.observable(""),de=M.observable(""),ue=M.observable(!1);let me=!0;const Qo=()=>d.peek().find(e=>e.id===h.peek())||null,ee=M.computed(()=>d.value.find(e=>e.id===h.value)||null),Wt=M.computed(()=>h.value?"preview":"start"),H=M.computed(()=>!!J.value.available),Ft=M.computed(()=>!!(f.value?.shop||Ke.value).available),Ve=M.computed(()=>!!h.value&&Co(i.value,H.value)),W=e=>M.computed({read:()=>i.value[e]!==!1,write:t=>{i.value={...i.peek(),[e]:!!t}}}),$=e=>{i.value={...i.peek(),...e}},te=e=>{try{return wo(e)}catch{return e}},Kt=M.computed(()=>d.value.map(e=>Bo(e,te))),Zt=M.computed(()=>_.value.map(e=>Lo(e,te))),F=M.computed(()=>(f.value?.items||[]).map(e=>({...e,choice:i.value.choices?.[e.key]}))),Vt=M.computed(()=>Ro(F.value).map(e=>({...e,cls:D.value===e.id?"is-on":"",seg:"kind"}))),Yt=M.computed(()=>Ct(F.value,At,It,D.value)),Gt=M.computed(()=>At.map(e=>({...e,count:Yt.value[e.id],cls:j.value===e.id?"is-on":"",seg:"filter"}))),Se=M.computed(()=>{const e=Q.value.trim().toLowerCase();return F.value.filter(t=>(!D.value||t.kind===D.value)&&It(t,j.value)&&(!e||`${t.title} ${t.target} ${t.oldUrl} ${t.postType||""}`.toLowerCase().includes(e)))}),Jt=M.computed(()=>Se.value.slice(0,ke).map(e=>{const t=qo(e);return{...t,pillCls:`${t.pillClass}${e.choice?" is-chosen":""}`}})),Qt=M.computed(()=>Se.value.length>ke?`Showing the first ${ke} of ${Se.value.length} - search or filter to find the rest.`:""),Xt=M.computed(()=>F.value.length?"Nothing matches.":"This export has nothing to import."),ea=M.computed(()=>Nt(f.value)),ta=M.computed(()=>(f.value?.notes||[]).map(e=>({text:e}))),aa=M.computed(()=>(f.value?.redirects||[]).slice(0,ke).map(e=>({...e,pill:e.action==="skip"?"Skipped":e.action==="update"?"Update":"New",pillClass:e.action==="skip"?"is-muted":"is-ok"}))),oa=M.computed(()=>String((f.value?.redirects||[]).filter(e=>e.action!=="skip").length)),sa=M.computed(()=>f.value?.site?.title||ee.value?.siteTitle||"WordPress export"),na=M.computed(()=>{const e=ee.value,t=f.value?.site;return[t?.url||e?.siteUrl,e?.fileName,t?.wxrVersion&&`WXR ${t.wxrVersion}`,e?.at&&`uploaded ${te(e.at)}`].filter(Boolean).join(" \xB7 ")}),ae=M.computed(()=>Ao(f.value)),la=M.computed(()=>ae.value?.note||""),ra=M.computed(()=>ae.value?.tone==="warn"?"is-warn":"is-info"),ia=M.computed(()=>(ae.value?.rows||[]).map(e=>({...e,id:e.label}))),pa=M.computed(()=>(ae.value?.notes||[]).map(e=>({text:e}))),ca=M.computed(()=>!!ae.value),x=M.computed(()=>yo(f.value)),da=M.computed(()=>!!x.value),ua=M.computed(()=>x.value?.wp||""),ma=M.computed(()=>x.value?.now||""),ha=M.computed(()=>x.value?.after||""),va=M.computed(()=>x.value?.tone==="warn"?"":"is-info"),wa=M.computed(()=>(x.value?.notes||[]).map(e=>({text:e}))),fa=M.computed(()=>x.value?.editNow||""),ba=M.computed(()=>!!x.value?.frontSwitch),ga=M.computed(()=>!!x.value?.latestSwitch),ya=M.computed(()=>!!x.value?.postsSwitch),xa=M.computed(()=>x.value?.postsText||""),Ye=M.computed(()=>x.value?.question||""),Ge=M.computed(()=>!!Ye.value&&typeof i.value.homeReplace!="boolean"),ka=M.computed({read:()=>i.value.latestPosts===!0,write:e=>$({latestPosts:!!e})}),Ma=M.computed({read:()=>!!x.value?.postsId&&i.value.postsPage===x.value.postsId,write:e=>$({postsPage:e&&x.peek()?.postsId||0})}),Le=M.computed(()=>go(f.value)),Pe=M.computed(()=>Po(f.value)),Ta=M.computed(()=>!!(Le.value.length||Pe.value.length)),Ea=M.computed(()=>{const e=Pe.value.length;return e?`Not imported: ${e} kind${e===1?"":"s"} of WordPress or plugin housekeeping`:""}),L=M.computed(()=>f.value?.people||null),$a=M.computed(()=>!!L.value?.rows?.length),Sa=M.computed(()=>(L.value?.rows||[]).map(To)),La=M.computed(()=>!!L.value?.canCreate),Pa=M.computed(()=>(L.value?.rows||[]).some(e=>e.choosable)),Je=M.computed(()=>ko(L.value)),Ca=M.computed(()=>Je.value.text),Ra=M.computed(()=>Je.value.tone==="warn"?"is-warn":"is-info"),qa=M.computed(()=>!!(L.value?.canCreate&&L.value?.mailReady&&L.value?.counts?.create)),Aa=M.computed(()=>xo(L.value)),Ia=M.computed({read:()=>i.value.invite===!0,write:e=>{i.value={...i.peek(),invite:!!e}}}),Na=M.computed(()=>H.value?`Posts go to ${J.value.basePath||"/blog"}.`:J.value.reason||"No Blog is switched on here."),he=M.computed(()=>ee.value?.uploads||null),Oa=M.computed(()=>{const e=he.value;return e?`${e.fileName} - ${e.files} file${e.files===1?"":"s"}, ${Me(e.size)}${e.unsafe?`. ${e.unsafe} with unsafe names (like ../) were ignored`:""}.`:`Zip the wp-content/uploads folder and upload it here (up to ${Me(z.uploads||0)}).`}),Ba=M.computed(()=>he.value?"Replace the zip":"Upload the uploads zip"),Qe=M.computed(()=>ee.value?.widgets||null),Da=M.computed(()=>Uo(ee.value,z.widgets||0)),Ha=M.computed(()=>Qe.value?"Replace the widgets file":"Upload the widgets file"),Ce=M.observable(""),Xe=M.computed(()=>Ho(f.value)),Ua=M.computed(()=>Ge.value?"Answer the home page question first.":""),et=M.computed(()=>!!f.value&&!y.value&&!pe.value&&!(i.value.media==="zip"&&!he.value)&&!Ge.value),_a=M.computed(()=>y.value?`Importing${y.value.siteTitle?` ${y.value.siteTitle}`:""}\u2026`:""),za=M.computed(()=>No(y.value)),tt=M.computed(()=>Io(y.value)),ja=M.observable(Me(z.wxr||0)),at=l.querySelector(".wpx-running .wpx-bar-fill");b.add(M.effect(()=>{at&&(at.style.width=`${tt.value}%`)}));async function Re(){const e=await R(`${P}/status`);return p()?(d.value=e.staged||[],_.value=e.history||[],J.value=e.blog||{available:!1},Ke.value=e.shop||{available:!1},e.running&&!y.peek()&&(y.value=e.running,se()),e):null}let ve=0,qe=null;async function K({first:e=!1}={}){const t=h.peek();if(!t)return;const a=++ve;$e.value="";const o=R(`${P}/staged/${t}/preview`,{method:"POST",body:JSON.stringify({options:xe(i.peek(),H.peek())})});try{let r;if(e?(pe.value=!0,r=await St(l.querySelector(".wpx-plan-loading"),o,$t.table)):(Ee.value=!0,r=await o),a!==ve||!p()||h.peek()!==t)return;f.value=r.plan}catch(r){if(a!==ve||!p())return;if(r.status===404){E.toast("That upload has gone - upload the export again.",{type:"warning"}),oe(),Re().catch(()=>{});return}$e.value=`Could not read the export: ${r.message||r}`}finally{a===ve&&(pe.value=!1,Ee.value=!1)}}let we="";b.add(M.effect(()=>{const e=`${h.value}|${qt(i.value)}`;if(e===we)return;const t=we.split("|")[0];we=e,!(!h.value||t!==h.value)&&(clearTimeout(qe),qe=setTimeout(()=>K(),250))})),b.add(()=>clearTimeout(qe)),b.add(M.effect(()=>{const e=h.value,t=i.value,a=Ve.value;if(!e||!me||!T)return;const o=v();A(Dt(o,g,e,a?{options:xe(t,!0),at:new Date().toISOString(),was:e}:null))}));const Ae=e=>{T&&A(Dt(v(),g,e,null))};async function fe(e){if(!d.peek().some(c=>c.id===e))return;const t=d.peek().find(c=>c.id===e),a=Rt(v(),d.peek().map(c=>c.id),g).items[e];if(me=!a,f.value=null,j.value="all",D.value="",Q.value="",i.value=_e(H.peek()),we=`${e}|${qt(i.peek())}`,h.value=e,await K({first:!0}),!p()||h.peek()!==e||!a)return;await new Promise(c=>setTimeout(c,0));const o=So({when:a.at?te(a.at):"",file:t?.fileName||""}),r=await Te(G(o.text),{title:o.title,confirmText:o.confirmText,cancelText:o.cancelText});!p()||h.peek()!==e||(me=!0,r?Ae(e):i.value=xe(a.options,H.peek()))}function oe(){h.value="",f.value=null,me=!0}async function ot(e=h.peek()){const t=d.peek().find(a=>a.id===e);if(t&&await Te(`Discard the upload of <strong>${G(t.siteTitle||t.fileName)}</strong>? Nothing has been imported from it.`,{title:"Discard upload",confirmText:"Discard",danger:!0}))try{if(await R(`${P}/staged/${e}`,{method:"DELETE"}),Ae(e),!p())return;h.peek()===e&&oe(),d.value=d.peek().filter(a=>a.id!==e),q(ie)}catch(a){E.toast(`Not discarded: ${a.message||a}`,{type:"error"})}}async function st(e){if(!e)return;if(X.value="",!/\.(xml|zip)$/i.test(e.name)){X.value="Upload the .xml file WordPress exports, or a .zip holding it.";return}if(z.wxr&&e.size>z.wxr*1.2&&/\.xml$/i.test(e.name)){X.value=`That file is over ${Me(z.wxr)}.`;return}const t=l.querySelector(".wpx-start .wpx-upload .wpx-bar-fill");ce.value=`Uploading ${e.name}\u2026`;try{const a=await We(`${P}/upload`,e,o=>{t&&(t.style.width=`${Math.round(o*100)}%`),ce.value=o<1?`Uploading ${e.name} - ${Math.round(o*100)}%`:`Reading ${e.name}\u2026`});if(!p())return;d.value=[a,...d.peek().filter(o=>o.id!==a.id)],q(ie),await fe(a.id)}catch(a){p()&&(X.value=a.message||String(a))}finally{p()&&(ce.value="",t&&(t.style.width="0"))}}async function Wa(e){const t=h.peek();if(!e||!t)return;if(!/\.zip$/i.test(e.name)){E.toast("Zip the wp-content/uploads folder and upload the .zip.",{type:"warning"});return}const a=l.querySelector(".wpx-zip-fill");de.value=`Uploading ${e.name}\u2026`;try{const o=await We(`${P}/staged/${t}/uploads`,e,r=>{a&&(a.style.width=`${Math.round(r*100)}%`),de.value=r<1?`Uploading ${e.name} - ${Math.round(r*100)}%`:`Checking ${e.name}\u2026`});if(!p())return;d.value=d.peek().map(r=>r.id===o.id?o:r),h.peek()===t&&K()}catch(o){p()&&E.toast(o.message||String(o),{type:"error"})}finally{p()&&(de.value="",a&&(a.style.width="0"))}}async function Fa(e){const t=h.peek();if(!(!e||!t)){if(!/\.(wie|json)$/i.test(e.name)){E.toast('Upload the .wie file the "Widget Importer & Exporter" plugin exports.',{type:"warning"});return}Ce.value=`Reading ${e.name}\u2026`;try{const a=await We(`${P}/staged/${t}/widgets`,e,()=>{});if(!p())return;d.value=d.peek().map(o=>o.id===a.id?a:o),h.peek()===t&&K()}catch(a){p()&&E.toast(a.message||String(a),{type:"error"})}finally{p()&&(Ce.value="")}}}async function Ka(){const e=h.peek();try{const t=await R(`${P}/staged/${e}/widgets`,{method:"DELETE"});if(!p())return;d.value=d.peek().map(a=>a.id===t.id?t:a),K()}catch(t){E.toast(`Not removed: ${t.message||t}`,{type:"error"})}}async function Za(){const e=h.peek();try{const t=await R(`${P}/staged/${e}/uploads`,{method:"DELETE"});if(!p())return;d.value=d.peek().map(a=>a.id===t.id?t:a),K()}catch(t){E.toast(`Not removed: ${t.message||t}`,{type:"error"})}}async function Va(){const e=h.peek(),t=f.peek();if(!e||!t||!et.peek())return;const o=Nt(t).filter(c=>c.value&&c.id!=="comments").map(c=>`${c.value} ${c.label.toLowerCase()}`);if(!(!await Te(`Import <strong>${G(t.site?.title||"this export")}</strong>: ${G(o.join(", ")||"nothing new")}? Pages edited here since an earlier import are left alone unless you chose Overwrite.`,{title:"Run the import",confirmText:"Run import"})||!p()||h.peek()!==e))try{const c=await R(`${P}/staged/${e}/run`,{method:"POST",body:JSON.stringify({options:xe(i.peek(),H.peek())})});if(Ae(e),!p())return;y.value={...c.job,siteTitle:t.site?.title||""},oe(),q(ie),se()}catch(c){E.toast(`The import did not start: ${c.message||c}`,{type:"error"})}}let Ie=null;function se(){clearTimeout(Ie);const e=y.peek();e&&(Ie=setTimeout(async()=>{try{const t=await R(`${P}/jobs/${e.id}`);if(!p())return;if(y.value={...t.job,siteTitle:e.siteTitle},t.job.status==="running")return se();if(y.value=null,await Re().catch(()=>{}),q(ie),q("#/pages"),q("#/media"),q("#/plugins/shopping-cart"),q("#/collections"),q("#/blocks"),!p())return;t.job.status==="done"?(E.toast("The import has finished - here is its report.",{type:"success"}),be(t.job.reportId)):(E.toast(`The import stopped: ${t.job.error||"an error"}`,{type:"error"}),t.job.reportId&&be(t.job.reportId))}catch(t){if(!p())return;if(t.status===404){y.value=null,Re().catch(()=>{});return}se()}},700))}b.add(()=>clearTimeout(Ie)),y.peek()&&se();let Z=!1;async function be(e){if(Z||!e)return;Z=!0;let t;try{t=await R(`${P}/history/${e}`)}catch(s){Z=!1,E.toast(`Could not open the report: ${s.message||s}`,{type:"error"});return}if(!p()){Z=!1;return}let a;try{a=E.slideover({title:G(`Report - ${t.run?.siteTitle||"WordPress import"}`),size:"lg",position:"right"})}catch(s){throw Z=!1,s}const o=Jo(`
|
|
79
|
+
</div>`,Vt='<div class="wpx-tile"><strong>{{value}}</strong><small>{{label}} <span data-bind-hidden="!sub">{{sub}}</span></small></div>',Ze='<p class="wpx-alert"><span>{{text}}</span></p>',Jt="<li>{{text}}</li>",ls='<div class="wpx-fact"><dt>{{label}}</dt><dd>{{value}}</dd></div>',Ve='<button type="button" data-on-click="$root.pickSeg($data)" data-bind-class="cls">{{label}} <b>{{count}}</b></button>',f=$o(Ft);function Je(m,r,i){return new Promise((g,L)=>{const w=new XMLHttpRequest,A=new FormData;A.append("file",r),w.open("POST",`/api${m}`);const b=Mo();b&&w.setRequestHeader("Authorization",`Bearer ${b}`),w.upload.onprogress=u=>{u.lengthComputable&&i(u.loaded/u.total)},w.onload=()=>{let u=null;try{u=JSON.parse(w.responseText)}catch{}w.status>=200&&w.status<300?g(u):L(new Error(u?.error||`The upload failed (${w.status}).`))},w.onerror=()=>L(new Error("The upload failed - the connection dropped.")),w.send(A),f.add(()=>{w.readyState!==4&&w.abort()})})}const Se=m=>m>=1048576?`${Math.round(m/1048576)} MB`:`${Math.max(1,Math.round(m/1024))} KB`,ee=m=>String(m??"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""");function is(m){const r=document.createElement("template");return r.innerHTML=m.trim(),r.content.firstElementChild}async function Le(m,r){const i=E.confirm(m,r);let g=null;try{g=[...document.querySelectorAll(".dm-dialog-overlay")].at(-1)??null}catch{}const L=f.add(()=>{if(!g)return;const w=g;g=null;try{w.querySelector(".dm-dialog-cancel")?.click(),w.remove()}catch{}});try{return await i}finally{g=null,L()}}function Ye(m){navigator.clipboard?.writeText(m).then(()=>E.toast("Copied.",{type:"success"}),()=>E.toast(m,{type:"info",duration:8e3}))}function z(m,r,i,g){const L=E.contextMenu(m,{cursor:"glyph",match:r,inherit:!1,density:"compact",items:i});f.add(()=>L?.destroy?.());const w=b=>{const u=b.target.closest(r);if(!u||!m.contains(u))return;const p=b.target.closest(".wpx-kebab");if(p){B(p);return}g?.(u)},A=b=>{const u=b.target.closest(r);u&&(b.key==="F10"&&b.shiftKey?(b.preventDefault(),B(u)):b.key==="Enter"&&b.target===u&&g&&(b.preventDefault(),b.stopPropagation(),g(u)))};m.addEventListener("click",w),m.addEventListener("keydown",A),f.add(()=>{m.removeEventListener("click",w),m.removeEventListener("keydown",A)})}export const wordpressImportView={templateUrl:"/admin/js/templates/wordpress-import.html",async onMount(m){f.reset();const r=m.get(0).querySelector(".wpx")||m.get(0),i=()=>Ft.test(location.hash)&&r.isConnected;let g="";try{g=S.get("auth_user")?.id||""}catch{}const L=Bo(g),w=()=>{try{return L?S.get(L):null}catch{return null}},A=e=>{try{L&&S.set(L,e)}catch{}},b=r.querySelector(".wpx-loading");let u;try{u=await At(b,$(`${y}/status`),qt.rows)}catch(e){if(!r.isConnected)return;b&&(b.hidden=!0);const t=r.querySelector(".wpx-failed");t&&(t.textContent=`Could not load the importer: ${e.message||e}. Reload the page to try again.`,t.hidden=!1);return}if(!i())return;b&&(b.hidden=!0),r.querySelector(".wpx-body").hidden=!1;const p=M.observable(u.staged||[]),j=M.observable(u.history||[]),te=M.observable(u.blog||{available:!1}),Ge=M.observable(u.shop||{available:!1}),W=u.limits||{},Qe=u.people?.defaultRole||"",x=M.observable(u.running||null),h=M.observable(""),v=M.observable(null),de=M.observable(!1),Pe=M.observable(!1),Ce=M.observable(""),c=M.observable(Ke(te.peek().available)),F=M.observable("all"),D=M.observable(""),ae=M.observable(""),ue=M.observable(""),oe=M.observable(""),me=M.observable(""),he=M.observable(!1),U=M.observable(u.crawl||null),we=M.observable(""),ve=M.observable(""),Yt=M.computed(()=>U.value?.status==="running"),Gt=M.computed(()=>!!String(we.value||"").trim()),Qt=M.computed(()=>{const e=U.value;if(!e)return"";const t=e.found?` - ${e.read} of ${e.found} page${e.found===1?"":"s"} read${e.failed?`, ${e.failed} could not be read`:""}`:"";return`${e.phase||"Reading"} on ${e.url}${t}\u2026`});let fe=!0;const cs=()=>p.peek().find(e=>e.id===h.peek())||null,K=M.computed(()=>p.value.find(e=>e.id===h.value)||null),Xt=M.computed(()=>h.value?"preview":"start"),H=M.computed(()=>!!te.value.available),ea=M.computed(()=>!!(v.value?.shop||Ge.value).available),Xe=M.computed(()=>!!h.value&&_o(c.value,H.value)),Z=e=>M.computed({read:()=>c.value[e]!==!1,write:t=>{c.value={...c.peek(),[e]:!!t}}}),P=e=>{c.value={...c.peek(),...e}},_=e=>{try{return So(e)}catch{return e}},ta=M.computed(()=>p.value.map(e=>Vo(e,_))),aa=M.computed(()=>j.value.map(e=>Uo(e,_))),V=M.computed(()=>(v.value?.items||[]).map(e=>({...e,choice:c.value.choices?.[e.key]}))),oa=M.computed(()=>zo(V.value).map(e=>({...e,cls:D.value===e.id?"is-on":"",seg:"kind"}))),sa=M.computed(()=>Ot(V.value,Ut,Ht,D.value)),na=M.computed(()=>Ut.map(e=>({...e,count:sa.value[e.id],cls:F.value===e.id?"is-on":"",seg:"filter"}))),Re=M.computed(()=>{const e=ae.value.trim().toLowerCase();return V.value.filter(t=>(!D.value||t.kind===D.value)&&Ht(t,F.value)&&(!e||`${t.title} ${t.target} ${t.oldUrl} ${t.postType||""}`.toLowerCase().includes(e)))}),ra=M.computed(()=>Re.value.slice(0,$e).map(e=>{const t=jo(e);return{...t,pillCls:`${t.pillClass}${e.choice?" is-chosen":""}`}})),la=M.computed(()=>Re.value.length>$e?`Showing the first ${$e} of ${Re.value.length} - search or filter to find the rest.`:""),ia=M.computed(()=>V.value.length?"Nothing matches.":"This export has nothing to import."),ca=M.computed(()=>_t(v.value)),pa=M.computed(()=>(v.value?.notes||[]).map(e=>({text:e}))),da=M.computed(()=>(v.value?.redirects||[]).slice(0,$e).map(e=>({...e,pill:e.action==="skip"?"Skipped":e.action==="update"?"Update":"New",pillClass:e.action==="skip"?"is-muted":"is-ok"}))),ua=M.computed(()=>String((v.value?.redirects||[]).filter(e=>e.action!=="skip").length)),ma=M.computed(()=>v.value?.site?.title||K.value?.siteTitle||"WordPress export"),et=M.computed(()=>(v.value?.site?.platform||K.value?.platform||"wordpress")==="wordpress"),ha=M.computed(()=>{const e=K.value,t=v.value?.site;return e?.source==="crawl"?[t?.url||e?.siteUrl,e?.at&&`read from the live site ${_(e.at)}`].filter(Boolean).join(" \xB7 "):et.value?[t?.url||e?.siteUrl,e?.fileName,t?.wxrVersion&&`WXR ${t.wxrVersion}`,e?.at&&`uploaded ${_(e.at)}`].filter(Boolean).join(" \xB7 "):[t?.url||e?.siteUrl,e?.fileName,`${t?.platformName||e?.platformName} export`,e?.at&&`uploaded ${_(e.at)}`].filter(Boolean).join(" \xB7 ")}),se=M.computed(()=>Wo(v.value)),wa=M.computed(()=>se.value?.note||""),va=M.computed(()=>se.value?.tone==="warn"?"is-warn":"is-info"),fa=M.computed(()=>(se.value?.rows||[]).map(e=>({...e,id:e.label}))),ba=M.computed(()=>(se.value?.notes||[]).map(e=>({text:e}))),ga=M.computed(()=>!!se.value),k=M.computed(()=>Ro(v.value)),ya=M.computed(()=>!!k.value),xa=M.computed(()=>k.value?.wp||""),ka=M.computed(()=>k.value?.now||""),Ma=M.computed(()=>k.value?.after||""),Ta=M.computed(()=>k.value?.tone==="warn"?"":"is-info"),Ea=M.computed(()=>(k.value?.notes||[]).map(e=>({text:e}))),$a=M.computed(()=>k.value?.editNow||""),Sa=M.computed(()=>!!k.value?.frontSwitch),La=M.computed(()=>!!k.value?.latestSwitch),Pa=M.computed(()=>!!k.value?.postsSwitch),Ca=M.computed(()=>k.value?.postsText||""),tt=M.computed(()=>k.value?.question||""),at=M.computed(()=>!!tt.value&&typeof c.value.homeReplace!="boolean"),Ra=M.computed({read:()=>c.value.latestPosts===!0,write:e=>P({latestPosts:!!e})}),qa=M.computed({read:()=>!!k.value?.postsId&&c.value.postsPage===k.value.postsId,write:e=>P({postsPage:e&&k.peek()?.postsId||0})}),qe=M.computed(()=>Co(v.value)),Ae=M.computed(()=>Ho(v.value)),Aa=M.computed(()=>!!(qe.value.length||Ae.value.length)),Ia=M.computed(()=>{const e=Ae.value.length;return e?`Not imported: ${e} kind${e===1?"":"s"} of WordPress or plugin housekeeping`:""}),C=M.computed(()=>v.value?.people||null),Na=M.computed(()=>!!C.value?.rows?.length),Oa=M.computed(()=>(C.value?.rows||[]).map(No)),Ba=M.computed(()=>!!C.value?.canCreate),Da=M.computed(()=>(C.value?.rows||[]).some(e=>e.choosable)),ot=M.computed(()=>Ao(C.value)),Ua=M.computed(()=>ot.value.text),Ha=M.computed(()=>ot.value.tone==="warn"?"is-warn":"is-info"),_a=M.computed(()=>!!(C.value?.canCreate&&C.value?.mailReady&&C.value?.counts?.create)),za=M.computed(()=>qo(C.value)),ja=M.computed({read:()=>c.value.invite===!0,write:e=>{c.value={...c.peek(),invite:!!e}}}),Wa=M.computed(()=>H.value?`Posts go to ${te.value.basePath||"/blog"}.`:te.value.reason||"No Blog is switched on here."),be=M.computed(()=>K.value?.uploads||null),Fa=M.computed(()=>{const e=be.value;return e?`${e.fileName} - ${e.files} file${e.files===1?"":"s"}, ${Se(e.size)}${e.unsafe?`. ${e.unsafe} with unsafe names (like ../) were ignored`:""}.`:`Zip the wp-content/uploads folder and upload it here (up to ${Se(W.uploads||0)}).`}),Ka=M.computed(()=>be.value?"Replace the zip":"Upload the uploads zip"),st=M.computed(()=>K.value?.widgets||null),Za=M.computed(()=>Go(K.value,W.widgets||0)),Va=M.computed(()=>st.value?"Replace the widgets file":"Upload the widgets file"),Ie=M.observable(""),nt=M.computed(()=>Yo(v.value)),Ja=M.computed(()=>at.value?"Answer the home page question first.":""),rt=M.computed(()=>!!v.value&&!x.value&&!de.value&&!(c.value.media==="zip"&&!be.value)&&!at.value),Ya=M.computed(()=>x.value?`Importing${x.value.siteTitle?` ${x.value.siteTitle}`:""}\u2026`:""),Ga=M.computed(()=>Ko(x.value)),lt=M.computed(()=>Fo(x.value)),Qa=M.observable(Se(W.wxr||0)),it=r.querySelector(".wpx-running .wpx-bar-fill");f.add(M.effect(()=>{it&&(it.style.width=`${lt.value}%`)}));async function Ne(){const e=await $(`${y}/status`);return i()?(p.value=e.staged||[],j.value=e.history||[],te.value=e.blog||{available:!1},Ge.value=e.shop||{available:!1},e.running&&!x.peek()&&(x.value=e.running,le()),e):null}let ge=0,Oe=null;async function J({first:e=!1}={}){const t=h.peek();if(!t)return;const a=++ge;Ce.value="";const o=$(`${y}/staged/${t}/preview`,{method:"POST",body:JSON.stringify({options:Ee(c.peek(),H.peek())})});try{let l;if(e?(de.value=!0,l=await At(r.querySelector(".wpx-plan-loading"),o,qt.table)):(Pe.value=!0,l=await o),a!==ge||!i()||h.peek()!==t)return;v.value=l.plan}catch(l){if(a!==ge||!i())return;if(l.status===404){E.toast("That upload has gone - upload the export again.",{type:"warning"}),re(),Ne().catch(()=>{});return}Ce.value=`Could not read the export: ${l.message||l}`}finally{a===ge&&(de.value=!1,Pe.value=!1)}}let ye="";f.add(M.effect(()=>{const e=`${h.value}|${Dt(c.value)}`;if(e===ye)return;const t=ye.split("|")[0];ye=e,!(!h.value||t!==h.value)&&(clearTimeout(Oe),Oe=setTimeout(()=>J(),250))})),f.add(()=>clearTimeout(Oe)),f.add(M.effect(()=>{const e=h.value,t=c.value,a=Xe.value;if(!e||!fe||!L)return;const o=w();A(Wt(o,g,e,a?{options:Ee(t,!0),at:new Date().toISOString(),was:e}:null))}));const Be=e=>{L&&A(Wt(w(),g,e,null))};async function ne(e){if(!p.peek().some(d=>d.id===e))return;const t=p.peek().find(d=>d.id===e),a=Bt(w(),p.peek().map(d=>d.id),g).items[e];if(fe=!a,v.value=null,F.value="all",D.value="",ae.value="",c.value=Ke(H.peek()),ye=`${e}|${Dt(c.peek())}`,h.value=e,await J({first:!0}),!i()||h.peek()!==e||!a)return;await new Promise(d=>setTimeout(d,0));const o=Do({when:a.at?_(a.at):"",file:t?.fileName||""}),l=await Le(ee(o.text),{title:o.title,confirmText:o.confirmText,cancelText:o.cancelText});!i()||h.peek()!==e||(fe=!0,l?Be(e):c.value=Ee(a.options,H.peek()))}function re(){h.value="",v.value=null,fe=!0}async function ct(e=h.peek()){const t=p.peek().find(a=>a.id===e);if(t&&await Le(`Discard the upload of <strong>${ee(t.siteTitle||t.fileName)}</strong>? Nothing has been imported from it.`,{title:"Discard upload",confirmText:"Discard",danger:!0}))try{if(await $(`${y}/staged/${e}`,{method:"DELETE"}),Be(e),!i())return;h.peek()===e&&re(),p.value=p.peek().filter(a=>a.id!==e),q(X)}catch(a){E.toast(`Not discarded: ${a.message||a}`,{type:"error"})}}async function pt(e){if(!e)return;if(oe.value="",!/\.(xml|zip)$/i.test(e.name)){oe.value="Upload the .xml file WordPress exports, or a .zip holding it.";return}if(W.wxr&&e.size>W.wxr*1.2&&/\.xml$/i.test(e.name)){oe.value=`That file is over ${Se(W.wxr)}.`;return}const t=r.querySelector(".wpx-start .wpx-upload .wpx-bar-fill");ue.value=`Uploading ${e.name}\u2026`;try{const a=await Je(`${y}/upload`,e,o=>{t&&(t.style.width=`${Math.round(o*100)}%`),ue.value=o<1?`Uploading ${e.name} - ${Math.round(o*100)}%`:`Reading ${e.name}\u2026`});if(!i())return;p.value=[a,...p.peek().filter(o=>o.id!==a.id)],q(X),await ne(a.id)}catch(a){i()&&(oe.value=a.message||String(a))}finally{i()&&(ue.value="",t&&(t.style.width="0"))}}async function Xa(e){const t=h.peek();if(!e||!t)return;if(!/\.zip$/i.test(e.name)){E.toast("Zip the wp-content/uploads folder and upload the .zip.",{type:"warning"});return}const a=r.querySelector(".wpx-zip-fill");me.value=`Uploading ${e.name}\u2026`;try{const o=await Je(`${y}/staged/${t}/uploads`,e,l=>{a&&(a.style.width=`${Math.round(l*100)}%`),me.value=l<1?`Uploading ${e.name} - ${Math.round(l*100)}%`:`Checking ${e.name}\u2026`});if(!i())return;p.value=p.peek().map(l=>l.id===o.id?o:l),h.peek()===t&&J()}catch(o){i()&&E.toast(o.message||String(o),{type:"error"})}finally{i()&&(me.value="",a&&(a.style.width="0"))}}async function eo(e){const t=h.peek();if(!(!e||!t)){if(!/\.(wie|json)$/i.test(e.name)){E.toast('Upload the .wie file the "Widget Importer & Exporter" plugin exports.',{type:"warning"});return}Ie.value=`Reading ${e.name}\u2026`;try{const a=await Je(`${y}/staged/${t}/widgets`,e,()=>{});if(!i())return;p.value=p.peek().map(o=>o.id===a.id?a:o),h.peek()===t&&J()}catch(a){i()&&E.toast(a.message||String(a),{type:"error"})}finally{i()&&(Ie.value="")}}}async function to(){const e=h.peek();try{const t=await $(`${y}/staged/${e}/widgets`,{method:"DELETE"});if(!i())return;p.value=p.peek().map(a=>a.id===t.id?t:a),J()}catch(t){E.toast(`Not removed: ${t.message||t}`,{type:"error"})}}async function ao(){const e=h.peek();try{const t=await $(`${y}/staged/${e}/uploads`,{method:"DELETE"});if(!i())return;p.value=p.peek().map(a=>a.id===t.id?t:a),J()}catch(t){E.toast(`Not removed: ${t.message||t}`,{type:"error"})}}async function oo(){const e=h.peek(),t=v.peek();if(!e||!t||!rt.peek())return;const o=_t(t).filter(d=>d.value&&d.id!=="comments").map(d=>`${d.value} ${d.label.toLowerCase()}`);if(!(!await Le(`Import <strong>${ee(t.site?.title||"this export")}</strong>: ${ee(o.join(", ")||"nothing new")}? Pages edited here since an earlier import are left alone unless you chose Overwrite.`,{title:"Run the import",confirmText:"Run import"})||!i()||h.peek()!==e))try{const d=await $(`${y}/staged/${e}/run`,{method:"POST",body:JSON.stringify({options:Ee(c.peek(),H.peek())})});if(Be(e),!i())return;x.value={...d.job,siteTitle:t.site?.title||""},re(),q(X),le()}catch(d){E.toast(`The import did not start: ${d.message||d}`,{type:"error"})}}let De=null;function le(){clearTimeout(De);const e=x.peek();e&&(De=setTimeout(async()=>{try{const t=await $(`${y}/jobs/${e.id}`);if(!i())return;if(x.value={...t.job,siteTitle:e.siteTitle},t.job.status==="running")return le();if(x.value=null,await Ne().catch(()=>{}),q(X),q("#/pages"),q("#/media"),q("#/plugins/shopping-cart"),q("#/collections"),q("#/blocks"),!i())return;t.job.status==="done"?(E.toast("The import has finished - here is its report.",{type:"success"}),ke(t.job.reportId)):(E.toast(`The import stopped: ${t.job.error||"an error"}`,{type:"error"}),t.job.reportId&&ke(t.job.reportId))}catch(t){if(!i())return;if(t.status===404){x.value=null,Ne().catch(()=>{});return}le()}},700))}f.add(()=>clearTimeout(De)),x.peek()&&le();async function so(){ve.value="";try{U.value=await $(`${y}/crawl`,{method:"POST",body:JSON.stringify({url:String(we.peek()||"").trim()})}),xe()}catch(e){i()&&(ve.value=e.message||String(e))}}async function no(){try{U.value=(await $(`${y}/crawl`,{method:"DELETE"})).crawl}catch(e){E.toast(e.message||String(e),{type:"error"})}}let Ue=null;function xe(){clearTimeout(Ue),Ue=setTimeout(async()=>{let e;try{e=(await $(`${y}/crawl`)).crawl}catch{i()&&xe();return}if(i()){if(U.value=e,e?.status==="running")return xe();e?.status==="done"&&e.meta?(we.value="",await $(`${y}/crawl`,{method:"DELETE"}).catch(()=>{}),U.value=null,p.value=[e.meta,...p.peek().filter(t=>t.id!==e.meta.id)],q(X),E.toast("The site has been read - here is what the import would do.",{type:"success"}),await ne(e.meta.id)):e&&e.status!=="running"&&(ve.value=e.status==="stopped"?"Stopped - nothing was kept.":`The site could not be read: ${e.error||"an error"}`,await $(`${y}/crawl`,{method:"DELETE"}).catch(()=>{}),U.value=null)}},1e3)}f.add(()=>clearTimeout(Ue)),U.peek()&&xe();let Y=!1;async function ke(e){if(Y||!e)return;Y=!0;let t;try{t=await $(`${y}/history/${e}`)}catch(s){Y=!1,E.toast(`Could not open the report: ${s.message||s}`,{type:"error"});return}if(!i()){Y=!1;return}let a;try{a=E.slideover({title:ee(`Report - ${t.run?.siteTitle||"WordPress import"}`),size:"lg",position:"right"})}catch(s){throw Y=!1,s}const o=is(`
|
|
80
80
|
<div class="wpx wpx-report">
|
|
81
81
|
<p class="wpx-note" data-bind-text="meta.value"></p>
|
|
82
82
|
<div class="wpx-tiles" data-each="tiles.value key=id"></div>
|
|
@@ -92,4 +92,4 @@ import{apiRequest as R,getToken as uo}from"../api.js";import{addBannerAction as
|
|
|
92
92
|
<div class="wpx-list wpx-report-people" data-each="people.value key=key"></div>
|
|
93
93
|
<div class="wpx-card-title" data-bind-hidden="!redirects.value.length">Redirects</div>
|
|
94
94
|
<div class="wpx-list wpx-report-redirects" data-each="redirects.value key=from"></div>
|
|
95
|
-
</div>`);o.querySelector(".wpx-tiles").innerHTML=zt,o.querySelector(".wpx-note-list").innerHTML=ze,o.querySelector(".wpx-seg").innerHTML=je,o.querySelector(".wpx-report-items").innerHTML=Ut,o.querySelector(".wpx-report-redirects").innerHTML=_t,o.querySelector(".wpx-report-people").innerHTML=Vo;const r=M.observable(t.run?.summary?.failed?"failed":"all"),c=/^\/[a-z0-9][a-z0-9/-]{0,200}$/.test(t.home?.previous||"")?t.home.previous:"",De=t.items||[],kt=Ct(De,Ot,Bt),O=t.run?.summary||{},He=s=>Object.values(O.kinds||{}).reduce((n,k)=>n+(k[s]||0),0),Xa={meta:M.observable([te(t.run?.at),t.run?.by,t.run?.file,t.run?.durationMs?`${Math.max(1,Math.round(t.run.durationMs/1e3))} s`:""].filter(Boolean).join(" \xB7 ")),tiles:M.observable([{id:"made",label:"Made",value:He("created"),sub:""},{id:"updated",label:"Updated",value:He("updated"),sub:""},{id:"kept",label:"Left as is",value:He("kept"),sub:""},{id:"redirects",label:"Redirects",value:(O.redirects?.created||0)+(O.redirects?.updated||0),sub:""},...O.people?[{id:"people",label:"Accounts made",value:O.people.created||0,sub:O.people.invited?`${O.people.invited} emailed`:""}]:[],{id:"comments",label:"Comments",value:O.comments||0,sub:""},{id:"failed",label:"Failed",value:O.failed||0,sub:""}]),notes:M.observable((t.notes||[]).map(s=>({text:s}))),homePrevious:M.observable(c),homePreviousText:M.observable(c?`This site's home page from before the import${t.home?.previousTitle?` ("${t.home.previousTitle}")`:""} is now a draft at ${c} - nothing was deleted. Publish it there, or delete it, from Pages.`:""),people:M.observable((t.people||[]).map(Eo)),filters:M.computed(()=>Ot.filter(s=>s.id==="all"||kt[s.id]).map(s=>({...s,count:kt[s.id],cls:r.value===s.id?"is-on":""}))),rows:M.computed(()=>De.filter(s=>Bt(s,r.value)).slice(0,1e3).map(s=>{const n=Oo(s);return{...n,pillCls:n.pillClass}})),redirects:M.observable((t.redirects||[]).filter(s=>s.result!=="skipped").slice(0,1e3).map(s=>({...s,reason:s.error||"",pill:s.result==="failed"?"Failed":s.result==="updated"?"Updated":"Added",pillClass:s.result==="failed"?"is-bad":"is-ok"})))};a.element.appendChild(o);const eo=M.applyBindings(Xa,o,{methods:{pickSeg:s=>{r.value=s.id}}}),to=Et(o),Mt=new Map(De.map(s=>[s.key,s])),ao=o.querySelector(".wpx-report-items"),oo=s=>{const n=Mt.get(s.dataset.key);if(!n)return[];const k=typeof n.target=="string"&&n.target.startsWith("/")?n.target:"",C=[{header:n.title}];if(k&&n.result!=="failed"&&n.result!=="skipped"&&C.push({label:"Open on the site",icon:"external-link",action:()=>window.open(k,"_blank","noopener")}),k&&(n.kind==="page"||n.kind==="custom"&&!n.collection)&&(n.result==="created"||n.result==="updated"||n.result==="kept")&&C.push({label:"Edit the page",icon:"edit",action:()=>{a.close(),location.hash=`#/pages/edit${k}`}}),n.kind==="widgets"&&/^[a-z0-9][a-z0-9-]{0,79}$/.test(n.target||"")&&["created","updated","kept"].includes(n.result)&&(C.push({label:"Edit the block",icon:"edit",action:()=>{a.close(),location.hash=`#/blocks/edit/${n.target}`}}),n.footer&&C.push({label:"Footer settings",icon:"settings",action:()=>{a.close(),location.hash="#/settings"}})),(n.kind==="collection"||n.kind==="custom")&&n.result!=="failed"&&n.result!=="skipped"&&/^[a-z0-9-]{1,80}$/.test(n.kind==="collection"?n.target:n.collection||"")){const Y=n.kind==="collection"?n.target:n.collection;C.push({label:"Open the collection",icon:"database",action:()=>{a.close(),location.hash=`#/collections/${Y}/entries`}})}return n.kind==="product"&&n.entryId&&/^[\w-]{1,64}$/.test(n.entryId)&&C.push({label:"Edit in the Shop",icon:"shopping-bag",action:()=>{a.close(),location.hash=`#/plugins/shopping-cart/products/${encodeURIComponent(n.entryId)}`}}),/^https?:\/\//i.test(n.oldUrl)&&C.push({label:"Open the old address",icon:"link",action:()=>window.open(n.oldUrl,"_blank","noopener,noreferrer")}),k&&C.push({label:"Copy the new address",icon:"copy",action:()=>Fe(new URL(k,location.origin).href)}),C},so=E.contextMenu(ao,{cursor:"glyph",match:".wpx-row",inherit:!1,density:"compact",items:oo}),no=o.querySelector(".wpx-report-people"),lo=new Map((t.people||[]).map(s=>[s.key,s])),ro=E.contextMenu(no,{cursor:"glyph",match:".wpx-row",inherit:!1,density:"compact",items:s=>{const n=lo.get(s.dataset.key);if(!n)return[];const k=/^[0-9a-f-]{36}$/i.test(n.userId||"")?n.userId:"";return[{header:n.name},...k&&n.result!=="skipped"?[{label:"Open their account",icon:"user",action:()=>{a.close(),location.hash=`#/users/edit/${k}`}}]:[],{label:"Open Users",icon:"users",action:()=>{a.close(),location.hash="#/users"}}]}}),io=o.querySelector(".wpx-report-redirects"),po=E.contextMenu(io,{cursor:"glyph",match:".wpx-row",inherit:!1,density:"compact",items:s=>[{header:s.dataset.from},...s.dataset.from.includes("*")?[]:[{label:"Try it on the site",icon:"external-link",action:()=>window.open(s.dataset.from,"_blank","noopener")}],{label:"Open SEO \u203A Redirects",icon:"corner-up-right",action:()=>{a.close(),location.hash="#/seo/redirects"}}]}),Ue=s=>{if(s.target.closest(".wpx-open-previous")&&c){a.close(),location.hash=`#/pages/edit${c}`;return}const n=s.target.closest(".wpx-kebab");if(n){B(n);return}const k=s.target.closest(".wpx-report-people .wpx-row");if(k){B(k.querySelector(".wpx-kebab")||k);return}const C=s.target.closest(".wpx-report-items .wpx-row");if(!C)return;const Y=Mt.get(C.dataset.key);Y?.target?.startsWith("/")&&Y.result!=="failed"&&Y.result!=="skipped"&&window.open(Y.target,"_blank","noopener")},Tt=s=>{const n=s.target.closest(".wpx-row");n&&(s.key==="F10"&&s.shiftKey?(s.preventDefault(),B(n)):s.key==="Enter"&&s.target===n&&(s.preventDefault(),s.stopPropagation(),Ue({target:n})))};o.addEventListener("click",Ue),o.addEventListener("keydown",Tt);const co=b.add(()=>a.close());ho(a,()=>{Z=!1,eo.dispose(),to(),so?.destroy?.(),po?.destroy?.(),ro?.destroy?.(),o.removeEventListener("click",Ue),o.removeEventListener("keydown",Tt),co()}),a.open(),I.scan(o)}async function Ya(e){const t=_.peek().find(a=>a.id===e);if(t&&await Te(`Remove the import of <strong>${G(t.siteTitle||t.source)}</strong> from this list? Everything it imported stays on the site.`,{title:"Remove from the history",confirmText:"Remove"}))try{if(await R(`${P}/history/${e}`,{method:"DELETE"}),!p())return;_.value=_.peek().filter(a=>a.id!==e),q(ie)}catch(a){E.toast(`Not removed: ${a.message||a}`,{type:"error"})}}l.querySelector(".wpx-staged").innerHTML=Wo,l.querySelector(".wpx-items").innerHTML=Ut,l.querySelector(".wpx-redirects").innerHTML=_t,l.querySelector(".wpx-history").innerHTML=Fo,l.querySelector(".wpx-tiles").innerHTML=zt,l.querySelector(".wpx-note-list").innerHTML=ze,l.querySelector(".wpx-home-notes").innerHTML=ze,l.querySelector(".wpx-kinds").innerHTML=je,l.querySelector(".wpx-filters").innerHTML=je,l.querySelector(".wpx-facts").innerHTML=Go,l.querySelector(".wpx-product-notes").innerHTML=jt,l.querySelector(".wpx-types").innerHTML=Ko,l.querySelector(".wpx-internal").innerHTML=jt,l.querySelector(".wpx-people-list").innerHTML=Zo,l.querySelector(".wpx-widget-areas").innerHTML=Yo;const Ga={mode:Wt,job:y,jobTitle:_a,jobText:za,jobPct:tt,staged:d,stagedRows:Kt,historyRows:Zt,plan:f,planLoading:pe,planError:$e,refreshing:Ee,opt:i,blogAvailable:H,blogNote:Na,dirty:Ve,canRun:et,siteTitle:sa,siteMeta:na,tiles:ea,notes:ta,kinds:Vt,filters:Gt,rows:Jt,moreText:Qt,emptyText:Xt,redirectRows:aa,redirectCount:oa,query:Q,uploadText:ce,uploadError:X,dropping:ue,wxrLimit:ja,zipInfo:he,zipText:Oa,zipButton:Ba,zipUploadText:de,hasPeople:$a,peopleRows:Sa,peopleCanCreate:La,peopleChoosable:Pa,peopleNote:Ca,peopleNoteCls:Ra,inviteAvailable:qa,inviteText:Aa,optInvite:Ia,shopAvailable:Ft,hasProducts:ca,productNote:la,productNoteCls:ra,productFacts:ia,productNotes:pa,typeRows:Le,internalRows:Pe,hasCustom:Ta,internalSummary:Ea,widgetsInfo:Qe,widgetsText:Da,widgetsButton:Ha,widgetsUploadText:Ce,widgetRows:Xe,hasHome:da,homeWp:ua,homeNow:ma,homeAfter:ha,homeAfterCls:va,homeNotes:wa,homeEdit:fa,homeFrontSwitch:ba,homeLatestSwitch:ga,homePostsSwitch:ya,homePostsText:xa,homeQuestion:Ye,runWhy:Ua,optHome:W("home"),optLatest:ka,optPostsPage:Ma,optComments:W("comments"),optMenus:W("menus"),optRedirects:W("redirects"),optDrafts:W("drafts"),optProducts:W("products")},Ja=M.applyBindings(Ga,l,{methods:{back:()=>oe(),discard:()=>ot(),run:()=>Va(),resetChoices:()=>{i.value=_e(H.peek())},postsBlog:()=>$({posts:"blog"}),postsPages:()=>$({posts:"pages"}),postsSkip:()=>$({posts:"skip"}),mediaDownload:()=>$({media:"download"}),mediaZip:()=>$({media:"zip"}),mediaSkip:()=>$({media:"skip"}),homeYes:()=>$({homeReplace:!0}),homeNo:()=>$({homeReplace:!1}),removeZip:()=>Za(),removeWidgets:()=>Ka(),peopleAll:()=>$({users:Lt(L.peek(),"create")}),peopleNone:()=>$({users:Lt(L.peek(),"skip")}),pickSeg:e=>{e.seg==="kind"?D.value=e.id:j.value=e.id},showProducts:()=>{D.value="product",j.value="all",Q.value="",l.querySelector(".wpx-items")?.closest(".wpx-card")?.scrollIntoView({behavior:"smooth",block:"start"})}}});b.add(()=>Ja.dispose()),b.add(Et(l,{position:"bottom"}));const ne=l.querySelector(".wpx-file"),nt=()=>{const e=ne.files?.[0];ne.value="",st(e)};ne.addEventListener("change",nt);const V=l.querySelector(".wpx-drop"),lt=e=>{e.preventDefault(),ue.value=!0},rt=()=>{ue.value=!1},it=e=>{e.preventDefault(),ue.value=!1,st(e.dataTransfer?.files?.[0])};V.addEventListener("dragover",lt),V.addEventListener("dragleave",rt),V.addEventListener("drop",it);const ge=l.querySelector(".wpx-zip-file"),pt=()=>{const e=ge.files?.[0];ge.value="",Wa(e)};ge.addEventListener("change",pt);const ye=l.querySelector(".wpx-wie-file"),ct=()=>{const e=ye.files?.[0];ye.value="",Fa(e)};ye.addEventListener("change",ct),b.add(()=>ye.removeEventListener("change",ct)),b.add(()=>{ne.removeEventListener("change",nt),V.removeEventListener("dragover",lt),V.removeEventListener("dragleave",rt),V.removeEventListener("drop",it),ge.removeEventListener("change",pt)}),U(l.querySelector(".wpx-staged"),".wpx-row",e=>[{header:d.peek().find(t=>t.id===e.dataset.id)?.siteTitle||"Upload"},{label:"Preview the import",icon:"eye",action:()=>fe(e.dataset.id)},{label:"Discard the upload",icon:"trash-2",action:()=>ot(e.dataset.id)}],e=>fe(e.dataset.id));const dt=(e,t)=>{i.value={...i.peek(),choices:fo(i.peek().choices,e,t)}};U(l.querySelector(".wpx-items"),".wpx-row",e=>{const t=F.peek().find(o=>o.key===e.dataset.key);if(!t)return[];const a=[{header:t.title}];for(const o of Pt(t,t.choice))a.push({label:o.label,icon:o.icon,action:()=>dt(t.key,o.id)});return t.oldUrl&&/^https?:\/\//i.test(t.oldUrl)&&a.push({label:"Open the old address",icon:"link",action:()=>window.open(t.oldUrl,"_blank","noopener,noreferrer")}),t.target?.startsWith("/")&&(t.action==="update"||t.action==="keep")&&a.push({label:"Open it on this site",icon:"external-link",action:()=>window.open(t.target,"_blank","noopener")}),a.length===1&&a.push({label:"Nothing to change here",icon:"info",disabled:!0,action:()=>{}}),a},e=>B(e.querySelector(".wpx-kebab")||e));const ut=(e,t)=>{i.value=jo(i.peek(),e,t)},mt=(e,t)=>{i.value=zo(i.peek(),e,t)},Qa=e=>{D.value="",j.value="all",Q.value=e,l.querySelector(".wpx-items")?.closest(".wpx-card")?.scrollIntoView({behavior:"smooth",block:"start"})},le=l.querySelector(".wpx-types"),ht=e=>{if(!e.target.closest(".wpx-type-ctl"))return;e.stopPropagation();const a=e.target.closest("button[data-as]"),o=e.target.closest(".wpx-type-row");a&&o&&ut(o.dataset.type,a.dataset.as)},vt=e=>{const t=e.target.closest("input[data-list-page]"),a=e.target.closest(".wpx-type-row");t&&a&&mt(a.dataset.type,t.checked)};le.addEventListener("click",ht,!0),le.addEventListener("change",vt),b.add(()=>{le.removeEventListener("click",ht,!0),le.removeEventListener("change",vt)}),U(le,".wpx-type-row",e=>{const t=Le.peek().find(a=>a.type===e.dataset.type);return t?[{header:`${t.label} ("${t.type}")`},...Do(t).map(a=>({label:a.label,icon:a.icon,action:()=>{a.id==="show"?Qa(t.type):a.id==="list"||a.id==="nolist"?mt(t.type,a.id==="list"):ut(t.type,a.id)}}))]:[]},e=>B(e.querySelector(".wpx-kebab")||e));const Ne=(e,t)=>{i.value=_o(i.peek(),e,t)},re=l.querySelector(".wpx-widget-areas"),wt=e=>{e.target.closest(".wpx-type-ctl")&&e.stopPropagation()},ft=e=>{const t=e.target.closest("input[data-footer]"),a=e.target.closest(".wpx-widget-row");t&&a&&Ne(a.dataset.area,t.checked)};re.addEventListener("click",wt,!0),re.addEventListener("change",ft),b.add(()=>{re.removeEventListener("click",wt,!0),re.removeEventListener("change",ft)}),U(re,".wpx-widget-row",e=>{const t=Xe.peek().find(r=>r.area===e.dataset.area),a=F.peek().find(r=>r.key===`widgets:${e.dataset.area}`);if(!t)return[];const o=[{header:`${t.label} ("${t.area}")`}];if(t.canPlace&&o.push(t.placeOn?{label:"Leave it out of the footer",icon:"eye-off",action:()=>Ne(t.area,!1)}:{label:"Place in the footer",icon:"layout",action:()=>Ne(t.area,!0)}),a)for(const r of Pt(a,a.choice))o.push({label:r.label,icon:r.icon,action:()=>dt(a.key,r.id)});return o.length===1&&o.push({label:"Nothing to change here",icon:"info",disabled:!0,action:()=>{}}),o},e=>B(e.querySelector(".wpx-kebab")||e));const bt=(e,t)=>{const a=L.peek()?.rows?.find(o=>o.key===e);a&&$({users:bo(i.peek().users,a,t)})},Oe=l.querySelector(".wpx-people-list"),gt=e=>{if(!e.target.closest(".wpx-type-ctl"))return;e.stopPropagation();const a=e.target.closest("button[data-user]"),o=e.target.closest(".wpx-person");a&&o&&bt(o.dataset.key,a.dataset.user)};Oe.addEventListener("click",gt,!0),b.add(()=>Oe.removeEventListener("click",gt,!0)),U(Oe,".wpx-person",e=>{const t=L.peek()?.rows?.find(a=>a.key===e.dataset.key);return t?[{header:t.name},...Mo(t).map(a=>({label:a.label,icon:a.icon,disabled:!!a.disabled,action:()=>{a.disabled||(a.id==="copy"?Fe(t.email):bt(t.key,a.id))}}))]:[]},e=>B(e.querySelector(".wpx-kebab")||e));const N=l.querySelector(".wpx-role");b.add(M.effect(()=>{const e=L.value;if(!N)return;const t=e?.roles||[],a=e?.role||"",o=`${t.map(r=>r.name).join(",")}|${a}`;N.dataset.sig!==o&&(N.dataset.sig=o,N.replaceChildren(...t.map(r=>{const c=document.createElement("option");return c.value=r.name,c.textContent=r.name===Ze?`${r.label} (default)`:r.label,c})),N.value=a)}));const yt=()=>$({userRole:N.value===Ze?"":N.value});N?.addEventListener("change",yt),b.add(()=>N?.removeEventListener("change",yt)),U(l.querySelector(".wpx-redirects"),".wpx-row",e=>[{header:e.dataset.from},{label:"Copy the old address",icon:"copy",action:()=>Fe(e.dataset.from)}],null),U(l.querySelector(".wpx-history"),".wpx-row",e=>[{header:_.peek().find(t=>t.id===e.dataset.id)?.siteTitle||"Import"},{label:"Open the report",icon:"file-text",action:()=>be(e.dataset.id)},{label:"Remove from the history",icon:"trash-2",action:()=>Ya(e.dataset.id)}],e=>be(e.dataset.id)),mo(u,{id:"wpx-upload",icon:"upload",title:"Upload an export",onClick:()=>{h.peek()&&oe(),setTimeout(()=>ne.click(),0)}}),I.scan(l);const Be=Rt(v(),d.peek().map(e=>e.id),g);Be.pruned&&T&&A({owner:g,items:Be.items});const xt=Object.entries(Be.items).sort((e,t)=>String(t[1].at).localeCompare(String(e[1].at)))[0];xt&&!y.peek()&&await fe(xt[0])}};
|
|
95
|
+
</div>`);o.querySelector(".wpx-tiles").innerHTML=Vt,o.querySelector(".wpx-note-list").innerHTML=Ze,o.querySelector(".wpx-seg").innerHTML=Ve,o.querySelector(".wpx-report-items").innerHTML=Kt,o.querySelector(".wpx-report-redirects").innerHTML=Zt,o.querySelector(".wpx-report-people").innerHTML=ns;const l=M.observable(t.run?.summary?.failed?"failed":"all"),d=/^\/[a-z0-9][a-z0-9/-]{0,200}$/.test(t.home?.previous||"")?t.home.previous:"",je=t.items||[],Lt=Ot(je,zt,jt),O=t.run?.summary||{},We=s=>Object.values(O.kinds||{}).reduce((n,T)=>n+(T[s]||0),0),po={meta:M.observable([_(t.run?.at),t.run?.by,t.run?.file,t.run?.durationMs?`${Math.max(1,Math.round(t.run.durationMs/1e3))} s`:""].filter(Boolean).join(" \xB7 ")),tiles:M.observable([{id:"made",label:"Made",value:We("created"),sub:""},{id:"updated",label:"Updated",value:We("updated"),sub:""},{id:"kept",label:"Left as is",value:We("kept"),sub:""},{id:"redirects",label:"Redirects",value:(O.redirects?.created||0)+(O.redirects?.updated||0),sub:""},...O.people?[{id:"people",label:"Accounts made",value:O.people.created||0,sub:O.people.invited?`${O.people.invited} emailed`:""}]:[],{id:"comments",label:"Comments",value:O.comments||0,sub:""},{id:"failed",label:"Failed",value:O.failed||0,sub:""}]),notes:M.observable((t.notes||[]).map(s=>({text:s}))),homePrevious:M.observable(d),homePreviousText:M.observable(d?`This site's home page from before the import${t.home?.previousTitle?` ("${t.home.previousTitle}")`:""} is now a draft at ${d} - nothing was deleted. Publish it there, or delete it, from Pages.`:""),people:M.observable((t.people||[]).map(Oo)),filters:M.computed(()=>zt.filter(s=>s.id==="all"||Lt[s.id]).map(s=>({...s,count:Lt[s.id],cls:l.value===s.id?"is-on":""}))),rows:M.computed(()=>je.filter(s=>jt(s,l.value)).slice(0,1e3).map(s=>{const n=Zo(s);return{...n,pillCls:n.pillClass}})),redirects:M.observable((t.redirects||[]).filter(s=>s.result!=="skipped").slice(0,1e3).map(s=>({...s,reason:s.error||"",pill:s.result==="failed"?"Failed":s.result==="updated"?"Updated":"Added",pillClass:s.result==="failed"?"is-bad":"is-ok"})))};a.element.appendChild(o);const uo=M.applyBindings(po,o,{methods:{pickSeg:s=>{l.value=s.id}}}),mo=Rt(o),Pt=new Map(je.map(s=>[s.key,s])),ho=o.querySelector(".wpx-report-items"),wo=s=>{const n=Pt.get(s.dataset.key);if(!n)return[];const T=typeof n.target=="string"&&n.target.startsWith("/")?n.target:"",R=[{header:n.title}];if(T&&n.result!=="failed"&&n.result!=="skipped"&&R.push({label:"Open on the site",icon:"external-link",action:()=>window.open(T,"_blank","noopener")}),T&&(n.kind==="page"||n.kind==="custom"&&!n.collection)&&(n.result==="created"||n.result==="updated"||n.result==="kept")&&R.push({label:"Edit the page",icon:"edit",action:()=>{a.close(),location.hash=`#/pages/edit${T}`}}),n.kind==="widgets"&&/^[a-z0-9][a-z0-9-]{0,79}$/.test(n.target||"")&&["created","updated","kept"].includes(n.result)&&(R.push({label:"Edit the block",icon:"edit",action:()=>{a.close(),location.hash=`#/blocks/edit/${n.target}`}}),n.footer&&R.push({label:"Footer settings",icon:"settings",action:()=>{a.close(),location.hash="#/settings"}})),(n.kind==="collection"||n.kind==="custom")&&n.result!=="failed"&&n.result!=="skipped"&&/^[a-z0-9-]{1,80}$/.test(n.kind==="collection"?n.target:n.collection||"")){const Q=n.kind==="collection"?n.target:n.collection;R.push({label:"Open the collection",icon:"database",action:()=>{a.close(),location.hash=`#/collections/${Q}/entries`}})}return n.kind==="product"&&n.entryId&&/^[\w-]{1,64}$/.test(n.entryId)&&R.push({label:"Edit in the Shop",icon:"shopping-bag",action:()=>{a.close(),location.hash=`#/plugins/shopping-cart/products/${encodeURIComponent(n.entryId)}`}}),/^https?:\/\//i.test(n.oldUrl)&&R.push({label:"Open the old address",icon:"link",action:()=>window.open(n.oldUrl,"_blank","noopener,noreferrer")}),T&&R.push({label:"Copy the new address",icon:"copy",action:()=>Ye(new URL(T,location.origin).href)}),R},vo=E.contextMenu(ho,{cursor:"glyph",match:".wpx-row",inherit:!1,density:"compact",items:wo}),fo=o.querySelector(".wpx-report-people"),bo=new Map((t.people||[]).map(s=>[s.key,s])),go=E.contextMenu(fo,{cursor:"glyph",match:".wpx-row",inherit:!1,density:"compact",items:s=>{const n=bo.get(s.dataset.key);if(!n)return[];const T=/^[0-9a-f-]{36}$/i.test(n.userId||"")?n.userId:"";return[{header:n.name},...T&&n.result!=="skipped"?[{label:"Open their account",icon:"user",action:()=>{a.close(),location.hash=`#/users/edit/${T}`}}]:[],{label:"Open Users",icon:"users",action:()=>{a.close(),location.hash="#/users"}}]}}),yo=o.querySelector(".wpx-report-redirects"),xo=E.contextMenu(yo,{cursor:"glyph",match:".wpx-row",inherit:!1,density:"compact",items:s=>[{header:s.dataset.from},...s.dataset.from.includes("*")?[]:[{label:"Try it on the site",icon:"external-link",action:()=>window.open(s.dataset.from,"_blank","noopener")}],{label:"Open SEO \u203A Redirects",icon:"corner-up-right",action:()=>{a.close(),location.hash="#/seo/redirects"}}]}),Fe=s=>{if(s.target.closest(".wpx-open-previous")&&d){a.close(),location.hash=`#/pages/edit${d}`;return}const n=s.target.closest(".wpx-kebab");if(n){B(n);return}const T=s.target.closest(".wpx-report-people .wpx-row");if(T){B(T.querySelector(".wpx-kebab")||T);return}const R=s.target.closest(".wpx-report-items .wpx-row");if(!R)return;const Q=Pt.get(R.dataset.key);Q?.target?.startsWith("/")&&Q.result!=="failed"&&Q.result!=="skipped"&&window.open(Q.target,"_blank","noopener")},Ct=s=>{const n=s.target.closest(".wpx-row");n&&(s.key==="F10"&&s.shiftKey?(s.preventDefault(),B(n)):s.key==="Enter"&&s.target===n&&(s.preventDefault(),s.stopPropagation(),Fe({target:n})))};o.addEventListener("click",Fe),o.addEventListener("keydown",Ct);const ko=f.add(()=>a.close());Eo(a,()=>{Y=!1,uo.dispose(),mo(),vo?.destroy?.(),xo?.destroy?.(),go?.destroy?.(),o.removeEventListener("click",Fe),o.removeEventListener("keydown",Ct),ko()}),a.open(),I.scan(o)}async function ro(e){const t=j.peek().find(a=>a.id===e);if(t&&await Le(`Remove the import of <strong>${ee(t.siteTitle||t.source)}</strong> from this list? Everything it imported stays on the site.`,{title:"Remove from the history",confirmText:"Remove"}))try{if(await $(`${y}/history/${e}`,{method:"DELETE"}),!i())return;j.value=j.peek().filter(a=>a.id!==e),q(X)}catch(a){E.toast(`Not removed: ${a.message||a}`,{type:"error"})}}r.querySelector(".wpx-staged").innerHTML=ts,r.querySelector(".wpx-items").innerHTML=Kt,r.querySelector(".wpx-redirects").innerHTML=Zt,r.querySelector(".wpx-history").innerHTML=as,r.querySelector(".wpx-tiles").innerHTML=Vt,r.querySelector(".wpx-note-list").innerHTML=Ze,r.querySelector(".wpx-home-notes").innerHTML=Ze,r.querySelector(".wpx-kinds").innerHTML=Ve,r.querySelector(".wpx-filters").innerHTML=Ve,r.querySelector(".wpx-facts").innerHTML=ls,r.querySelector(".wpx-product-notes").innerHTML=Jt,r.querySelector(".wpx-types").innerHTML=os,r.querySelector(".wpx-internal").innerHTML=Jt,r.querySelector(".wpx-people-list").innerHTML=ss,r.querySelector(".wpx-widget-areas").innerHTML=rs;const lo={mode:Xt,job:x,jobTitle:Ya,jobText:Ga,jobPct:lt,staged:p,stagedRows:ta,historyRows:aa,plan:v,planLoading:de,planError:Ce,refreshing:Pe,opt:c,blogAvailable:H,blogNote:Wa,dirty:Xe,canRun:rt,siteTitle:ma,siteMeta:ha,fromWp:et,tiles:ca,notes:pa,kinds:oa,filters:na,rows:ra,moreText:la,emptyText:ia,redirectRows:da,redirectCount:ua,query:ae,uploadText:ue,uploadError:oe,dropping:he,crawlUrl:we,crawlError:ve,crawlRunning:Yt,crawlReady:Gt,crawlText:Qt,wxrLimit:Qa,zipInfo:be,zipText:Fa,zipButton:Ka,zipUploadText:me,hasPeople:Na,peopleRows:Oa,peopleCanCreate:Ba,peopleChoosable:Da,peopleNote:Ua,peopleNoteCls:Ha,inviteAvailable:_a,inviteText:za,optInvite:ja,shopAvailable:ea,hasProducts:ga,productNote:wa,productNoteCls:va,productFacts:fa,productNotes:ba,typeRows:qe,internalRows:Ae,hasCustom:Aa,internalSummary:Ia,widgetsInfo:st,widgetsText:Za,widgetsButton:Va,widgetsUploadText:Ie,widgetRows:nt,hasHome:ya,homeWp:xa,homeNow:ka,homeAfter:Ma,homeAfterCls:Ta,homeNotes:Ea,homeEdit:$a,homeFrontSwitch:Sa,homeLatestSwitch:La,homePostsSwitch:Pa,homePostsText:Ca,homeQuestion:tt,runWhy:Ja,optHome:Z("home"),optLatest:Ra,optPostsPage:qa,optComments:Z("comments"),optMenus:Z("menus"),optRedirects:Z("redirects"),optDrafts:Z("drafts"),optProducts:Z("products")},io=M.applyBindings(lo,r,{methods:{back:()=>re(),startCrawl:()=>so(),stopCrawl:()=>no(),discard:()=>ct(),run:()=>oo(),resetChoices:()=>{c.value=Ke(H.peek())},postsBlog:()=>P({posts:"blog"}),postsPages:()=>P({posts:"pages"}),postsSkip:()=>P({posts:"skip"}),mediaDownload:()=>P({media:"download"}),mediaZip:()=>P({media:"zip"}),mediaSkip:()=>P({media:"skip"}),homeYes:()=>P({homeReplace:!0}),homeNo:()=>P({homeReplace:!1}),removeZip:()=>ao(),removeWidgets:()=>to(),peopleAll:()=>P({users:It(C.peek(),"create")}),peopleNone:()=>P({users:It(C.peek(),"skip")}),pickSeg:e=>{e.seg==="kind"?D.value=e.id:F.value=e.id},showProducts:()=>{D.value="product",F.value="all",ae.value="",r.querySelector(".wpx-items")?.closest(".wpx-card")?.scrollIntoView({behavior:"smooth",block:"start"})}}});f.add(()=>io.dispose()),f.add(Rt(r,{position:"bottom"}));const ie=r.querySelector(".wpx-file"),dt=()=>{const e=ie.files?.[0];ie.value="",pt(e)};ie.addEventListener("change",dt);const G=r.querySelector(".wpx-drop"),ut=e=>{e.preventDefault(),he.value=!0},mt=()=>{he.value=!1},ht=e=>{e.preventDefault(),he.value=!1,pt(e.dataTransfer?.files?.[0])};G.addEventListener("dragover",ut),G.addEventListener("dragleave",mt),G.addEventListener("drop",ht);const Me=r.querySelector(".wpx-zip-file"),wt=()=>{const e=Me.files?.[0];Me.value="",Xa(e)};Me.addEventListener("change",wt);const Te=r.querySelector(".wpx-wie-file"),vt=()=>{const e=Te.files?.[0];Te.value="",eo(e)};Te.addEventListener("change",vt),f.add(()=>Te.removeEventListener("change",vt)),f.add(()=>{ie.removeEventListener("change",dt),G.removeEventListener("dragover",ut),G.removeEventListener("dragleave",mt),G.removeEventListener("drop",ht),Me.removeEventListener("change",wt)}),z(r.querySelector(".wpx-staged"),".wpx-row",e=>[{header:p.peek().find(t=>t.id===e.dataset.id)?.siteTitle||"Upload"},{label:"Preview the import",icon:"eye",action:()=>ne(e.dataset.id)},{label:"Discard the upload",icon:"trash-2",action:()=>ct(e.dataset.id)}],e=>ne(e.dataset.id));const ft=(e,t)=>{c.value={...c.peek(),choices:Lo(c.peek().choices,e,t)}};z(r.querySelector(".wpx-items"),".wpx-row",e=>{const t=V.peek().find(o=>o.key===e.dataset.key);if(!t)return[];const a=[{header:t.title}];for(const o of Nt(t,t.choice))a.push({label:o.label,icon:o.icon,action:()=>ft(t.key,o.id)});return t.oldUrl&&/^https?:\/\//i.test(t.oldUrl)&&a.push({label:"Open the old address",icon:"link",action:()=>window.open(t.oldUrl,"_blank","noopener,noreferrer")}),t.target?.startsWith("/")&&(t.action==="update"||t.action==="keep")&&a.push({label:"Open it on this site",icon:"external-link",action:()=>window.open(t.target,"_blank","noopener")}),a.length===1&&a.push({label:"Nothing to change here",icon:"info",disabled:!0,action:()=>{}}),a},e=>B(e.querySelector(".wpx-kebab")||e));const bt=(e,t)=>{c.value=es(c.peek(),e,t)},gt=(e,t)=>{c.value=Xo(c.peek(),e,t)},co=e=>{D.value="",F.value="all",ae.value=e,r.querySelector(".wpx-items")?.closest(".wpx-card")?.scrollIntoView({behavior:"smooth",block:"start"})},ce=r.querySelector(".wpx-types"),yt=e=>{if(!e.target.closest(".wpx-type-ctl"))return;e.stopPropagation();const a=e.target.closest("button[data-as]"),o=e.target.closest(".wpx-type-row");a&&o&&bt(o.dataset.type,a.dataset.as)},xt=e=>{const t=e.target.closest("input[data-list-page]"),a=e.target.closest(".wpx-type-row");t&&a&>(a.dataset.type,t.checked)};ce.addEventListener("click",yt,!0),ce.addEventListener("change",xt),f.add(()=>{ce.removeEventListener("click",yt,!0),ce.removeEventListener("change",xt)}),z(ce,".wpx-type-row",e=>{const t=qe.peek().find(a=>a.type===e.dataset.type);return t?[{header:`${t.label} ("${t.type}")`},...Jo(t).map(a=>({label:a.label,icon:a.icon,action:()=>{a.id==="show"?co(t.type):a.id==="list"||a.id==="nolist"?gt(t.type,a.id==="list"):bt(t.type,a.id)}}))]:[]},e=>B(e.querySelector(".wpx-kebab")||e));const He=(e,t)=>{c.value=Qo(c.peek(),e,t)},pe=r.querySelector(".wpx-widget-areas"),kt=e=>{e.target.closest(".wpx-type-ctl")&&e.stopPropagation()},Mt=e=>{const t=e.target.closest("input[data-footer]"),a=e.target.closest(".wpx-widget-row");t&&a&&He(a.dataset.area,t.checked)};pe.addEventListener("click",kt,!0),pe.addEventListener("change",Mt),f.add(()=>{pe.removeEventListener("click",kt,!0),pe.removeEventListener("change",Mt)}),z(pe,".wpx-widget-row",e=>{const t=nt.peek().find(l=>l.area===e.dataset.area),a=V.peek().find(l=>l.key===`widgets:${e.dataset.area}`);if(!t)return[];const o=[{header:`${t.label} ("${t.area}")`}];if(t.canPlace&&o.push(t.placeOn?{label:"Leave it out of the footer",icon:"eye-off",action:()=>He(t.area,!1)}:{label:"Place in the footer",icon:"layout",action:()=>He(t.area,!0)}),a)for(const l of Nt(a,a.choice))o.push({label:l.label,icon:l.icon,action:()=>ft(a.key,l.id)});return o.length===1&&o.push({label:"Nothing to change here",icon:"info",disabled:!0,action:()=>{}}),o},e=>B(e.querySelector(".wpx-kebab")||e));const Tt=(e,t)=>{const a=C.peek()?.rows?.find(o=>o.key===e);a&&P({users:Po(c.peek().users,a,t)})},_e=r.querySelector(".wpx-people-list"),Et=e=>{if(!e.target.closest(".wpx-type-ctl"))return;e.stopPropagation();const a=e.target.closest("button[data-user]"),o=e.target.closest(".wpx-person");a&&o&&Tt(o.dataset.key,a.dataset.user)};_e.addEventListener("click",Et,!0),f.add(()=>_e.removeEventListener("click",Et,!0)),z(_e,".wpx-person",e=>{const t=C.peek()?.rows?.find(a=>a.key===e.dataset.key);return t?[{header:t.name},...Io(t).map(a=>({label:a.label,icon:a.icon,disabled:!!a.disabled,action:()=>{a.disabled||(a.id==="copy"?Ye(t.email):Tt(t.key,a.id))}}))]:[]},e=>B(e.querySelector(".wpx-kebab")||e));const N=r.querySelector(".wpx-role");f.add(M.effect(()=>{const e=C.value;if(!N)return;const t=e?.roles||[],a=e?.role||"",o=`${t.map(l=>l.name).join(",")}|${a}`;N.dataset.sig!==o&&(N.dataset.sig=o,N.replaceChildren(...t.map(l=>{const d=document.createElement("option");return d.value=l.name,d.textContent=l.name===Qe?`${l.label} (default)`:l.label,d})),N.value=a)}));const $t=()=>P({userRole:N.value===Qe?"":N.value});N?.addEventListener("change",$t),f.add(()=>N?.removeEventListener("change",$t)),z(r.querySelector(".wpx-redirects"),".wpx-row",e=>[{header:e.dataset.from},{label:"Copy the old address",icon:"copy",action:()=>Ye(e.dataset.from)}],null),z(r.querySelector(".wpx-history"),".wpx-row",e=>[{header:j.peek().find(t=>t.id===e.dataset.id)?.siteTitle||"Import"},{label:"Open the report",icon:"file-text",action:()=>ke(e.dataset.id)},{label:"Remove from the history",icon:"trash-2",action:()=>ro(e.dataset.id)}],e=>ke(e.dataset.id)),To(m,{id:"wpx-upload",icon:"upload",title:"Upload an export",onClick:()=>{h.peek()&&re(),setTimeout(()=>ie.click(),0)}}),I.scan(r);const ze=Bt(w(),p.peek().map(e=>e.id),g);ze.pruned&&L&&A({owner:g,items:ze.items});const St=Object.entries(ze.items).sort((e,t)=>String(t[1].at).localeCompare(String(e[1].at)))[0];St&&!x.peek()&&await ne(St[0])}};
|
package/docs/DommaFeatures.md
CHANGED
|
@@ -1194,6 +1194,11 @@ The four Tools below were plugins until 0.67.0 and are now part of the CMS. They
|
|
|
1194
1194
|
- The settings cog sets the opening filter, sort, default priority, relative dates and delete confirmation.
|
|
1195
1195
|
|
|
1196
1196
|
Where: **Tools > Todo** (`#/todo`), `/api/todo`; collection `todo-items`, which declares MongoDB and uses it where the site has a working connection (files otherwise) - Since: 0.67.0 core, 0.69.0 rebuilt, 0.87.0 notices, 0.93.0 MongoDB honoured.
|
|
1197
|
+
- **Import a site** (was "Import from WordPress") - Bring a site across from WordPress, Squarespace or Wix. Upload an export, or read a live site; see a preview of every page, post, file, menu and redirect before anything changes; run it as a background job; keep each run's report. Re-runs update what they made.
|
|
1198
|
+
- WordPress: the WXR export (`.xml` or a `.zip` holding one), media from the old site or a zip of `wp-content/uploads`, Yoast/Rank Math SEO, WooCommerce products, custom post types, widgets, authors, the home page.
|
|
1199
|
+
- Squarespace (unreleased): its WordPress-format export. Images on the Squarespace CDN are downloaded at full size (sizes such as `?format=750w` dropped), images named only in page HTML (`data-src`) become attachments, and the preview says what Squarespace leaves out (products, events, audio/video, other blogs).
|
|
1200
|
+
- Wix, or any site without an export (unreleased): **Copy a live site** - type the address, and the site's sitemap (or the links from its home page) is read, up to 500 pages, that host only, through `safeFetch`. Each page's words, headings, images, links and documents, blog posts (og:type article / JSON-LD BlogPosting) with dates, authors and descriptions, and the home page's menu are written as a WordPress-format export and staged like an upload. Wix images become their originals (`/v1/fill/...` dropped). The preview notes pages with little text and addresses that could not be read. Old addresses such as `/post/<slug>` redirect.
|
|
1201
|
+
Where: **Tools > Maintenance > Import a site** (`#/wordpress-import`), `/api/import/wordpress` (`POST/GET/DELETE /crawl`), `server/services/wpImport/` (`platforms.js`, `crawl.js`); permission `import.wordpress`.
|
|
1197
1202
|
- **Tool switches** - Contacts, Notes, Todo, Analytics and SEO can each be switched off. A Tool that is off keeps its data, but it disappears from the sidebar, its API answers 404, and anything it feeds stops, including notification sources, calendar layers, related items and the analytics beacon. A switch takes effect after a restart.
|
|
1198
1203
|
Where: **Marketplace** (`#/plugins`) > "Built-in Tools"; `config/tools.json` (`{"notes": {"enabled": false, "locked": true}}`); `PUT /api/tools/:name`; `server/services/tools.js` - Since: 0.88.0.
|
|
1199
1204
|
- **Dependencies and cascades** - A plugin's `plugin.json` can declare dependencies:
|
|
@@ -2709,6 +2714,8 @@ Later changes to these features are in the CHANGELOG (for example 0.92.1: row-le
|
|
|
2709
2714
|
### Content, authoring and the public site
|
|
2710
2715
|
|
|
2711
2716
|
- Build your first page: create, write Markdown, preview in split and Live Preview at mobile width, publish.
|
|
2717
|
+
- Leaving Wix: copy the live site with Import a site, read the preview's notes (thin pages, unreadable addresses), import to a staging site, check the redirects from `/post/...`, then move the domain.
|
|
2718
|
+
- Leaving Squarespace: export the WordPress-format file, import it before closing the account, and rebuild what Squarespace leaves out.
|
|
2712
2719
|
- Teach the chat bot: add a chat launcher, replace the example Knowledge, try questions, then turn a week of Unanswered questions into entries and other ways of asking.
|
|
2713
2720
|
- Draft, review and publish: use the draft banner, send a client a 7-day share link, revoke it, publish from the banner.
|
|
2714
2721
|
- Members-only content: gate pages with "role and above" versus "role only" (`=role`), arrays for sibling roles, and matching menu item visibility.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "domma-cms",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.41.0",
|
|
4
4
|
"description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "server/server.js",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"bcryptjs": "^3.0.3",
|
|
87
87
|
"css-select": "^7.0.0",
|
|
88
88
|
"dom-serializer": "^3.1.1",
|
|
89
|
-
"domma-js": "1.0
|
|
89
|
+
"domma-js": "1.1.0",
|
|
90
90
|
"dotenv": "^17.2.3",
|
|
91
91
|
"fastify": "5.12.7",
|
|
92
92
|
"gray-matter": "^4.0.3",
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* GET /status staged uploads, the running job, recent runs, what posts and products can become
|
|
7
7
|
* GET /count the sidebar badge
|
|
8
|
-
* POST /upload a WXR export (.xml, or a .zip holding one) - multipart, field "file"
|
|
8
|
+
* POST /upload a WXR export (.xml, or a .zip holding one) - multipart, field "file";
|
|
9
|
+
* Squarespace's export is one too (services/wpImport/platforms.js)
|
|
10
|
+
* POST /crawl {url} -> read a live site (Wix, or any) into an export, in the background
|
|
11
|
+
* GET /crawl that reading's progress; when done, `stagedId` is the export waiting to run
|
|
12
|
+
* DELETE /crawl stop it
|
|
9
13
|
* POST /staged/:id/uploads the wp-content/uploads folder as a .zip - multipart, field "file"
|
|
10
14
|
* DELETE /staged/:id/uploads drop that zip
|
|
11
15
|
* POST /staged/:id/widgets the widgets, as a .wie file (the "Widget Importer & Exporter" plugin's) - multipart, field "file"
|
|
@@ -38,6 +42,7 @@ import {
|
|
|
38
42
|
stagingPath, startRun, updateStagingMeta, UPLOADS_ZIP_MAX_BYTES, WIE_MAX_BYTES, widgetsMeta, WXR_MAX_BYTES, zipRel
|
|
39
43
|
} from '../../services/wpImport/index.js';
|
|
40
44
|
import {readWie} from '../../services/wpImport/widgets.js';
|
|
45
|
+
import {crawlSite, CrawlError, startUrl} from '../../services/wpImport/crawl.js';
|
|
41
46
|
import {getReport, isId, listHistory, listStaging, removeHistory} from '../../services/wpImport/store.js';
|
|
42
47
|
import {openZip} from '../../services/wpImport/zip.js';
|
|
43
48
|
import {seoEngine} from '../../services/seo/index.js';
|
|
@@ -64,6 +69,43 @@ async function saveUpload(file, dest, max) {
|
|
|
64
69
|
|
|
65
70
|
const mb = (n) => `${Math.round(n / 1048576)} MB`;
|
|
66
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The one site being read at a time (a crawl is minutes of outbound requests).
|
|
74
|
+
* Kept in memory: a restart drops it, and the person starts it again.
|
|
75
|
+
*/
|
|
76
|
+
let crawl = null;
|
|
77
|
+
let crawlAbort = null;
|
|
78
|
+
export const crawlState = () => (crawl ? {...crawl} : null);
|
|
79
|
+
|
|
80
|
+
/** Read a site in the background; when it is read, its export is staged like an upload. */
|
|
81
|
+
export function beginCrawl(url, by, opts = {}) {
|
|
82
|
+
const home = startUrl(url);
|
|
83
|
+
crawl = {url: home, status: 'running', phase: 'Starting', found: 0, read: 0, failed: 0, at: new Date().toISOString(), by};
|
|
84
|
+
crawlAbort = new AbortController();
|
|
85
|
+
const mine = crawl;
|
|
86
|
+
const done = (async () => {
|
|
87
|
+
try {
|
|
88
|
+
const {xml, summary} = await crawlSite(home, {
|
|
89
|
+
signal: crawlAbort.signal, fetchOpts: opts.fetchOpts, maxPages: opts.maxPages,
|
|
90
|
+
onProgress: (p) => Object.assign(mine, p)
|
|
91
|
+
});
|
|
92
|
+
if (crawl !== mine) return;
|
|
93
|
+
if (Buffer.byteLength(xml) > WXR_MAX_BYTES) throw new CrawlError(`The site came to more than ${mb(WXR_MAX_BYTES)} - too big to import in one go.`);
|
|
94
|
+
try { allowInGitignore(process.cwd(), [IMPORT_RULE]); } catch { /* not a managed site repo */ }
|
|
95
|
+
const host = new URL(home).hostname.replace(/[^\w.-]/g, '_');
|
|
96
|
+
const id = await createStaging({fileName: `${host} (read ${new Date().toISOString().slice(0, 10)}).xml`, kind: 'xml', by, source: 'crawl', crawl: summary});
|
|
97
|
+
await fs.promises.writeFile(stagingPath(id, 'export.xml'), xml, {mode: 0o600});
|
|
98
|
+
await updateStagingMeta(id, {size: Buffer.byteLength(xml)});
|
|
99
|
+
const meta = await inspectStaged(id);
|
|
100
|
+
Object.assign(mine, {status: 'done', phase: 'Read', stagedId: id, summary, meta});
|
|
101
|
+
} catch (err) {
|
|
102
|
+
if (crawl !== mine) return;
|
|
103
|
+
Object.assign(mine, {status: crawlAbort?.signal.aborted ? 'stopped' : 'failed', error: err.message || String(err)});
|
|
104
|
+
}
|
|
105
|
+
})();
|
|
106
|
+
return {state: crawlState(), done};
|
|
107
|
+
}
|
|
108
|
+
|
|
67
109
|
/**
|
|
68
110
|
* What the person running the import may do with users: whether they may add
|
|
69
111
|
* accounts at all (users.create), and the roles they may give - every role on
|
|
@@ -162,6 +204,7 @@ export async function wordpressImportRoutes(fastify, opts = {}) {
|
|
|
162
204
|
shop: shopForScreen(shop),
|
|
163
205
|
staged: await listStaging(),
|
|
164
206
|
running: job ? {...job} : null,
|
|
207
|
+
crawl: crawlState(),
|
|
165
208
|
history: (await listHistory()).slice(0, 50),
|
|
166
209
|
blog: {available: blog.available, basePath: blog.basePath, comments: Boolean(blog.comments), reason: blog.reason || ''},
|
|
167
210
|
redirects: Boolean(seoEngine()),
|
|
@@ -176,7 +219,7 @@ export async function wordpressImportRoutes(fastify, opts = {}) {
|
|
|
176
219
|
const staged = await listStaging();
|
|
177
220
|
if (job) {
|
|
178
221
|
return {count: 1, label: `Importing - ${job.phase}`, tone: 'live',
|
|
179
|
-
details: {title: 'Import
|
|
222
|
+
details: {title: 'Import a site', rows: [{label: 'Progress', value: `${job.done} of ${job.total}`}], items: [], empty: ''}};
|
|
180
223
|
}
|
|
181
224
|
const last = runs[0];
|
|
182
225
|
return {
|
|
@@ -184,7 +227,7 @@ export async function wordpressImportRoutes(fastify, opts = {}) {
|
|
|
184
227
|
label: runs.length ? `${plural(runs.length, 'import')} so far` : 'Nothing imported yet',
|
|
185
228
|
tone: 'info',
|
|
186
229
|
details: {
|
|
187
|
-
title: 'Import
|
|
230
|
+
title: 'Import a site',
|
|
188
231
|
rows: [
|
|
189
232
|
{label: 'Imports', value: String(runs.length)},
|
|
190
233
|
{label: 'Waiting to run', value: String(staged.length)},
|
|
@@ -218,6 +261,22 @@ export async function wordpressImportRoutes(fastify, opts = {}) {
|
|
|
218
261
|
}
|
|
219
262
|
});
|
|
220
263
|
|
|
264
|
+
fastify.post('/crawl', may, async (request, reply) => {
|
|
265
|
+
if (crawl?.status === 'running') return reply.code(409).send({error: `Already reading ${crawl.url} - wait for it, or stop it.`});
|
|
266
|
+
try {
|
|
267
|
+
return beginCrawl(request.body?.url, request.user?.email || '', opts.crawl || {}).state;
|
|
268
|
+
} catch (err) {
|
|
269
|
+
if (err instanceof CrawlError) return reply.code(400).send({error: err.message});
|
|
270
|
+
return fail(reply, err);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
fastify.get('/crawl', may, async () => ({crawl: crawlState()}));
|
|
274
|
+
fastify.delete('/crawl', may, async () => {
|
|
275
|
+
if (crawl?.status === 'running') crawlAbort?.abort();
|
|
276
|
+
else crawl = null;
|
|
277
|
+
return {crawl: crawlState()};
|
|
278
|
+
});
|
|
279
|
+
|
|
221
280
|
fastify.post('/staged/:id/uploads', may, async (request, reply) => {
|
|
222
281
|
const {id} = request.params;
|
|
223
282
|
const meta = isId(id) ? await stagingMeta(id) : null;
|
package/server/server.js
CHANGED
|
@@ -679,7 +679,7 @@ for (const item of coreToolItems) toolEntry(item.permission, item);
|
|
|
679
679
|
// Launchers sit in Content beside Menus and Context Menus; switched off, no entry (toolEntry).
|
|
680
680
|
if (isToolEnabled('launchers')) registerSidebarItem({folder: 'content', item: {source: 'Built in', text: 'Launchers', url: '#/launchers', icon: 'rocket', permission: 'settings', countUrl: '/api/launchers/_count', inventory: true}});
|
|
681
681
|
else if (isToolStaffOnly('launchers')) registerSidebarItem({folder: 'content', item: {source: 'Built in', text: 'Launchers', url: '#/launchers', icon: 'rocket', permission: 'settings', countUrl: '/api/launchers/_count', inventory: true, staffOnly: true}});
|
|
682
|
-
toolEntry('wordpress-import', {text: 'Import
|
|
682
|
+
toolEntry('wordpress-import', {text: 'Import a site', url: '#/wordpress-import', icon: 'download', permission: 'import', countUrl: '/api/import/wordpress/count', inventory: true});
|
|
683
683
|
// Todo's to-dos on the calendar (registered when routes/api/todo.js loads).
|
|
684
684
|
if (!isToolEnabled('todo')) {
|
|
685
685
|
const {unregisterCalendarSource} = await import('./services/hooks.js');
|
|
@@ -111,22 +111,31 @@ export function defaultThemeConfig() {
|
|
|
111
111
|
// ---------------------------------------------------------------------------
|
|
112
112
|
|
|
113
113
|
let _cssCache = null;
|
|
114
|
+
let _cssStamp = null;
|
|
114
115
|
|
|
115
116
|
function readThemeStylesheet() {
|
|
116
|
-
if (_cssCache !== null) return _cssCache;
|
|
117
117
|
for (const file of THEME_CSS_CANDIDATES) {
|
|
118
118
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
const stat = fsSync.statSync(file);
|
|
120
|
+
const stamp = `${file}:${stat.mtimeMs}:${stat.ctimeMs}:${stat.size}`;
|
|
121
|
+
if (_cssCache !== null && _cssStamp === stamp) return _cssCache;
|
|
122
|
+
const css = fsSync.readFileSync(file, 'utf8');
|
|
123
|
+
invalidateThemeStylesheet();
|
|
124
|
+
_cssCache = css;
|
|
125
|
+
_cssStamp = stamp;
|
|
126
|
+
return css;
|
|
121
127
|
} catch { /* try the next candidate */ }
|
|
122
128
|
}
|
|
123
|
-
|
|
124
|
-
|
|
129
|
+
// A package can disappear briefly while an upgrade replaces it. Do not
|
|
130
|
+
// retain ids from the old file, or permanently cache an empty catalogue.
|
|
131
|
+
invalidateThemeStylesheet();
|
|
132
|
+
return '';
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
/** Drop the memoised stylesheet - after an upgrade, or in tests. */
|
|
128
136
|
export function invalidateThemeStylesheet() {
|
|
129
137
|
_cssCache = null;
|
|
138
|
+
_cssStamp = null;
|
|
130
139
|
_themeIdCache = null;
|
|
131
140
|
_tokenNameCache = null;
|
|
132
141
|
}
|
|
@@ -139,8 +148,8 @@ let _themeIdCache = null;
|
|
|
139
148
|
* @returns {string[]}
|
|
140
149
|
*/
|
|
141
150
|
export function listThemeIds() {
|
|
142
|
-
if (_themeIdCache) return _themeIdCache;
|
|
143
151
|
const css = readThemeStylesheet();
|
|
152
|
+
if (_themeIdCache) return _themeIdCache;
|
|
144
153
|
const ids = new Set();
|
|
145
154
|
for (const m of css.matchAll(/^\.dm-theme-([a-z0-9-]+)\s*\{/gm)) ids.add(m[1]);
|
|
146
155
|
_themeIdCache = [...ids];
|
|
@@ -157,8 +166,8 @@ let _tokenNameCache = null;
|
|
|
157
166
|
* @returns {string[]}
|
|
158
167
|
*/
|
|
159
168
|
export function listThemeTokens() {
|
|
160
|
-
if (_tokenNameCache) return _tokenNameCache;
|
|
161
169
|
const css = readThemeStylesheet();
|
|
170
|
+
if (_tokenNameCache) return _tokenNameCache;
|
|
162
171
|
const names = new Set();
|
|
163
172
|
for (const m of css.matchAll(/(--dm-[a-z0-9-]+)\s*:/g)) names.add(m[1]);
|
|
164
173
|
_tokenNameCache = [...names].sort();
|
package/server/services/tools.js
CHANGED
|
@@ -65,7 +65,7 @@ export const CORE_TOOLS = Object.freeze([
|
|
|
65
65
|
{name: 'analytics', displayName: 'Analytics', icon: 'chart-bar', description: 'Page views and visitors, counted on this server.'},
|
|
66
66
|
{name: 'launchers', displayName: 'Launchers', icon: 'message-circle', description: 'Discs pinned to the page that open a page, a form or a chat - in a modal or a slideover.'},
|
|
67
67
|
{name: 'seo', displayName: 'SEO', icon: 'search', description: 'How the site looks to search engines: an audit of every page, redirects, the sitemap and robots.txt.'},
|
|
68
|
-
{name: 'wordpress-import', displayName: 'Import
|
|
68
|
+
{name: 'wordpress-import', displayName: 'Import a site', icon: 'download', description: 'Bring a site across from WordPress, Squarespace or Wix: pages, posts, media, menus, comments, WooCommerce products and redirects from the old addresses. Wix and other sites without an export are read from the live site.'}
|
|
69
69
|
]);
|
|
70
70
|
|
|
71
71
|
const CORE_NAMES = new Set(CORE_TOOLS.map(t => t.name));
|