mirror of
https://github.com/outline/outline.git
synced 2026-11-28 16:19:46 +03:00
In Slab a document's leading heading is real content, not its title — the filename is authoritative. Add an `extractTitle` option to DocumentConverter.convert (default true, preserving existing callers) that, when false, skips lifting a leading H1 into the title and leaves it in the body. Expose it through a `shouldExtractTitleFromHeading` seam on the Markdown task and override it in SlabAPIImportTask. With no extracted title, the page falls back to the filename-derived title. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AC5Ho2SHBjNpxEAMr5uL6o
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import type { IntegrationService } from "@shared/types";
|
|
import type { ImportTask } from "@server/models";
|
|
import type { ZipTreeNode } from "@server/utils/ZipHelper";
|
|
import MarkdownAPIImportTask from "./MarkdownAPIImportTask";
|
|
|
|
type Service = IntegrationService.Markdown | IntegrationService.Slab;
|
|
|
|
/**
|
|
* Imports a Slab workspace export.
|
|
*
|
|
* Slab exports the same zip-of-Markdown structure as Outline's own Markdown
|
|
* export, so all conversion, attachment, and persistence logic is inherited
|
|
* from {@link MarkdownAPIImportTask}. This subclass exists as a dedicated
|
|
* seam for Slab-specific behavior (e.g. quirks in how Slab references remote
|
|
* assets) and so Slab imports are scheduled, traced, and retried under their
|
|
* own task name rather than the generic Markdown one.
|
|
*/
|
|
export default class SlabAPIImportTask extends MarkdownAPIImportTask {
|
|
protected async scheduleNextTask(
|
|
importTask: ImportTask<Service>
|
|
): Promise<void> {
|
|
await new SlabAPIImportTask().schedule({ importTaskId: importTask.id });
|
|
}
|
|
|
|
/**
|
|
* Slab exports wrap the entire workspace in a single root directory named
|
|
* "slab". When present, descend into it so the directories one level down
|
|
* are imported as collections rather than a single "slab" collection.
|
|
*
|
|
* @param nodes The archive's top-level tree nodes.
|
|
* @returns The nodes to import as collections.
|
|
*/
|
|
protected resolveCollectionRootNodes(nodes: ZipTreeNode[]): ZipTreeNode[] {
|
|
if (
|
|
nodes.length === 1 &&
|
|
nodes[0].children.length > 0 &&
|
|
nodes[0].title.toLowerCase() === "slab"
|
|
) {
|
|
return nodes[0].children;
|
|
}
|
|
return nodes;
|
|
}
|
|
|
|
/**
|
|
* Slab does not treat a document's first heading as its title — the
|
|
* filename is authoritative. Keep the leading heading as body content.
|
|
*
|
|
* @returns false so the leading heading is preserved in the document body.
|
|
*/
|
|
protected shouldExtractTitleFromHeading(): boolean {
|
|
return false;
|
|
}
|
|
}
|