diff --git a/package.json b/package.json index 251d1666..2934f369 100644 --- a/package.json +++ b/package.json @@ -1276,6 +1276,12 @@ "default": "yyyy-MM-dd", "markdownDescription": "Specify the prefix you want to add for your new article filenames. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.templates.prefix)", "scope": "Templates" + }, + "frontMatter.templates.enabled": { + "type": "boolean", + "default": false, + "markdownDescription": "Specify if you want to use templates. [Check in the docs](https://frontmatter.codes/docs/settings#frontmatter.templates.enabled)", + "scope": "Templates" } } }, diff --git a/src/commands/Content.ts b/src/commands/Content.ts index b0f84751..0c3f0159 100644 --- a/src/commands/Content.ts +++ b/src/commands/Content.ts @@ -1,9 +1,14 @@ import { commands, QuickPickItem, window } from 'vscode'; -import { COMMAND_NAME } from '../constants'; +import { COMMAND_NAME, SETTING_TEMPLATES_ENABLED } from '../constants'; +import { Settings } from '../helpers'; export class Content { public static async create() { + const templatesEnabled = await Settings.get(SETTING_TEMPLATES_ENABLED); + if (!templatesEnabled) { + commands.executeCommand(COMMAND_NAME.createByContentType); + } const options: QuickPickItem[] = [{ label: "Create content by content type", diff --git a/src/commands/Template.ts b/src/commands/Template.ts index ab95ab79..8c138964 100644 --- a/src/commands/Template.ts +++ b/src/commands/Template.ts @@ -100,11 +100,24 @@ export class Template { } } + /** + * Retrieve all templates + */ + public static async getTemplates() { + const folder = Settings.get(SETTING_TEMPLATES_FOLDER); + + if (!folder) { + Notifications.warning(`No templates found.`); + return; + } + + return await vscode.workspace.findFiles(`${folder}/**/*`, "**/node_modules/**,**/archetypes/**"); + } + /** * Create from a template */ public static async create(folderPath: string) { - const folder = Settings.get(SETTING_TEMPLATES_FOLDER); const contentTypes = ContentType.getAll(); if (!folderPath) { @@ -112,12 +125,7 @@ export class Template { return; } - if (!folder) { - Notifications.warning(`No templates found.`); - return; - } - - const templates = await vscode.workspace.findFiles(`${folder}/**/*`, "**/node_modules/**,**/archetypes/**"); + const templates = await Template.getTemplates(); if (!templates || templates.length === 0) { Notifications.warning(`No templates found.`); return; diff --git a/src/constants/settings.ts b/src/constants/settings.ts index a318c981..82951cef 100644 --- a/src/constants/settings.ts +++ b/src/constants/settings.ts @@ -32,6 +32,7 @@ export const SETTING_SEO_DESCRIPTION_FIELD = "taxonomy.seoDescriptionField"; export const SETTING_TEMPLATES_FOLDER = "templates.folder"; export const SETTING_TEMPLATES_PREFIX = "templates.prefix"; +export const SETTING_TEMPLATES_ENABLED = "templates.enabled"; export const SETTING_TELEMETRY_DISABLE = "telemetry.disable"; diff --git a/src/helpers/Extension.ts b/src/helpers/Extension.ts index 61f7160e..7473734c 100644 --- a/src/helpers/Extension.ts +++ b/src/helpers/Extension.ts @@ -1,7 +1,8 @@ import { basename } from "path"; import { extensions, Uri, ExtensionContext, window, workspace, commands, ExtensionMode, DiagnosticCollection, languages } from "vscode"; import { Folders } from "../commands/Folders"; -import { EXTENSION_NAME, GITHUB_LINK, SETTING_DATE_FIELD, SETTING_MODIFIED_FIELD, EXTENSION_BETA_ID, EXTENSION_ID, ExtensionState, CONFIG_KEY, SETTING_CONTENT_PAGE_FOLDERS, SETTING_DASHBOARD_MEDIA_SNIPPET, SETTING_CONTENT_SNIPPETS } from "../constants"; +import { Template } from "../commands/Template"; +import { EXTENSION_NAME, GITHUB_LINK, SETTING_DATE_FIELD, SETTING_MODIFIED_FIELD, EXTENSION_BETA_ID, EXTENSION_ID, ExtensionState, CONFIG_KEY, SETTING_CONTENT_PAGE_FOLDERS, SETTING_DASHBOARD_MEDIA_SNIPPET, SETTING_CONTENT_SNIPPETS, SETTING_TEMPLATES_ENABLED } from "../constants"; import { ContentFolder, Snippet } from "../models"; import { Notifications } from "./Notifications"; import { Settings } from "./SettingsHelper"; @@ -212,6 +213,17 @@ export class Extension { await Settings.update(SETTING_CONTENT_SNIPPETS, snippets, true); } + + const templates = await Template.getTemplates(); + if (templates && templates.length > 0) { + const answer = await window.showQuickPick(["Yes", "No"], { + title: "Front Matter - Templates", + placeHolder: "Do you want to keep on using the template functionality?", + ignoreFocusOut: true + }); + + Settings.update(SETTING_TEMPLATES_ENABLED, answer?.toLocaleLowerCase() === "yes", true); + } } }