mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-06-25 20:41:40 +02:00
#360 - Define which content types can be used on your page folders
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ export interface ContentFolder {
|
||||
excludeSubdir?: boolean;
|
||||
previewPath?: string;
|
||||
filePrefix?: string;
|
||||
contentTypes?: string[];
|
||||
}
|
||||
Reference in New Issue
Block a user