Add Slab importer backed by the Markdown import pipeline

Slab exports a zip of Markdown documents that is structurally identical to
the Outline Markdown export, with one difference: images are referenced as
remote signed URLs rather than files inside the archive.

Rather than build a parallel importer, this reuses the Markdown task and
processor and teaches the shared import pipeline to download remote images:

- Enable per-page attachment upload for the Markdown task. The base
  APIImportTask already downloads remote image/video/attachment URLs and
  rewrites them to internal redirect URLs; the Markdown task previously
  opted out because its attachments live in the zip.
- Make the base upload step skip URLs that are already internal, so local
  zip attachments (resolved to redirect URLs during rewriteMarkdown and
  uploaded from the archive in onAllTasksCompleted) pass through untouched
  while remote URLs are fetched and re-hosted. Also guards the URL rewrite
  against nodes not present in the download map.
- Introduce IntegrationService.Slab as a distinct, importable service that
  routes through the Markdown task/processor, so imports are tracked and
  labelled as "Slab" with no duplicated import logic.
- Wire the create API (schema + route), the import settings UI (Slab card
  and dialog), and a placeholder logo asset.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AC5Ho2SHBjNpxEAMr5uL6o
This commit is contained in:
Claude committed 2026-06-29 15:55:42 +00:00
1 parent 4dad8a59bd
commit ce587064e7
12 files changed
+134 -21

No files matched your search

