redirect-map-plan 0.1.0 → 0.2.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 +6 -0
- package/README.md +36 -2
- package/bin/redirect-map-plan.js +72 -1
- package/package.json +2 -2
- package/src/open.js +22 -0
- package/src/plan.js +40 -8
- package/src/ui/client.js +527 -0
- package/src/ui/page.js +265 -0
- package/src/ui/server.js +554 -0
- package/src/write.js +7 -2
package/src/ui/client.js
ADDED
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
// Browser script for the local interface. Plain JavaScript, no libraries.
|
|
2
|
+
// Every piece of data from a plan is added with textContent; links are only made for
|
|
3
|
+
// http(s) URLs. Nothing here uses innerHTML.
|
|
4
|
+
(() => {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const $ = (id) => document.getElementById(id);
|
|
8
|
+
|
|
9
|
+
// The token arrives once in the address; keep it for this tab and take it out of the
|
|
10
|
+
// address bar (and this history entry), so it isn't left in history or shared by accident.
|
|
11
|
+
let token = '';
|
|
12
|
+
try {
|
|
13
|
+
token = new URLSearchParams(location.search).get('t') || sessionStorage.getItem('rmp-token') || '';
|
|
14
|
+
if (token) sessionStorage.setItem('rmp-token', token);
|
|
15
|
+
} catch {
|
|
16
|
+
token = new URLSearchParams(location.search).get('t') || '';
|
|
17
|
+
}
|
|
18
|
+
if (location.search) history.replaceState(null, '', location.pathname);
|
|
19
|
+
if (!token) {
|
|
20
|
+
$('no-token').hidden = false;
|
|
21
|
+
$('form-section').hidden = true;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const PAGE = 200;
|
|
25
|
+
|
|
26
|
+
const el = (tag, cls, text) => {
|
|
27
|
+
const node = document.createElement(tag);
|
|
28
|
+
if (cls) node.className = cls;
|
|
29
|
+
if (text !== undefined && text !== null) node.textContent = String(text);
|
|
30
|
+
return node;
|
|
31
|
+
};
|
|
32
|
+
const isHttp = (value) => /^https?:\/\//i.test(String(value || ''));
|
|
33
|
+
const plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
|
|
34
|
+
|
|
35
|
+
const get = async (path) => {
|
|
36
|
+
const res = await fetch(path, { headers: { 'x-rmp-token': token } });
|
|
37
|
+
if (res.status === 403) {
|
|
38
|
+
$('no-token').hidden = false;
|
|
39
|
+
$('form-section').hidden = true;
|
|
40
|
+
try {
|
|
41
|
+
sessionStorage.removeItem('rmp-token');
|
|
42
|
+
} catch {
|
|
43
|
+
/* nothing stored */
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return res;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const post = async (path, body) => {
|
|
50
|
+
const res = await fetch(path, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: { 'content-type': 'application/json', 'x-rmp-token': token },
|
|
53
|
+
body: JSON.stringify(body || {}),
|
|
54
|
+
});
|
|
55
|
+
const data = await res.json().catch(() => ({}));
|
|
56
|
+
if (!res.ok) throw Object.assign(new Error(data.error || `HTTP ${res.status}`), { data, status: res.status });
|
|
57
|
+
return data;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const readFile = (file) =>
|
|
61
|
+
new Promise((resolve, reject) => {
|
|
62
|
+
const reader = new FileReader();
|
|
63
|
+
reader.onload = () => resolve({ name: file.name, data: String(reader.result).split(',')[1] || '' });
|
|
64
|
+
reader.onerror = () => reject(reader.error || new Error(`Could not read ${file.name}`));
|
|
65
|
+
reader.readAsDataURL(file);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ---- Form: platforms, defaults from the command line, drop zones ----
|
|
69
|
+
|
|
70
|
+
const option = (value, label) => {
|
|
71
|
+
const o = el('option', '', label);
|
|
72
|
+
o.value = value;
|
|
73
|
+
return o;
|
|
74
|
+
};
|
|
75
|
+
const showTargetSetting = () => {
|
|
76
|
+
$('w-blog').hidden = $('f-to').value !== 'shopify';
|
|
77
|
+
$('w-collection').hidden = $('f-to').value !== 'webflow';
|
|
78
|
+
};
|
|
79
|
+
$('f-to').addEventListener('change', showTargetSetting);
|
|
80
|
+
|
|
81
|
+
const showDefault = (key, text) => {
|
|
82
|
+
$(`c-default-${key}`).hidden = false;
|
|
83
|
+
$(`t-default-${key}`).textContent = text;
|
|
84
|
+
};
|
|
85
|
+
const applyDefaults = (d) => {
|
|
86
|
+
for (const p of d.platforms.from) $('f-from').append(option(p.id, p.id === 'other' ? 'Other (URL patterns only)' : p.name));
|
|
87
|
+
for (const p of d.platforms.to) $('f-to').append(option(p.id, p.name));
|
|
88
|
+
if (d.from) $('f-from').value = d.from;
|
|
89
|
+
if (d.to) $('f-to').value = d.to;
|
|
90
|
+
showTargetSetting();
|
|
91
|
+
if (d.sitemaps?.length) $('f-sitemaps').value = d.sitemaps.join('\n');
|
|
92
|
+
if (d.oldBase) $('f-oldbase').value = d.oldBase;
|
|
93
|
+
if (d.blogHandle) $('f-blog').value = d.blogHandle;
|
|
94
|
+
if (d.postsCollection) $('f-collection').value = d.postsCollection;
|
|
95
|
+
$('f-titles').checked = Boolean(d.titles);
|
|
96
|
+
$('f-ignore-robots').checked = Boolean(d.ignoreRobots);
|
|
97
|
+
$('f-private').checked = Boolean(d.allowPrivateNetwork);
|
|
98
|
+
const fields = { delay: 'f-delay', concurrency: 'f-concurrency', timeout: 'f-timeout', limit: 'f-limit' };
|
|
99
|
+
for (const [key, value] of Object.entries(d.numbers || {})) if (fields[key]) $(fields[key]).value = value;
|
|
100
|
+
const files = (list) => (list.length === 1 ? list[0] : `${list.length} files: ${list.join(', ')}`);
|
|
101
|
+
if (d.localOld?.length) showDefault('old', `Use ${files(d.localOld)} (from the command line)`);
|
|
102
|
+
if (d.oldRedirects) showDefault('oldredirects', `Use ${d.oldRedirects} (from the command line)`);
|
|
103
|
+
if (d.rulesFile) showDefault('rules', `Use ${d.rulesFile} (from the command line)`);
|
|
104
|
+
if (d.ignoreRobots || d.allowPrivateNetwork || Object.keys(d.numbers || {}).length) $('advanced').open = true;
|
|
105
|
+
};
|
|
106
|
+
get('/api/defaults')
|
|
107
|
+
.then((res) => (res.ok ? res.json() : null))
|
|
108
|
+
.then((d) => d && applyDefaults(d))
|
|
109
|
+
.catch(() => {});
|
|
110
|
+
|
|
111
|
+
const dropZone = (zoneId, inputId) => {
|
|
112
|
+
const zone = $(zoneId);
|
|
113
|
+
const input = $(inputId);
|
|
114
|
+
const text = zone.querySelector('.ui_drop-text');
|
|
115
|
+
const empty = text.textContent;
|
|
116
|
+
const update = () => {
|
|
117
|
+
const names = [...input.files].map((f) => f.name);
|
|
118
|
+
zone.classList.toggle('has-file', names.length > 0);
|
|
119
|
+
text.textContent = names.length ? names.join(', ') : empty;
|
|
120
|
+
};
|
|
121
|
+
input.addEventListener('change', update);
|
|
122
|
+
for (const ev of ['dragenter', 'dragover']) zone.addEventListener(ev, () => zone.classList.add('is-over'));
|
|
123
|
+
for (const ev of ['dragleave', 'drop']) zone.addEventListener(ev, () => zone.classList.remove('is-over'));
|
|
124
|
+
};
|
|
125
|
+
dropZone('d-old', 'f-oldfiles');
|
|
126
|
+
dropZone('d-oldredirects', 'f-oldredirects');
|
|
127
|
+
dropZone('d-rules', 'f-rules');
|
|
128
|
+
|
|
129
|
+
const formError = (message) => {
|
|
130
|
+
$('form-error').hidden = !message;
|
|
131
|
+
$('form-error').textContent = message || '';
|
|
132
|
+
};
|
|
133
|
+
for (const id of ['f-sitemaps', 'f-oldfiles', 'f-oldbase', 'f-from', 'f-to', 'f-blog', 'f-collection']) $(id).addEventListener('input', () => formError(''));
|
|
134
|
+
|
|
135
|
+
const usingDefault = (key) => !$(`c-default-${key}`).hidden && $(`f-default-${key}`).checked;
|
|
136
|
+
|
|
137
|
+
async function submit() {
|
|
138
|
+
formError('');
|
|
139
|
+
const sitemaps = $('f-sitemaps').value.split(/\s+/).filter(Boolean);
|
|
140
|
+
const bad = sitemaps.find((s) => !isHttp(s));
|
|
141
|
+
if (bad) return formError(`"${bad}" isn't a web address. Paste a sitemap URL, or drop a saved file instead.`);
|
|
142
|
+
const oldFiles = [...$('f-oldfiles').files];
|
|
143
|
+
if (!sitemaps.length && !oldFiles.length && !usingDefault('old')) return formError('Add the old sitemap URL, or drop a saved sitemap or a list of URLs.');
|
|
144
|
+
const oldBase = $('f-oldbase').value.trim();
|
|
145
|
+
if (oldBase && !isHttp(oldBase)) return formError(`"${oldBase}" isn't a web address (it should start with https://).`);
|
|
146
|
+
$('run').disabled = true;
|
|
147
|
+
$('run-hint').textContent = 'Starting…';
|
|
148
|
+
try {
|
|
149
|
+
const oldRedirects = $('f-oldredirects').files[0];
|
|
150
|
+
const rules = $('f-rules').files[0];
|
|
151
|
+
await post('/api/run', {
|
|
152
|
+
sitemaps,
|
|
153
|
+
useDefaultOld: usingDefault('old'),
|
|
154
|
+
oldFiles: await Promise.all(oldFiles.map(readFile)),
|
|
155
|
+
oldBase,
|
|
156
|
+
from: $('f-from').value,
|
|
157
|
+
to: $('f-to').value,
|
|
158
|
+
blogHandle: $('w-blog').hidden ? '' : $('f-blog').value.trim(),
|
|
159
|
+
postsCollection: $('w-collection').hidden ? '' : $('f-collection').value.trim(),
|
|
160
|
+
oldRedirectsFile: oldRedirects ? await readFile(oldRedirects) : null,
|
|
161
|
+
useDefaultOldRedirects: usingDefault('oldredirects'),
|
|
162
|
+
rulesFile: rules ? await readFile(rules) : null,
|
|
163
|
+
useDefaultRules: usingDefault('rules'),
|
|
164
|
+
titles: $('f-titles').checked,
|
|
165
|
+
delay: $('f-delay').value,
|
|
166
|
+
concurrency: $('f-concurrency').value,
|
|
167
|
+
timeout: $('f-timeout').value,
|
|
168
|
+
limit: $('f-limit').value,
|
|
169
|
+
ignoreRobots: $('f-ignore-robots').checked,
|
|
170
|
+
allowPrivateNetwork: $('f-private').checked,
|
|
171
|
+
});
|
|
172
|
+
$('run-hint').textContent = '';
|
|
173
|
+
} catch (err) {
|
|
174
|
+
formError(err.message);
|
|
175
|
+
$('run').disabled = false;
|
|
176
|
+
$('run-hint').textContent = '';
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
$('rmp-form').addEventListener('submit', (event) => {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
submit();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// ---- Progress (server-sent events) ----
|
|
186
|
+
|
|
187
|
+
const PHASES = {
|
|
188
|
+
suggest: 'Reading the URLs to see which platform they come from',
|
|
189
|
+
read: 'Reading the old URLs',
|
|
190
|
+
place: 'Placing each URL with the new platform’s rules',
|
|
191
|
+
'old-redirects': 'Reading the old redirects',
|
|
192
|
+
titles: 'Reading the old pages’ titles',
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const resetForRun = () => {
|
|
196
|
+
$('progress').hidden = false;
|
|
197
|
+
for (const id of ['suggestion', 'results', 'stats-section', 'settings-section', 'warnings-section', 'next-section', 'list-section']) $(id).hidden = true;
|
|
198
|
+
$('phase').textContent = 'Starting…';
|
|
199
|
+
$('progress-count').textContent = '';
|
|
200
|
+
$('bar-wrap').classList.add('is-indeterminate');
|
|
201
|
+
$('bar').style.width = '0';
|
|
202
|
+
$('live').replaceChildren();
|
|
203
|
+
$('cancel').hidden = false;
|
|
204
|
+
$('cancel').disabled = false;
|
|
205
|
+
$('run').disabled = true;
|
|
206
|
+
};
|
|
207
|
+
const finished = () => {
|
|
208
|
+
$('cancel').hidden = true;
|
|
209
|
+
$('run').disabled = false;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const handle = async (event) => {
|
|
213
|
+
switch (event.type) {
|
|
214
|
+
case 'start':
|
|
215
|
+
resetForRun();
|
|
216
|
+
$('progress').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
217
|
+
break;
|
|
218
|
+
case 'phase':
|
|
219
|
+
$('phase').textContent = PHASES[event.name] || event.name;
|
|
220
|
+
$('bar-wrap').classList.toggle('is-indeterminate', event.name !== 'titles');
|
|
221
|
+
if (event.name === 'place' && event.urls) $('progress-count').textContent = plural(event.urls, 'old URL', 'old URLs');
|
|
222
|
+
break;
|
|
223
|
+
case 'progress': {
|
|
224
|
+
const pct = event.total ? Math.round((event.done / event.total) * 100) : 0;
|
|
225
|
+
$('bar').style.width = `${pct}%`;
|
|
226
|
+
$('progress-count').textContent = `${event.done} of ${plural(event.total, 'page', 'pages')} · ${pct}%`;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case 'page': {
|
|
230
|
+
const row = el('div', 'ui_live-row');
|
|
231
|
+
row.append(el('span', '', event.status || '–'), el('span', '', event.title ? `${event.url} · ${event.title}` : event.url));
|
|
232
|
+
$('live').prepend(row);
|
|
233
|
+
if ($('live').childElementCount > 500) $('live').lastElementChild.remove();
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case 'suggested':
|
|
237
|
+
$('progress').hidden = true;
|
|
238
|
+
finished();
|
|
239
|
+
showSuggestion(event.suggestions || []);
|
|
240
|
+
break;
|
|
241
|
+
case 'done':
|
|
242
|
+
$('phase').textContent = 'Done';
|
|
243
|
+
$('bar-wrap').classList.remove('is-indeterminate');
|
|
244
|
+
$('bar').style.width = '100%';
|
|
245
|
+
finished();
|
|
246
|
+
await loadResults();
|
|
247
|
+
break;
|
|
248
|
+
case 'cancelled':
|
|
249
|
+
$('phase').textContent = 'Cancelled';
|
|
250
|
+
finished();
|
|
251
|
+
break;
|
|
252
|
+
case 'error':
|
|
253
|
+
$('phase').textContent = 'The plan stopped';
|
|
254
|
+
$('progress-count').textContent = event.message || '';
|
|
255
|
+
$('bar-wrap').classList.remove('is-indeterminate');
|
|
256
|
+
finished();
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const events = new EventSource(`/api/events?t=${encodeURIComponent(token)}`);
|
|
263
|
+
events.onmessage = (message) => {
|
|
264
|
+
try {
|
|
265
|
+
handle(JSON.parse(message.data));
|
|
266
|
+
} catch {
|
|
267
|
+
/* ignore a malformed event */
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
$('cancel').addEventListener('click', async () => {
|
|
272
|
+
$('cancel').disabled = true;
|
|
273
|
+
try {
|
|
274
|
+
await post('/api/cancel');
|
|
275
|
+
} catch (err) {
|
|
276
|
+
$('progress-count').textContent = err.message;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// ---- Platform suggestion: show the evidence, let the person pick ----
|
|
281
|
+
|
|
282
|
+
function showSuggestion(list) {
|
|
283
|
+
$('suggestion').hidden = false;
|
|
284
|
+
const buttons = $('suggest-buttons');
|
|
285
|
+
buttons.replaceChildren();
|
|
286
|
+
const pick = (id, label, primary) => {
|
|
287
|
+
const b = el('button', primary ? 'button' : 'button is-secondary', label);
|
|
288
|
+
b.type = 'button';
|
|
289
|
+
b.addEventListener('click', () => {
|
|
290
|
+
$('f-from').value = id;
|
|
291
|
+
$('suggestion').hidden = true;
|
|
292
|
+
if (!$('f-to').value) {
|
|
293
|
+
$('form-section').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
294
|
+
return formError('Pick where the site is going, then make the plan.');
|
|
295
|
+
}
|
|
296
|
+
return submit();
|
|
297
|
+
});
|
|
298
|
+
buttons.append(b);
|
|
299
|
+
};
|
|
300
|
+
if (!list.length) {
|
|
301
|
+
$('suggest-title').textContent = 'We found no platform signals in the URLs.';
|
|
302
|
+
$('suggest-evidence').replaceChildren();
|
|
303
|
+
$('suggest-others').textContent = 'If the old site isn’t on Webflow, WordPress, Shopify or Wix, plan it as Other (URL patterns only).';
|
|
304
|
+
pick('other', 'Plan it as Other', true);
|
|
305
|
+
} else {
|
|
306
|
+
const [top, ...rest] = list;
|
|
307
|
+
$('suggest-title').textContent = `The URLs look most like ${top.name}.`;
|
|
308
|
+
$('suggest-evidence').replaceChildren(...top.evidence.map((e) => el('li', '', e)));
|
|
309
|
+
$('suggest-others').textContent = rest.length ? `Also possible: ${rest.map((r) => `${r.name} (${r.evidence.join('; ')})`).join(', ')}.` : '';
|
|
310
|
+
pick(top.id, `Yes, plan it from ${top.name}`, true);
|
|
311
|
+
for (const r of rest) pick(r.id, `Plan it from ${r.name}`, false);
|
|
312
|
+
}
|
|
313
|
+
const choose = el('button', 'button is-secondary', 'Choose in the form');
|
|
314
|
+
choose.type = 'button';
|
|
315
|
+
choose.addEventListener('click', () => {
|
|
316
|
+
$('suggestion').hidden = true;
|
|
317
|
+
$('form-section').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
318
|
+
$('f-from').focus();
|
|
319
|
+
});
|
|
320
|
+
buttons.append(choose);
|
|
321
|
+
$('suggestion').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ---- Results ----
|
|
325
|
+
|
|
326
|
+
const OUTCOME = {
|
|
327
|
+
changes: 'Must change',
|
|
328
|
+
'old-redirect': 'Old redirect',
|
|
329
|
+
blocked: 'Blocked',
|
|
330
|
+
setting: 'One setting',
|
|
331
|
+
keeps: 'Keeps its URL',
|
|
332
|
+
drop: 'Not carried over',
|
|
333
|
+
decide: 'You decide',
|
|
334
|
+
skip: 'Skipped',
|
|
335
|
+
};
|
|
336
|
+
const state = { data: null, outcome: 'all', query: '', shown: PAGE };
|
|
337
|
+
|
|
338
|
+
const headline = (d) => {
|
|
339
|
+
const s = d.summary;
|
|
340
|
+
return s.changes
|
|
341
|
+
? `${s.changes} of ${plural(s.urls, 'URL', 'URLs')} ${s.changes === 1 ? 'needs' : 'need'} a redirect moving from ${d.from.name} to ${d.to.name}.`
|
|
342
|
+
: `All ${plural(s.urls, 'URL', 'URLs')} can keep their address moving from ${d.from.name} to ${d.to.name}.`;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const listItem = (strong, detail, examples) => {
|
|
346
|
+
const li = el('li');
|
|
347
|
+
li.append(el('b', '', strong));
|
|
348
|
+
const parts = [detail, examples && examples.length ? `For example ${examples.join(', ')}.` : ''].filter(Boolean);
|
|
349
|
+
if (parts.length) li.append(el('p', 'plan_notes', parts.join(' ')));
|
|
350
|
+
return li;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
async function loadResults() {
|
|
354
|
+
const res = await get('/api/results');
|
|
355
|
+
if (!res.ok) return;
|
|
356
|
+
const data = await res.json();
|
|
357
|
+
state.data = data;
|
|
358
|
+
state.outcome = 'all';
|
|
359
|
+
state.query = '';
|
|
360
|
+
state.shown = PAGE;
|
|
361
|
+
$('search').value = '';
|
|
362
|
+
const s = data.summary;
|
|
363
|
+
for (const id of ['results', 'stats-section', 'next-section', 'list-section']) $(id).hidden = false;
|
|
364
|
+
$('headline').textContent = headline(data);
|
|
365
|
+
$('results-meta').textContent = `${plural(s.urls, 'URL', 'URLs')} · ${plural(s.rows, 'redirect row', 'redirect rows')} · ${plural(s.requests, 'request', 'requests')} · ${(s.durationMs / 1000).toFixed(1)} s`;
|
|
366
|
+
|
|
367
|
+
// Downloads: the full plan opens in a new tab; the rest are files.
|
|
368
|
+
const downloads = $('downloads');
|
|
369
|
+
downloads.replaceChildren();
|
|
370
|
+
for (const name of data.files) {
|
|
371
|
+
const b = el('button', name === 'plan.html' ? 'button' : 'button is-secondary', name === 'plan.html' ? 'Open the full plan' : name);
|
|
372
|
+
b.type = 'button';
|
|
373
|
+
b.addEventListener('click', () => download(name, b));
|
|
374
|
+
downloads.append(b);
|
|
375
|
+
}
|
|
376
|
+
const save = el('button', 'button is-secondary', 'Save to folder');
|
|
377
|
+
save.type = 'button';
|
|
378
|
+
save.id = 'save';
|
|
379
|
+
save.addEventListener('click', () => saveToFolder(save));
|
|
380
|
+
downloads.append(save);
|
|
381
|
+
saveOverwrite = false;
|
|
382
|
+
$('saved').textContent = '';
|
|
383
|
+
|
|
384
|
+
const stats = $('stats');
|
|
385
|
+
stats.replaceChildren();
|
|
386
|
+
for (const [n, label] of [
|
|
387
|
+
[s.keeps, 'Keep their URL'],
|
|
388
|
+
[s.setting, 'With one setting'],
|
|
389
|
+
[s.changes, 'Must change'],
|
|
390
|
+
[s.blocked + s.drop + s.decide, 'Blocked, not carried over or to decide'],
|
|
391
|
+
]) {
|
|
392
|
+
const cell = el('div', 'stats_cell');
|
|
393
|
+
cell.append(el('p', 'stats_number', n), el('p', 'text-style-mono text-color-grey', label));
|
|
394
|
+
stats.append(cell);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
$('settings-section').hidden = !data.settings.length;
|
|
398
|
+
$('settings-title').textContent = `Settings to make on the new platform · ${data.settings.length}`;
|
|
399
|
+
$('settings-lead').textContent = `Make these settings on ${data.to.name}. Some let old URLs keep their address with no redirect; others are needed for the new addresses in the plan.`;
|
|
400
|
+
const sentence = (t) => `${t.charAt(0).toUpperCase()}${t.slice(1)}.`;
|
|
401
|
+
$('settings').replaceChildren(...data.settings.map((x) => listItem(x.text, sentence(x.effect), x.examples)));
|
|
402
|
+
|
|
403
|
+
$('warnings-section').hidden = !data.warnings.length;
|
|
404
|
+
$('warnings-title').textContent = `Check these · ${data.warnings.length}`;
|
|
405
|
+
$('warnings').replaceChildren(...data.warnings.map((w) => el('li', '', w.text)));
|
|
406
|
+
|
|
407
|
+
$('next-lead').textContent = `Import ${data.redirectFile} on ${data.to.name} (${plural(s.rows, 'row', 'rows')}), then test the redirects with redirect-map-check. Before launch, against the staging site (change the staging address, and run it in the folder that holds redirect-map.csv):`;
|
|
408
|
+
$('command').textContent = data.command;
|
|
409
|
+
$('copied').textContent = '';
|
|
410
|
+
|
|
411
|
+
const chips = $('chips');
|
|
412
|
+
chips.replaceChildren();
|
|
413
|
+
const counts = {};
|
|
414
|
+
for (const p of data.items) counts[p.outcome] = (counts[p.outcome] || 0) + 1;
|
|
415
|
+
for (const [key, label] of [['all', `All ${data.items.length}`], ...Object.keys(OUTCOME).filter((k) => counts[k]).map((k) => [k, `${OUTCOME[k]} ${counts[k]}`])]) {
|
|
416
|
+
const chip = el('button', 'ui_chip', label);
|
|
417
|
+
chip.type = 'button';
|
|
418
|
+
chip.dataset.outcome = key;
|
|
419
|
+
chip.setAttribute('aria-pressed', String(key === 'all'));
|
|
420
|
+
chip.addEventListener('click', () => {
|
|
421
|
+
state.outcome = key;
|
|
422
|
+
state.shown = PAGE;
|
|
423
|
+
for (const c of chips.children) c.setAttribute('aria-pressed', String(c.dataset.outcome === key));
|
|
424
|
+
render();
|
|
425
|
+
});
|
|
426
|
+
chips.append(chip);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
$('notes').replaceChildren(...data.notes.map((n) => el('li', '', n)));
|
|
430
|
+
$('notes-wrap').hidden = data.notes.length === 0;
|
|
431
|
+
render();
|
|
432
|
+
$('results').scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function row(p) {
|
|
436
|
+
const tr = el('tr');
|
|
437
|
+
tr.append(el('td', 'is-path', `${p.path}${p.query ? `?${p.query}` : ''}`));
|
|
438
|
+
const outcome = el('td');
|
|
439
|
+
outcome.append(el('span', `plan_outcome is-${p.outcome}`, OUTCOME[p.outcome] || p.outcome));
|
|
440
|
+
tr.append(outcome, el('td', 'is-path', p.newPath || '–'));
|
|
441
|
+
const notes = el('td');
|
|
442
|
+
if (p.notes.length) notes.append(el('p', 'plan_notes', p.notes.join(' ')));
|
|
443
|
+
tr.append(notes);
|
|
444
|
+
return tr;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function filtered() {
|
|
448
|
+
const q = state.query.toLowerCase();
|
|
449
|
+
return state.data.items.filter((p) => (state.outcome === 'all' || p.outcome === state.outcome) && (!q || `${p.path}?${p.query} ${p.newPath || ''} ${p.notes.join(' ')}`.toLowerCase().includes(q)));
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
function render() {
|
|
453
|
+
if (!state.data) return;
|
|
454
|
+
const items = filtered();
|
|
455
|
+
$('list').replaceChildren(...items.slice(0, state.shown).map(row));
|
|
456
|
+
$('more').hidden = items.length <= state.shown;
|
|
457
|
+
$('shown').textContent = items.length ? `Showing ${Math.min(items.length, state.shown)} of ${plural(items.length, 'URL', 'URLs')}` : 'No URLs match these filters.';
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
$('search').addEventListener('input', () => {
|
|
461
|
+
state.query = $('search').value;
|
|
462
|
+
state.shown = PAGE;
|
|
463
|
+
render();
|
|
464
|
+
});
|
|
465
|
+
$('more').addEventListener('click', () => {
|
|
466
|
+
state.shown += PAGE;
|
|
467
|
+
render();
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
$('copy').addEventListener('click', async () => {
|
|
471
|
+
try {
|
|
472
|
+
await navigator.clipboard.writeText($('command').textContent);
|
|
473
|
+
$('copied').textContent = 'Copied.';
|
|
474
|
+
} catch {
|
|
475
|
+
$('copied').textContent = 'Select the command and copy it.';
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// Downloads go through fetch with the token header, so no address with the token ends up
|
|
480
|
+
// in the browser's history or download list.
|
|
481
|
+
async function download(name, button) {
|
|
482
|
+
button.disabled = true;
|
|
483
|
+
try {
|
|
484
|
+
const res = await get(`/api/download/${encodeURIComponent(name)}`);
|
|
485
|
+
if (!res.ok) throw new Error(`Could not get ${name} (HTTP ${res.status}).`);
|
|
486
|
+
const blob = await res.blob();
|
|
487
|
+
const href = URL.createObjectURL(name === 'plan.html' ? new Blob([blob], { type: 'text/html' }) : blob);
|
|
488
|
+
const a = document.createElement('a');
|
|
489
|
+
a.href = href;
|
|
490
|
+
if (name === 'plan.html') {
|
|
491
|
+
a.target = '_blank';
|
|
492
|
+
a.rel = 'noopener';
|
|
493
|
+
} else {
|
|
494
|
+
a.download = name;
|
|
495
|
+
}
|
|
496
|
+
document.body.append(a);
|
|
497
|
+
a.click();
|
|
498
|
+
a.remove();
|
|
499
|
+
// The plan tab may be reloaded, so its link lives as long as this page; downloads don't need it after a minute.
|
|
500
|
+
if (name !== 'plan.html') setTimeout(() => URL.revokeObjectURL(href), 60_000);
|
|
501
|
+
} catch (err) {
|
|
502
|
+
$('saved').textContent = err.message;
|
|
503
|
+
} finally {
|
|
504
|
+
button.disabled = false;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
let saveOverwrite = false;
|
|
509
|
+
async function saveToFolder(button) {
|
|
510
|
+
$('saved').textContent = 'Saving…';
|
|
511
|
+
try {
|
|
512
|
+
const answer = await post('/api/save', { overwrite: saveOverwrite });
|
|
513
|
+
if (answer.exists) {
|
|
514
|
+
saveOverwrite = true;
|
|
515
|
+
button.textContent = 'Replace the saved plan';
|
|
516
|
+
$('saved').textContent = `${answer.path} already has a plan. Click again to replace it.`;
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
$('saved').textContent = `Saved to ${answer.path}.${answer.stalePages ? ' The old-pages.json already there is from an earlier run; we kept it.' : ''}`;
|
|
520
|
+
if (answer.command) $('command').textContent = answer.command;
|
|
521
|
+
saveOverwrite = false;
|
|
522
|
+
button.textContent = 'Save to folder';
|
|
523
|
+
} catch (err) {
|
|
524
|
+
$('saved').textContent = err.message;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
})();
|