@realiizlabs/admin 0.15.9 → 0.16.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.
@@ -151,6 +151,12 @@ interface PublishInput {
151
151
  } | null;
152
152
  /** Pictures chosen in this session, already shrunk in the browser; committed with the MDX. */
153
153
  images?: ImagePayload[];
154
+ /**
155
+ * The slug this item was opened as (edits only). When the new frontmatter produces a
156
+ * different file name — a date-prefixed event whose date moved — the old file is removed
157
+ * in the same commit, so an edit never leaves a stale copy behind.
158
+ */
159
+ replaces?: string | null;
154
160
  }
155
161
  type PublishResult = {
156
162
  ok: false;
@@ -249,6 +255,7 @@ declare function createStudio(config: StudioConfig): {
249
255
  pendingFor: (path: string) => Promise<PendingChange | null>;
250
256
  pathOf: (typeId: string, slug: string) => Promise<string | null>;
251
257
  listItems: (typeId: string) => Promise<ListItem[]>;
258
+ listSlugs: (typeId: string) => Promise<string[]>;
252
259
  countItems: (typeId: string) => Promise<number>;
253
260
  readItem: (typeId: string, slug: string, opts?: {
254
261
  ref?: string;
@@ -151,6 +151,12 @@ interface PublishInput {
151
151
  } | null;
152
152
  /** Pictures chosen in this session, already shrunk in the browser; committed with the MDX. */
153
153
  images?: ImagePayload[];
154
+ /**
155
+ * The slug this item was opened as (edits only). When the new frontmatter produces a
156
+ * different file name — a date-prefixed event whose date moved — the old file is removed
157
+ * in the same commit, so an edit never leaves a stale copy behind.
158
+ */
159
+ replaces?: string | null;
154
160
  }
155
161
  type PublishResult = {
156
162
  ok: false;
@@ -249,6 +255,7 @@ declare function createStudio(config: StudioConfig): {
249
255
  pendingFor: (path: string) => Promise<PendingChange | null>;
250
256
  pathOf: (typeId: string, slug: string) => Promise<string | null>;
251
257
  listItems: (typeId: string) => Promise<ListItem[]>;
258
+ listSlugs: (typeId: string) => Promise<string[]>;
252
259
  countItems: (typeId: string) => Promise<number>;
253
260
  readItem: (typeId: string, slug: string, opts?: {
254
261
  ref?: string;
@@ -404,6 +404,10 @@ function makeReaders(config, registry, pending) {
404
404
  const entries = await listDirectory(repo(), e.folder);
405
405
  return entries.find((x) => registry.slugOf(e, x.name) === slug)?.path ?? null;
406
406
  };
407
+ const listSlugs = async (typeId) => {
408
+ const items = await listItems(typeId);
409
+ return items.filter((i) => !i.isNew).map((i) => i.slug).sort();
410
+ };
407
411
  const listItems = async (typeId) => {
408
412
  const e = need(typeId);
409
413
  const ctx = repo();
@@ -479,7 +483,7 @@ function makeReaders(config, registry, pending) {
479
483
  }
480
484
  };
481
485
  const prStatus = (number) => getPullRequestStatus(repo(), number);
482
- return { pathOf, listItems, countItems, readItem, lastAuthor, getPullRequest: getPullRequest2, prStatus };
486
+ return { pathOf, listItems, listSlugs, countItems, readItem, lastAuthor, getPullRequest: getPullRequest2, prStatus };
483
487
  }
484
488
 
485
489
  // src/git/branch.ts
@@ -601,18 +605,22 @@ ${input.body.trim()}
601
605
  if (!pictures.ok) return { ok: false, error: pictures.error };
602
606
  const files = [{ path, content }, ...pictures.files];
603
607
  const repo = config.env().repo;
608
+ const oldPath = input.replaces ? await readers.pathOf(entry.id, input.replaces).catch(() => null) : null;
609
+ const remove = oldPath && oldPath !== path ? [oldPath] : [];
610
+ const renamed = remove.length ? `
611
+ Renamed from \`${oldPath}\` to \`${path}\`` : "";
604
612
  if (input.existing && await stillOpen(input.existing.number)) {
605
- await writeFiles(repo, input.existing.branch, files, `Update: ${title}`);
613
+ await writeFiles(repo, input.existing.branch, files, `Update: ${title}`, { remove });
606
614
  redirect(`/admin/pr/${input.existing.number}`);
607
615
  }
608
616
  const branch = `admin/${entry.id}/${fileName.replace(/\.mdx$/, "")}-${stamp()}`;
609
617
  await createBranch(repo, branch);
610
- await writeFiles(repo, branch, files, `Publish: ${title}`);
618
+ await writeFiles(repo, branch, files, `Publish: ${title}`, { remove });
611
619
  const pr = await openPullRequest(repo, branch, {
612
620
  title: `Publish: ${title}`,
613
621
  body: `Published from the dashboard by ${user.email ?? user.id}.
614
622
 
615
- File: \`${path}\``
623
+ File: \`${path}\`${renamed}`
616
624
  });
617
625
  redirect(`/admin/pr/${pr.number}`);
618
626
  };
@@ -1103,7 +1111,7 @@ function makeHandlers(ctx) {
1103
1111
  }
1104
1112
 
1105
1113
  // src/version.ts
1106
- var ADMIN_VERSION = "0.15.9" ;
1114
+ var ADMIN_VERSION = "0.16.0" ;
1107
1115
 
1108
1116
  // src/studio/update.ts
1109
1117
  var PACKAGE_NAME = "@realiizlabs/admin";