mirror of
https://github.com/outline/outline.git
synced 2026-11-30 00:50:41 +03:00
Slab exports wrap the entire workspace in a single top-level directory named "slab". Without handling this, the import produces one "slab" collection containing everything, instead of mapping each workspace area to its own collection. Add a `resolveCollectionRootNodes` seam on the Markdown bootstrap phase (default: pass entries through unchanged) and override it in SlabAPIImportTask to descend into a lone, case-insensitive "slab" root directory so its child directories become collections. Paths are left intact, so the attachment manifest, completion re-walk, and internal-link resolution stay consistent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AC5Ho2SHBjNpxEAMr5uL6o
73 lines
1.9 KiB
TypeScript
73 lines
1.9 KiB
TypeScript
import type { ZipTreeNode } from "@server/utils/ZipHelper";
|
|
import SlabAPIImportTask from "./SlabAPIImportTask";
|
|
|
|
class TestSlabAPIImportTask extends SlabAPIImportTask {
|
|
public resolve(nodes: ZipTreeNode[]): ZipTreeNode[] {
|
|
return this.resolveCollectionRootNodes(nodes);
|
|
}
|
|
}
|
|
|
|
const dir = (
|
|
title: string,
|
|
children: ZipTreeNode[] = [],
|
|
pathInZip = title
|
|
): ZipTreeNode => ({
|
|
name: title,
|
|
title,
|
|
pathInZip,
|
|
children,
|
|
});
|
|
|
|
const file = (name: string, pathInZip = name): ZipTreeNode => ({
|
|
name,
|
|
title: name.replace(/\.[^.]+$/, ""),
|
|
pathInZip,
|
|
children: [],
|
|
});
|
|
|
|
describe("SlabAPIImportTask#resolveCollectionRootNodes", () => {
|
|
const task = new TestSlabAPIImportTask();
|
|
|
|
it("unwraps a single root 'slab' directory into its children", () => {
|
|
const eng = dir(
|
|
"Engineering",
|
|
[file("doc.md", "slab/Engineering/doc.md")],
|
|
"slab/Engineering"
|
|
);
|
|
const product = dir(
|
|
"Product",
|
|
[file("spec.md", "slab/Product/spec.md")],
|
|
"slab/Product"
|
|
);
|
|
const root = dir("slab", [eng, product], "slab");
|
|
|
|
expect(task.resolve([root])).toEqual([eng, product]);
|
|
});
|
|
|
|
it("is case-insensitive on the wrapper directory name", () => {
|
|
const child = dir("Team", [file("a.md", "Slab/Team/a.md")], "Slab/Team");
|
|
const root = dir("Slab", [child], "Slab");
|
|
|
|
expect(task.resolve([root])).toEqual([child]);
|
|
});
|
|
|
|
it("leaves multiple root directories untouched", () => {
|
|
const a = dir("Engineering", [file("a.md", "Engineering/a.md")]);
|
|
const b = dir("slab", [file("b.md", "slab/b.md")]);
|
|
|
|
expect(task.resolve([a, b])).toEqual([a, b]);
|
|
});
|
|
|
|
it("leaves a single non-'slab' root directory untouched", () => {
|
|
const a = dir("Engineering", [file("doc.md", "Engineering/doc.md")]);
|
|
|
|
expect(task.resolve([a])).toEqual([a]);
|
|
});
|
|
|
|
it("does not unwrap an empty 'slab' directory", () => {
|
|
const root = dir("slab", []);
|
|
|
|
expect(task.resolve([root])).toEqual([root]);
|
|
});
|
|
});
|