+21
View File
@@ -23,6 +23,7 @@ import FileOperationListItem from "./components/FileOperationListItem";
import ImportJSONDialog from "./components/ImportJSONDialog";
import { ImportListItem } from "./components/ImportListItem";
import ImportMarkdownDialog from "./components/ImportMarkdownDialog";
import ImportSlabDialog from "./components/ImportSlabDialog";
type Config = {
/** The title of the import. */
@@ -89,6 +90,26 @@ function useImportsConfig() {
},
];
items.push({
title: "Slab",
subtitle: t("Import a zip file of Markdown documents exported from Slab"),
icon: <img src={cdnPath("/images/slab.png")} alt="" width={28} />,
action: (
<Button
type="submit"
onClick={() => {
dialogs.openModal({
title: t("Import data"),
content: <ImportSlabDialog />,
});
}}
neutral
>
{t("Import")}…
</Button>
),
});
PluginManager.getHooks(Hook.Imports).forEach((plugin) => {
items.push({ ...plugin.value });
});
@@ -71,6 +71,14 @@ function DropToImport({ disabled, onSubmit, children, format }: Props) {
permission: permission ?? undefined,
}
);
} else if (format === IntegrationService.Slab) {
await imports.create(
{ service: IntegrationService.Slab },
{
attachmentId: attachment.id,
permission: permission ?? undefined,
}
);
} else if (format === FileOperationFormat.JSON) {
await imports.create(
{ service: IntegrationService.JSON },
@@ -0,0 +1,32 @@
import { Trans } from "react-i18next";
import { IntegrationService } from "@shared/types";
import Text from "@shared/components/Text";
import useStores from "~/hooks/useStores";
import DropToImport from "./DropToImport";
function ImportSlabDialog() {
const { dialogs } = useStores();
return (
<>
<Text as="p">
<Trans>
Import a zip file of Markdown documents exported from Slab –
collections, posts, and images will be imported. In Slab, open the
admin settings and use the <em>Export</em> option to download an
archive of your content.
</Trans>
</Text>
<DropToImport
onSubmit={dialogs.closeAllModals}
format={IntegrationService.Slab}
>
<Trans>
Drag and drop the zip file exported from Slab, or click to upload
</Trans>
</DropToImport>
</>
);
}
export default ImportSlabDialog;
Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

@@ -5,11 +5,14 @@ import type { Import, ImportTask } from "@server/models";
import MarkdownAPIImportTask from "../tasks/MarkdownAPIImportTask";
import ImportsProcessor from "./ImportsProcessor";
export default class MarkdownImportsProcessor extends ImportsProcessor<IntegrationService.Markdown> {
protected canProcess(
importModel: Import<IntegrationService.Markdown>
): boolean {
return importModel.service === IntegrationService.Markdown;
type Markdown = IntegrationService.Markdown | IntegrationService.Slab;
export default class MarkdownImportsProcessor extends ImportsProcessor<Markdown> {
protected canProcess(importModel: Import<Markdown>): boolean {
return (
importModel.service === IntegrationService.Markdown ||
importModel.service === IntegrationService.Slab
);
}
protected getInitialPhase(): ImportTaskPhase {
@@ -17,9 +20,9 @@ export default class MarkdownImportsProcessor extends ImportsProcessor<Integrati
}
protected async buildTasksInput(
importModel: Import<IntegrationService.Markdown>,
importModel: Import<Markdown>,
_transaction: Transaction
): Promise<ImportTaskInput<IntegrationService.Markdown>> {
): Promise<ImportTaskInput<Markdown>> {
if (!importModel.scratch?.storageKey) {
throw new Error(
"Markdown import is missing scratch.storageKey for the bootstrap phase"
@@ -30,7 +33,7 @@ export default class MarkdownImportsProcessor extends ImportsProcessor<Integrati
}
protected async scheduleTask(
importTask: ImportTask<IntegrationService.Markdown>
importTask: ImportTask<Markdown>
): Promise<void> {
await new MarkdownAPIImportTask().schedule({ importTaskId: importTask.id });
}
+20 -3
View File
@@ -21,6 +21,7 @@ import {
ImportTaskState,
} from "@shared/types";
import { toError } from "@shared/utils/error";
import { isExternalUrl } from "@shared/utils/urls";
import { createContext } from "@server/context";
import { schema } from "@server/editor";
import Logger from "@server/logging/Logger";
@@ -365,7 +366,14 @@ export default abstract class APIImportTask<
return { url, name: name.length !== 0 ? name : node.type.name };
}),
"url"
);
).filter((item) => isExternalUrl(item.url));
// Nothing remote to download — content already points at internal
// attachments (e.g. a Markdown zip's local files resolved to redirect
// URLs), so leave the doc untouched.
if (!attachmentsData.length) {
return doc;
}
await sequelize.transaction(async (transaction) => {
const dbPromises = attachmentsData.map(async (item) => {
@@ -436,14 +444,23 @@ export default abstract class APIImportTask<
const attrs = json.attrs ?? {};
if (node.type.name === "attachment") {
const attachmentModel = urlToAttachment[attrs.href as string];
// attachment node uses 'href' attribute.
const attachmentModel = urlToAttachment[attrs.href as string];
// Nodes already pointing at internal attachments aren't in the map;
// leave them untouched.
if (!attachmentModel) {
return node;
}
attrs.href = attachmentModel.redirectUrl;
// attachment node can have id.
attrs.id = attachmentModel.id;
} else if (node.type.name === "image" || node.type.name === "video") {
// image & video nodes use 'src' attribute.
attrs.src = urlToAttachment[attrs.src as string].redirectUrl;
const attachmentModel = urlToAttachment[attrs.src as string];
if (!attachmentModel) {
return node;
}
attrs.src = attachmentModel.redirectUrl;
}
json.attrs = attrs;
@@ -66,6 +66,18 @@ describe("rewriteAttachmentPaths", () => {
]);
expect(out).toBe("![x](https://example.com/a.png)");
});
it("leaves remote signed URLs untouched so the base task can download them", () => {
// Slab exports reference images as remote signed URLs rather than files
// in the zip; these aren't in the manifest and must survive rewriting so
// the per-page attachment upload step can fetch and re-host them.
const signedUrl =
"https://uploads.slab.com/posts/abc/image.png?Signature=xyz&Expires=123";
const out = rewriteAttachmentPaths(`![x](${signedUrl})`, [
{ id: "id-a", pathInZip: "C/attachments/local.png" },
]);
expect(out).toBe(`![x](${signedUrl})`);
});
});
describe("rewriteInternalLinks", () => {
+12 -2
View File
@@ -30,7 +30,11 @@ import type { ProcessOutput } from "./APIImportTask";
import APIImportTask from "./APIImportTask";
import { DocumentConverter } from "@server/utils/DocumentConverter";
type Markdown = IntegrationService.Markdown;
// The Markdown task backs both the Outline Markdown zip importer and the
// Slab importer — they share an identical zip-of-markdown shape, differing
// only in that Slab references images as remote signed URLs (downloaded via
// the base class's per-page attachment upload) rather than local files.
type Markdown = IntegrationService.Markdown | IntegrationService.Slab;
interface DiscoveredDocument {
id: string;
@@ -153,7 +157,13 @@ export function rewriteInternalLinks(
export default class MarkdownAPIImportTask extends APIImportTask<Markdown> {
protected shouldUploadAttachmentsPerPage(): boolean {
return false;
// Per-page upload downloads remote image/attachment URLs referenced in
// the markdown (e.g. Slab's signed export URLs) and rewrites them to
// internal redirect URLs. The base step skips URLs that are already
// internal, so local zip attachments — rewritten to redirect URLs during
// `rewriteMarkdown` and uploaded from the archive in
// `onAllTasksCompleted` — pass through untouched.
return true;
}
protected async scheduleNextTask(importTask: ImportTask<Markdown>) {
+1
View File
@@ -34,6 +34,7 @@ router.post(
if (
body.service === IntegrationService.Markdown ||
body.service === IntegrationService.Slab ||
body.service === IntegrationService.JSON
) {
const attachment = await Attachment.findByPk(body.attachmentId, {
+5
View File
@@ -43,6 +43,11 @@ export const ImportsCreateSchema = BaseSchema.extend({
attachmentId: z.uuid(),
permission: z.enum(CollectionPermission).optional(),
}),
z.object({
service: z.literal(IntegrationService.Slab),
attachmentId: z.uuid(),
permission: z.enum(CollectionPermission).optional(),
}),
z.object({
service: z.literal(IntegrationService.JSON),
attachmentId: z.uuid(),
+9 -8
View File
@@ -41,7 +41,7 @@ export type JSONImportInput = z.infer<typeof JSONImportInputItemSchema>[];
export type ImportInput<T extends ImportableIntegrationService> =
T extends IntegrationService.Notion
? NotionImportInput
: T extends IntegrationService.Markdown
: T extends IntegrationService.Markdown | IntegrationService.Slab
? MarkdownImportInput
: T extends IntegrationService.JSON
? JSONImportInput
@@ -130,12 +130,13 @@ export interface JSONImportScratch {
* isn't part of any single task's input. Cleared when the import flips to
* `Processed`.
*/
export type ImportScratch<T extends ImportableIntegrationService> =
T extends IntegrationService.Markdown
? MarkdownImportScratch
: T extends IntegrationService.JSON
? JSONImportScratch
: never;
export type ImportScratch<T extends ImportableIntegrationService> = T extends
| IntegrationService.Markdown
| IntegrationService.Slab
? MarkdownImportScratch
: T extends IntegrationService.JSON
? JSONImportScratch
: never;
/**
* Per-page task input. Generated by the bootstrap task and consumed by
@@ -213,7 +214,7 @@ export type JSONImportTaskInput = (
export type ImportTaskInput<T extends ImportableIntegrationService> =
T extends IntegrationService.Notion
? NotionImportTaskInput
: T extends IntegrationService.Markdown
: T extends IntegrationService.Markdown | IntegrationService.Slab
? MarkdownImportTaskInput
: T extends IntegrationService.JSON
? JSONImportTaskInput
+3
View File
@@ -168,6 +168,7 @@ export enum IntegrationService {
Figma = "figma",
Notion = "notion",
Markdown = "markdown",
Slab = "slab",
JSON = "json",
}
@@ -175,12 +176,14 @@ export type ImportableIntegrationService = Extract<
IntegrationService,
| IntegrationService.Notion
| IntegrationService.Markdown
| IntegrationService.Slab
| IntegrationService.JSON
>;
export const ImportableIntegrationService = {
Notion: IntegrationService.Notion,
Markdown: IntegrationService.Markdown,
Slab: IntegrationService.Slab,
JSON: IntegrationService.JSON,
} as const;