#360 - Define which content types can be used on your page folders

This commit is contained in:
Elio Struyf
2022-11-09 13:59:14 +01:00
parent f1a8e0d425
commit e3bd7eebbe
6 changed files with 31 additions and 12 deletions
+1
View File
@@ -8,6 +8,7 @@
### 🎨 Enhancements
- [#360](https://github.com/estruyf/vscode-front-matter/issues/360): Define which content types can be used on your page folders
- [#406](https://github.com/estruyf/vscode-front-matter/issues/406): Added support for single data entries in the data dashboard
- [#428](https://github.com/estruyf/vscode-front-matter/issues/428): Improved UX for inserting images to your content
- [#430](https://github.com/estruyf/vscode-front-matter/issues/430): Support for HEXO its `post_asset_folder` setting (image location)
+7
View File
@@ -210,6 +210,13 @@
"filePrefix": {
"type": [ "null", "string" ],
"description": "Defines a prefix for the file name."
},
"contentTypes": {
"type": "array",
"description": "Defines which content types can be used for the current location. If not defined, all content types will be available.",
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
+1 -1
View File
@@ -81,7 +81,7 @@ export class Folders {
* Create content in a registered folder
* @returns
*/
public static async create() {
public static async create() {
const selectedFolder = await Questions.SelectContentFolder();
if (!selectedFolder) {
return;
+12 -8
View File
@@ -64,11 +64,6 @@ export class ContentType {
* @returns
*/
public static async createContent() {
const selectedContentType = await Questions.SelectContentType();
if (!selectedContentType) {
return;
}
const selectedFolder = await Questions.SelectContentFolder();
if (!selectedFolder) {
return;
@@ -76,10 +71,19 @@ export class ContentType {
const contentTypes = ContentType.getAll();
const folders = Folders.get();
const folder = folders.find(f => f.title === selectedFolder);
const location = folders.find(f => f.title === selectedFolder);
if (contentTypes && location) {
const folderPath = Folders.getFolderPath(Uri.file(location.path));
if (!folder) {
return;
}
const selectedContentType = await Questions.SelectContentType(folder.contentTypes || []);
if (!selectedContentType) {
return;
}
if (contentTypes && folder) {
const folderPath = Folders.getFolderPath(Uri.file(folder.path));
const contentType = contentTypes.find(ct => ct.name === selectedContentType);
if (folderPath && contentType) {
ContentType.create(contentType, folderPath);
+9 -3
View File
@@ -46,7 +46,7 @@ export class Questions {
* @returns
*/
public static async SelectContentFolder(showWarning: boolean = true): Promise<string | undefined> {
const folders = Folders.get();
let folders = Folders.get();
let selectedFolder: string | undefined;
if (folders.length > 1) {
@@ -72,16 +72,22 @@ export class Questions {
/**
* Select the content type to create new content
* @param allowedCts Allowed content types for the folder
* @param showWarning
* @returns
*/
public static async SelectContentType(showWarning: boolean = true): Promise<string | undefined> {
const contentTypes = ContentType.getAll();
public static async SelectContentType(allowedCts: string[], showWarning: boolean = true): Promise<string | undefined> {
let contentTypes = ContentType.getAll();
if (!contentTypes || contentTypes.length === 0) {
Notifications.warning("No content types found. Please create a content type first.");
return;
}
// Only allow content types that are allowed for the folder
if (allowedCts && allowedCts.length > 0) {
contentTypes = contentTypes.filter(ct => allowedCts.find(allowedCt => allowedCt === ct.name));
}
if (contentTypes.length === 1) {
return contentTypes[0].name;
}
+1
View File
@@ -5,4 +5,5 @@ export interface ContentFolder {
excludeSubdir?: boolean;
previewPath?: string;
filePrefix?: string;
contentTypes?: string[];
}