mirror of
https://github.com/estruyf/vscode-front-matter.git
synced 2026-08-08 09:53:20 +02:00
#412 - Support for sub-folders
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vscode-front-matter-beta",
|
||||
"displayName": "Front Matter CMS",
|
||||
"description": "Front Matter is a CMS that runs within Visual Studio Code. It gives you the power and control of a full-blown CMS while also providing you the flexibility and speed of the static site generator of your choice like: Hugo, Jekyll, Hexo, NextJs, Gatsby, and many more...",
|
||||
"description": "Front Matter is a CMS that runs within Visual Studio Code. It gives you the power and control of a full-blown CMS while also providing you the flexibility and speed of the static site generator of your choice like: Hugo, Jekyll, Docusaurus, NextJs, Gatsby, and many more...",
|
||||
"icon": "assets/frontmatter-teal-128x128.png",
|
||||
"version": "8.2.0",
|
||||
"preview": false,
|
||||
|
||||
+4
-17
@@ -1,32 +1,19 @@
|
||||
import { GitListener } from './listeners/general/GitListener';
|
||||
import * as vscode from 'vscode';
|
||||
import { Telemetry } from './helpers/Telemetry';
|
||||
import { ContentType } from './helpers/ContentType';
|
||||
import { Dashboard } from './commands/Dashboard';
|
||||
import { Article, Settings, StatusListener } from './commands';
|
||||
import { Folders } from './commands/Folders';
|
||||
import { Preview } from './commands/Preview';
|
||||
import { Project } from './commands/Project';
|
||||
import { Template } from './commands/Template';
|
||||
import { Cache } from './commands/Cache';
|
||||
import { COMMAND_NAME, TelemetryEvent } from './constants';
|
||||
import { TaxonomyType } from './models';
|
||||
import { MarkdownFoldingProvider } from './providers/MarkdownFoldingProvider';
|
||||
import { TagType } from './panelWebView/TagType';
|
||||
import { ExplorerView } from './explorerView/ExplorerView';
|
||||
import { Extension } from './helpers/Extension';
|
||||
import { DashboardData } from './models/DashboardData';
|
||||
import { DashboardSettings, debounceCallback, Logger, Settings as SettingsHelper } from './helpers';
|
||||
import { Content } from './commands/Content';
|
||||
import ContentProvider from './providers/ContentProvider';
|
||||
import { Wysiwyg } from './commands/Wysiwyg';
|
||||
import { Diagnostics } from './commands/Diagnostics';
|
||||
import { PagesListener } from './listeners/dashboard';
|
||||
import { Backers } from './commands/Backers';
|
||||
import { DataListener, SettingsListener } from './listeners/panel';
|
||||
import { NavigationType } from './dashboardWebView/models';
|
||||
import { ModeSwitch } from './services/ModeSwitch';
|
||||
import { PagesParser } from './services/PagesParser';
|
||||
import { ContentType, Telemetry, Extension } from './helpers';
|
||||
import { TaxonomyType, DashboardData } from './models';
|
||||
import { Backers, Diagnostics, Wysiwyg, Content, Cache, Template, Project, Preview, Folders, Dashboard, Article, Settings, StatusListener } from './commands';
|
||||
|
||||
let frontMatterStatusBar: vscode.StatusBarItem;
|
||||
let statusDebouncer: { (fnc: any, time: number): void; };
|
||||
@@ -37,7 +24,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||
const { subscriptions, extensionUri, extensionPath } = context;
|
||||
|
||||
const extension = Extension.getInstance(context);
|
||||
Backers.init(context);
|
||||
Backers.init(context).then(() => {});
|
||||
|
||||
if (!extension.checkIfExtensionCanRun()) {
|
||||
return undefined;
|
||||
|
||||
@@ -480,8 +480,7 @@ export class Settings {
|
||||
}
|
||||
|
||||
// Array settings
|
||||
if (relSettingName === SETTING_CUSTOM_SCRIPTS.toLowerCase()) {
|
||||
|
||||
if (Settings.isEqualOrStartsWith(relSettingName, SETTING_CUSTOM_SCRIPTS)) {
|
||||
// Get the correct setting name
|
||||
let settingNameValue = ""
|
||||
if (relSettingName === SETTING_CUSTOM_SCRIPTS.toLowerCase()) {
|
||||
@@ -492,35 +491,32 @@ export class Settings {
|
||||
Settings.globalConfig[`${CONFIG_KEY}.${settingNameValue}`] = [...crntValue, configJson];
|
||||
}
|
||||
// Content types
|
||||
else if (relSettingName === SETTING_TAXONOMY_CONTENT_TYPES.toLowerCase()) {
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_TAXONOMY_CONTENT_TYPES)) {
|
||||
Settings.updateGlobalConfigArraySetting(SETTING_TAXONOMY_CONTENT_TYPES, "name", configJson);
|
||||
}
|
||||
// Data files
|
||||
else if (relSettingName === SETTING_DATA_FILES.toLowerCase()) {
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_DATA_FILES)) {
|
||||
Settings.updateGlobalConfigArraySetting(SETTING_DATA_FILES, "id", configJson);
|
||||
}
|
||||
// Data folders
|
||||
else if (relSettingName === SETTING_DATA_FOLDERS.toLowerCase()) {
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_DATA_FOLDERS)) {
|
||||
Settings.updateGlobalConfigArraySetting(SETTING_DATA_FOLDERS, "id", configJson);
|
||||
}
|
||||
// Data types
|
||||
else if (relSettingName === SETTING_DATA_TYPES.toLowerCase()) {
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_DATA_TYPES)) {
|
||||
Settings.updateGlobalConfigArraySetting(SETTING_DATA_TYPES, "id", configJson);
|
||||
}
|
||||
// Page folders
|
||||
else if (relSettingName === SETTING_CONTENT_PAGE_FOLDERS.toLowerCase()) {
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_CONTENT_PAGE_FOLDERS)) {
|
||||
Settings.updateGlobalConfigArraySetting(SETTING_CONTENT_PAGE_FOLDERS, "path", configJson);
|
||||
}
|
||||
// Placeholders
|
||||
else if (relSettingName === SETTING_CONTENT_PLACEHOLDERS.toLowerCase()) {
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_CONTENT_PLACEHOLDERS)) {
|
||||
Settings.updateGlobalConfigArraySetting(SETTING_CONTENT_PLACEHOLDERS, "id", configJson);
|
||||
}
|
||||
// Object settings
|
||||
else if (relSettingName === SETTING_CONTENT_SNIPPETS.toLowerCase()) {
|
||||
// Filename is the key
|
||||
const fileName = parse(configFilePath).name;
|
||||
const crntValue = Settings.globalConfig[`${CONFIG_KEY}.${SETTING_CONTENT_SNIPPETS}`] || {};
|
||||
Settings.globalConfig[`${CONFIG_KEY}.${SETTING_CONTENT_SNIPPETS}`] = { ...crntValue, ...{ [fileName]: configJson } };
|
||||
else if (Settings.isEqualOrStartsWith(relSettingName, SETTING_CONTENT_SNIPPETS)) {
|
||||
Settings.updateGlobalConfigObjectByNameSetting(SETTING_CONTENT_SNIPPETS, configFilePath, configJson);
|
||||
}
|
||||
} catch (e) {
|
||||
Logger.error(`Error reading config file: ${configFile.fsPath}`);
|
||||
@@ -528,6 +524,19 @@ export class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the setting name is equal or starts with the reference setting name
|
||||
* @param value
|
||||
* @param startsWith
|
||||
* @returns
|
||||
*/
|
||||
private static isEqualOrStartsWith(value: string, startsWith: string) {
|
||||
value = value.toLowerCase();
|
||||
startsWith = startsWith.toLowerCase();
|
||||
|
||||
return value === startsWith || value.startsWith(`${startsWith}.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an array setting in the global config
|
||||
* @param settingName
|
||||
@@ -539,15 +548,32 @@ export class Settings {
|
||||
|
||||
// Check if folder is already added
|
||||
const itemIdx = crntValue.findIndex((item: any) => item[fieldName] === configJson[fieldName]);
|
||||
if (itemIdx !== -1) {
|
||||
crntValue[itemIdx] = configJson;
|
||||
} else {
|
||||
if (itemIdx === -1) {
|
||||
crntValue.push(configJson);
|
||||
}
|
||||
|
||||
Settings.globalConfig[`${CONFIG_KEY}.${settingName}`] = [...crntValue];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an object by the file name in the global config
|
||||
* @param settingName
|
||||
* @param fileNamepath
|
||||
* @param configJson
|
||||
*/
|
||||
private static updateGlobalConfigObjectByNameSetting<T>(settingName: string, fileNamepath: string, configJson: any): void {
|
||||
const crntValue = Settings.globalConfig[`${CONFIG_KEY}.${settingName}`] || {};
|
||||
|
||||
// Filename is the key
|
||||
const fileName = parse(fileNamepath).name;
|
||||
|
||||
if (!crntValue[fileName]) {
|
||||
crntValue[fileName] = configJson;
|
||||
|
||||
Settings.globalConfig[`${CONFIG_KEY}.${settingName}`] = { ...crntValue, ...{ [fileName]: configJson } };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a file creation watcher
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user