diff --git a/package.json b/package.json index 6976fec6..aa3d130b 100644 --- a/package.json +++ b/package.json @@ -314,6 +314,11 @@ "name" ] } + }, + "pageBundle": { + "type": "boolean", + "default": false, + "description": "Specify if you want to create a folder when creating new content." } }, "additionalProperties": false, diff --git a/src/helpers/ContentType.ts b/src/helpers/ContentType.ts index 11924f68..0ffabedf 100644 --- a/src/helpers/ContentType.ts +++ b/src/helpers/ContentType.ts @@ -7,7 +7,7 @@ import { Questions } from "./Questions"; import sanitize from '../helpers/Sanitize'; import { format } from "date-fns"; import { join } from "path"; -import { existsSync, writeFileSync } from "fs"; +import { existsSync, mkdirSync, writeFileSync } from "fs"; import { Notifications } from "./Notifications"; import { DEFAULT_CONTENT_TYPE_NAME } from "../constants/ContentType"; @@ -58,16 +58,35 @@ export class ContentType { return; } + // Name of the file or folder to create const sanitizedName = sanitize(titleValue.toLowerCase().replace(/ /g, "-")); - let newFileName = `${sanitizedName}.md`; + let newFilePath: string | undefined; - if (prefix && typeof prefix === "string") { - newFileName = `${format(new Date(), prefix)}-${newFileName}`; + // Create a folder with the `index.md` file + if (contentType.pageBundle) { + const newFolder = join(folderPath, sanitizedName); + if (existsSync(newFolder)) { + Notifications.error(`A page bundle with the name ${sanitizedName} already exists in ${folderPath}`); + return; + } else { + mkdirSync(newFolder); + newFilePath = join(newFolder, `index.md`); + } + } else { + let newFileName = `${sanitizedName}.md`; + + if (prefix && typeof prefix === "string") { + newFileName = `${format(new Date(), prefix)}-${newFileName}`; + } + + newFilePath = join(folderPath, newFileName); + if (existsSync(newFilePath)) { + Notifications.warning(`Content with the title already exists. Please specify a new title.`); + return; + } } - const newFilePath = join(folderPath, newFileName); - if (existsSync(newFilePath)) { - Notifications.warning(`Content with the title already exists. Please specify a new title.`); + if (!newFilePath) { return; } diff --git a/src/models/PanelSettings.ts b/src/models/PanelSettings.ts index 5f5b1b4d..d1b5513d 100644 --- a/src/models/PanelSettings.ts +++ b/src/models/PanelSettings.ts @@ -22,6 +22,8 @@ export interface PanelSettings { export interface ContentType { name: string; fields: Field[]; + + pageBundle?: boolean; } export interface Field {