Skip to content

Commit

Permalink
issue/estruyf#504
Browse files Browse the repository at this point in the history
  • Loading branch information
furkanb committed Feb 10, 2023
1 parent 4f91aeb commit 04960b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,11 @@
"type": "string",
"default": "",
"description": "An optional post script that can be used after new content creation."
},
"defaultFileName": {
"type": "string",
"default": "index",
"description": "Default file name to use when creating new content."
}
},
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ArticleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export class ArticleHelper {
return;
} else {
await mkdirAsync(newFolder);
newFilePath = join(newFolder, `index.${fileExtension || contentType.fileType || fileType}`);
newFilePath = join(newFolder, `${contentType.defaultFileName ?? `index`}.${fileExtension || contentType.fileType || fileType}`);
}
} else {
let newFileName = `${sanitizedName}.${fileExtension || contentType?.fileType || fileType}`;
Expand Down
1 change: 1 addition & 0 deletions src/models/PanelSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ContentType {
fileType?: "md" | "mdx" | string;
previewPath?: string | null;
pageBundle?: boolean;
defaultFileName?: string;
template?: string;
postScript?: string;
}
Expand Down
10 changes: 9 additions & 1 deletion src/panelWebView/components/FileItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ const FileItem: React.FunctionComponent<IFileItemProps> = ({ name, folderName, p
Messenger.send(CommandToCode.openInEditor, path);
};

/*
File names which would not give any info about the content.
by themselves, e.g.: index | +page | etc…
Ideally we should have access to the `defaultFileName`
property of the contentType here to check.
*/
const vagueFileNamesList = ['index', '+page']

const itemName = useMemo(() => {
if (folderName && name.includes("index.")) {
if (folderName && vagueFileNamesList.some(vagueFileName => name.includes(vagueFileName + '.'))) {
return folderName;
}

Expand Down

0 comments on commit 04960b7

Please sign in to comment.