#458 - Add prefix to page bundles

This commit is contained in:
Elio Struyf
2022-11-14 10:48:15 +01:00
parent 0ea06a841e
commit 59cbc03b0c
+10 -2
View File
@@ -338,13 +338,21 @@ export class ArticleHelper {
if (typeof filePrefixOnFolder !== "undefined") {
prefix = filePrefixOnFolder;
}
if (prefix && typeof prefix === "string") {
prefix = `${format(new Date(), DateHelper.formatUpdate(prefix) as string)}`;
}
// Name of the file or folder to create
const sanitizedName = ArticleHelper.sanitize(titleValue);
let sanitizedName = ArticleHelper.sanitize(titleValue);
let newFilePath: string | undefined;
// Create a folder with the `index.md` file
if (contentType?.pageBundle) {
if (prefix && typeof prefix === "string") {
sanitizedName = `${prefix}-${sanitizedName}`;
}
const newFolder = join(folderPath, sanitizedName);
if (await existsAsync(newFolder)) {
Notifications.error(`A page bundle with the name ${sanitizedName} already exists in ${folderPath}`);
@@ -357,7 +365,7 @@ export class ArticleHelper {
let newFileName = `${sanitizedName}.${fileExtension || contentType?.fileType || fileType}`;
if (prefix && typeof prefix === "string") {
newFileName = `${format(new Date(), DateHelper.formatUpdate(prefix) as string)}-${newFileName}`;
newFileName = `${prefix}-${newFileName}`;
}
newFilePath = join(folderPath, newFileName);