mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-11 19:32:54 +02:00
Merge branch 'furkanb-issue/#504' into dev
This commit is contained in:
@@ -1321,6 +1321,11 @@
|
||||
"string"
|
||||
],
|
||||
"description": "Defines a prefix for the file name."
|
||||
},
|
||||
"defaultFileName": {
|
||||
"type": "string",
|
||||
"default": "index",
|
||||
"description": "Default file name to use when creating new content."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false,
|
||||
|
||||
@@ -403,7 +403,12 @@ export class ArticleHelper {
|
||||
return;
|
||||
} else {
|
||||
await mkdirAsync(newFolder, { recursive: true });
|
||||
newFilePath = join(newFolder, `index.${fileExtension || contentType.fileType || fileType}`);
|
||||
newFilePath = join(
|
||||
newFolder,
|
||||
`${sanitize(contentType.defaultFileName ?? `index`)}.${
|
||||
fileExtension || contentType.fileType || fileType
|
||||
}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
let newFileName = `${sanitizedName}.${fileExtension || contentType?.fileType || fileType}`;
|
||||
|
||||
@@ -47,6 +47,7 @@ export interface ContentType {
|
||||
fileType?: 'md' | 'mdx' | string;
|
||||
previewPath?: string | null;
|
||||
pageBundle?: boolean;
|
||||
defaultFileName?: string;
|
||||
template?: string;
|
||||
postScript?: string;
|
||||
filePrefix?: string;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Messenger } from '@estruyf/vscode/dist/client';
|
||||
import * as React from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { DEFAULT_FILE_TYPES } from '../../constants/DefaultFileTypes';
|
||||
import { ContentType } from '../../helpers';
|
||||
import { CommandToCode } from '../CommandToCode';
|
||||
import { FileIcon } from './Icons/FileIcon';
|
||||
import { MarkdownIcon } from './Icons/MarkdownIcon';
|
||||
@@ -21,8 +22,14 @@ const FileItem: React.FunctionComponent<IFileItemProps> = ({
|
||||
Messenger.send(CommandToCode.openInEditor, path);
|
||||
};
|
||||
|
||||
let vagueFileNamesList = ['index', '+page'];
|
||||
const contentTypes = ContentType.getAll() || [];
|
||||
const defaultNames = contentTypes.map(contentType => contentType.defaultFileName || "index");
|
||||
vagueFileNamesList = [...vagueFileNamesList, ...defaultNames];
|
||||
vagueFileNamesList = [...new Set(vagueFileNamesList)];
|
||||
|
||||
const itemName = useMemo(() => {
|
||||
if (folderName && name.includes('index.')) {
|
||||
if (folderName && vagueFileNamesList.some(vagueFileName => name.includes(vagueFileName + '.'))) {
|
||||
return folderName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user