Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

984 B
Raw Blame
import {
  createId,
  type Pages,
  type Folder,
  ROOT_FOLDER_ID,
  type Instance,
  type DataSource,
} from "@webstudio-is/sdk";

export const createRootFolder = (
  children: Folder["children"] = []
): Folder => ({
  id: ROOT_FOLDER_ID,
  name: "Root",
  slug: "",
  children,
});

export const createDefaultPages = ({
  rootInstanceId,
  systemDataSourceId,
  homePageId = createId("nano"),
}: {
  rootInstanceId: Instance["id"];
  systemDataSourceId?: DataSource["id"];
  homePageId?: string;
}): Pages => {
  // This is a root folder that nobody can delete or going to be able to see.
  const rootFolder = createRootFolder([homePageId]);
  const homePage = {
    id: homePageId,
    name: "Home",
    path: "",
    title: `"Home"`,
    meta: {},
    rootInstanceId,
    systemDataSourceId,
  };
  return {
    meta: {},
    homePageId,
    rootFolderId: ROOT_FOLDER_ID,
    pages: new Map([[homePageId, homePage]]),
    folders: new Map([[rootFolder.id, rootFolder]]),
  };
};