@tideworthy/tidysites 0.1.16 → 0.1.18
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/bin/tidysites.mjs +16 -2
- package/lib/folder.mjs +12 -1
- package/package.json +1 -1
package/bin/tidysites.mjs
CHANGED
|
@@ -356,6 +356,7 @@ async function push(ctx) {
|
|
|
356
356
|
if (removeKeys.length) { const rem = readRemoved(ctx.dir); for (const k of removeKeys) rem.delete(k); writeRemoved(ctx.dir, rem); }
|
|
357
357
|
if (r.missing?.length) say(`Not found to remove: ${r.missing.map((m) => `${m.collection}/${m.slug}`).join(', ')}`);
|
|
358
358
|
}
|
|
359
|
+
const menuProblems = [];
|
|
359
360
|
for (const name of menus) {
|
|
360
361
|
const m = s.menus[name];
|
|
361
362
|
let items;
|
|
@@ -364,9 +365,22 @@ async function push(ctx) {
|
|
|
364
365
|
} catch (e) {
|
|
365
366
|
fail(`menus/${name}.json: ${e.message}`);
|
|
366
367
|
}
|
|
367
|
-
|
|
368
|
-
|
|
368
|
+
try {
|
|
369
|
+
try {
|
|
370
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } });
|
|
371
|
+
} catch (e) {
|
|
372
|
+
// A menu the website does not have yet (a phone drawer, a footer column) is created from the file, then filled.
|
|
373
|
+
if (!/not.?found/i.test(e.message ?? '')) throw e;
|
|
374
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_create', arguments: { name, label: m.label || name } });
|
|
375
|
+
await tool(ctx.cfg, 'call_website_site_tool', { site_id: ctx.cfg.site, tool: 'menu_set_items', arguments: { name, items } });
|
|
376
|
+
say(`Menu ${name}: created.`);
|
|
377
|
+
}
|
|
378
|
+
say(`Menu ${name}: ${items.length} item${items.length === 1 ? '' : 's'} written.`);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
menuProblems.push(`menus/${name}.json: ${e.message}`);
|
|
381
|
+
}
|
|
369
382
|
}
|
|
383
|
+
if (menuProblems.length) fail(menuProblems.join('\n'));
|
|
370
384
|
// Refresh only what went, and take the website's version of exactly those entries; every other file stays as it is.
|
|
371
385
|
const pushed = new Set([...keys, ...menus.map((m) => `menus/${m}`)]);
|
|
372
386
|
if (touched.length) await pull(ctx, touched, { overwrite: pushed, menus: menus.length > 0 });
|
package/lib/folder.mjs
CHANGED
|
@@ -145,9 +145,20 @@ export function pushDocument(local, snapshot, { keys, removeKeys = [], settings
|
|
|
145
145
|
// so the names the snapshot had and the file no longer has go as null.
|
|
146
146
|
const data = { ...e.data };
|
|
147
147
|
if (was?.data) for (const k of Object.keys(was.data)) if (!(k in data) && !emptyValue(was.data[k])) data[k] = null;
|
|
148
|
-
|
|
148
|
+
// A new entry's seed key is its slug, so "$ref:<slug>" from another file resolves to it once it is created.
|
|
149
|
+
(content[collection] ??= []).push({ id: e.id || slug, slug, status: e.status, data });
|
|
149
150
|
if (was?.updated_at) expect[key] = was.updated_at;
|
|
150
151
|
}
|
|
152
|
+
// "$ref:<slug>" (or "$ref:<collection>/<slug>") to an entry the folder already knows the website's id for becomes that id; a reference to an entry created by this same push stays for the website to resolve.
|
|
153
|
+
const ids = new Map();
|
|
154
|
+
for (const [k, e] of Object.entries(local)) if (e?.id) { const [, slug] = splitKey(k); ids.set(slug, e.id); ids.set(k, e.id); }
|
|
155
|
+
const resolveRefs = (v) => {
|
|
156
|
+
if (typeof v === 'string' && v.startsWith('$ref:')) { const target = v.slice(5).trim(); const id = ids.get(target) ?? ids.get(target.split('/').pop()); return id ?? `$ref:${target.split('/').pop()}`; }
|
|
157
|
+
if (Array.isArray(v)) return v.map(resolveRefs);
|
|
158
|
+
if (v && typeof v === 'object') return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolveRefs(x)]));
|
|
159
|
+
return v;
|
|
160
|
+
};
|
|
161
|
+
for (const entries of Object.values(content)) for (const e of entries) e.data = resolveRefs(e.data);
|
|
151
162
|
const remove = {};
|
|
152
163
|
for (const key of removeKeys) {
|
|
153
164
|
const [collection, slug] = splitKey(key);
|
package/package.json
CHANGED