mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-06 08:52:47 +02:00
#777 - Extra states for invalid files
This commit is contained in:
@@ -741,15 +741,17 @@ export class ArticleHelper {
|
||||
* Get the details of the current article
|
||||
* @returns
|
||||
*/
|
||||
public static async getDetails(filePath: string) {
|
||||
public static async getDetails(
|
||||
filePath: string
|
||||
): Promise<Article | 'nofilepath' | 'nodata' | 'notsupported'> {
|
||||
const baseUrl = Settings.get<string>(SETTING_SITE_BASEURL);
|
||||
if (!filePath) {
|
||||
return null;
|
||||
return 'nofilepath';
|
||||
}
|
||||
|
||||
const document = await workspace.openTextDocument(filePath);
|
||||
if (!ArticleHelper.isSupportedFile(document)) {
|
||||
return null;
|
||||
return 'notsupported';
|
||||
}
|
||||
|
||||
const article = await ArticleHelper.getFrontMatterByPath(filePath);
|
||||
@@ -805,7 +807,7 @@ export class ArticleHelper {
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
return 'nodata';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -199,7 +199,7 @@ export class DataListener extends BaseListener {
|
||||
if (filePath) {
|
||||
articleDetails = await ArticleHelper.getDetails(filePath);
|
||||
|
||||
if (!articleDetails) {
|
||||
if (!articleDetails || articleDetails === 'nodata') {
|
||||
try {
|
||||
const contents = await ArticleHelper.getContents(filePath);
|
||||
if (contents) {
|
||||
@@ -214,6 +214,10 @@ export class DataListener extends BaseListener {
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else if (articleDetails === 'notsupported' || articleDetails === 'nofilepath') {
|
||||
// No file or invalid file format
|
||||
this.sendMsg(Command.metadata, undefined);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.sendMsg(Command.metadata, undefined);
|
||||
|
||||
Reference in New Issue
Block a user