Skip to content

Commit

Permalink
#458 - Add prefix to page bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Nov 14, 2022
1 parent 0ea06a8 commit 59cbc03
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/helpers/ArticleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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);
Expand Down

0 comments on commit 59cbc03

Please sign in to comment.