From c6f40194b4eb9d6b12e0ff4516607e67b1b1ebd9 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 23 Oct 2024 17:53:27 +0200 Subject: [PATCH 01/14] Refactor snippet type display logic #867 --- src/dashboardWebView/components/SnippetsView/Item.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dashboardWebView/components/SnippetsView/Item.tsx b/src/dashboardWebView/components/SnippetsView/Item.tsx index b62be87f..d54e4359 100644 --- a/src/dashboardWebView/components/SnippetsView/Item.tsx +++ b/src/dashboardWebView/components/SnippetsView/Item.tsx @@ -183,7 +183,7 @@ export const Item: React.FunctionComponent = ({
{ - snippet.isMediaSnippet ? l10n.t(LocalizationKey.dashboardSnippetsViewItemTypeContent) : l10n.t(LocalizationKey.dashboardSnippetsViewItemTypeMedia) + snippet.isMediaSnippet ? l10n.t(LocalizationKey.dashboardSnippetsViewItemTypeMedia) : l10n.t(LocalizationKey.dashboardSnippetsViewItemTypeContent) }
From cec3cbee3a51a5489addb530ad072fbdb17e3f9b Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 23 Oct 2024 17:54:43 +0200 Subject: [PATCH 02/14] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 890bfb89..8e34383a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [10.x.x] - 2024-xx-xx + +### 🐞 Fixes + +- [#876](https://github.com/estruyf/vscode-front-matter/issues/876): Fix snippet type on the snippet card + ## [10.5.1] - 2024-10-23 ### 🎨 Enhancements From 0e04e687faf77c2a46bb98139c705e18e0cd550e Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 24 Oct 2024 12:05:07 +0200 Subject: [PATCH 03/14] #878 - Enhanced select all logic --- CHANGELOG.md | 4 ++ .../components/Common/ItemSelection.tsx | 3 ++ .../components/Header/ActionsBar.tsx | 53 ++++++++++--------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e34383a..1b272288 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [10.x.x] - 2024-xx-xx +### 🎨 Enhancements + +- [#878](https://github.com/estruyf/vscode-front-matter/issues/878): Allow the `select all` button to work on other pages when there is a selection present + ### 🐞 Fixes - [#876](https://github.com/estruyf/vscode-front-matter/issues/876): Fix snippet type on the snippet card diff --git a/src/dashboardWebView/components/Common/ItemSelection.tsx b/src/dashboardWebView/components/Common/ItemSelection.tsx index eeda2de4..13f9a99d 100644 --- a/src/dashboardWebView/components/Common/ItemSelection.tsx +++ b/src/dashboardWebView/components/Common/ItemSelection.tsx @@ -25,6 +25,9 @@ export const ItemSelection: React.FunctionComponent = ({
{ + e.stopPropagation(); + }} onChange={() => { onMultiSelect(filePath); }} diff --git a/src/dashboardWebView/components/Header/ActionsBar.tsx b/src/dashboardWebView/components/Header/ActionsBar.tsx index 612a7f17..8035a773 100644 --- a/src/dashboardWebView/components/Header/ActionsBar.tsx +++ b/src/dashboardWebView/components/Header/ActionsBar.tsx @@ -4,8 +4,7 @@ import { CommandLineIcon, PencilIcon, TrashIcon, ChevronDownIcon, XMarkIcon, Eye import { useRecoilState, useRecoilValue } from 'recoil'; import { MultiSelectedItemsAtom, PagedItems, SelectedItemActionAtom, SelectedMediaFolderSelector, SettingsSelector } from '../../state'; import { ActionsBarItem } from './ActionsBarItem'; -import * as l10n from '@vscode/l10n'; -import { LocalizationKey } from '../../../localization'; +import { LocalizationKey, localize } from '../../../localization'; import { Alert } from '../Modals/Alert'; import { messageHandler } from '@estruyf/vscode/dist/client'; import { DashboardMessage } from '../../DashboardMessage'; @@ -68,8 +67,14 @@ export const ActionsBar: React.FunctionComponent = ({ }, [selectedFiles]); const selectAllItems = React.useCallback(() => { - setSelectedFiles([...pagedItems]); - }, [pagedItems]); + const allSelected = [...selectedFiles, ...pagedItems]; + setSelectedFiles(Array.from(new Set(allSelected))); + }, [selectedFiles, pagedItems]); + + const hasAllItemsSelectedOnPage = React.useMemo(() => { + const selectedItemsOnPage = selectedFiles.filter((file) => pagedItems.includes(file)); + return selectedItemsOnPage.length >= pagedItems.length; + }, [selectedFiles, pagedItems]); const languageActions = React.useMemo(() => { const actions: React.ReactNode[] = []; @@ -92,7 +97,7 @@ export const ActionsBar: React.FunctionComponent = ({ }) }}> - {l10n.t(LocalizationKey.commonTranslate)} + {localize(LocalizationKey.commonTranslate)} ) @@ -107,7 +112,7 @@ export const ActionsBar: React.FunctionComponent = ({ className='flex items-center text-[var(--vscode-tab-inactiveForeground)] hover:text-[var(--vscode-tab-activeForeground)]' > - {l10n.t(LocalizationKey.commonLanguages)} + {localize(LocalizationKey.commonLanguages)} @@ -163,7 +168,7 @@ export const ActionsBar: React.FunctionComponent = ({ disabled={selectedFiles.length === 0} > - {l10n.t(LocalizationKey.commonScripts)} + {localize(LocalizationKey.commonScripts)} @@ -197,10 +202,10 @@ export const ActionsBar: React.FunctionComponent = ({ 1} onClick={viewFile} - title={l10n.t(LocalizationKey.commonView)} + title={localize(LocalizationKey.commonView)} > { @@ -211,10 +216,10 @@ export const ActionsBar: React.FunctionComponent = ({ messageHandler.send(DashboardMessage.rename, selectedFiles[0]); setSelectedFiles([]); }} - title={l10n.t(LocalizationKey.commonRename)} + title={localize(LocalizationKey.commonRename)} >
@@ -258,33 +263,33 @@ export const ActionsBar: React.FunctionComponent = ({ setSelectedFiles([])} - title={l10n.t(LocalizationKey.dashboardHeaderActionsBarItemsSelected, selectedFiles.length)} + title={localize(LocalizationKey.dashboardHeaderActionsBarItemsSelected, selectedFiles.length)} > ) }
- {l10n.t(LocalizationKey.dashboardHeaderActionsBarSelectAll)} + {localize(LocalizationKey.dashboardHeaderActionsBarSelectAll)}
{showAlert && ( setShowAlert(false)} trigger={onDeleteConfirm} /> From 6f288ff757adce30158f90fae3c8571e3ccc7f5c Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Thu, 24 Oct 2024 14:25:34 +0200 Subject: [PATCH 04/14] #879 Fix for auto updating last modified date on save --- CHANGELOG.md | 1 + src/commands/Article.ts | 17 +++++++++++++---- src/extension.ts | 13 ++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b272288..61920621 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### 🐞 Fixes - [#876](https://github.com/estruyf/vscode-front-matter/issues/876): Fix snippet type on the snippet card +- [#879](https://github.com/estruyf/vscode-front-matter/issues/879): Fix for auto updating last modified date on save ## [10.5.1] - 2024-10-23 diff --git a/src/commands/Article.ts b/src/commands/Article.ts index b0e35076..044ef7da 100644 --- a/src/commands/Article.ts +++ b/src/commands/Article.ts @@ -52,7 +52,7 @@ export class Article { * * @param subscriptions - The array of subscriptions to register the commands with. */ - public static async registerCommands(subscriptions: unknown[]) { + public static registerCommands(subscriptions: unknown[]) { subscriptions.push( commands.registerCommand(COMMAND_NAME.setLastModifiedDate, Article.setLastModifiedDate) ); @@ -66,6 +66,15 @@ export class Article { subscriptions.push(commands.registerCommand(COMMAND_NAME.insertSnippet, Article.insertSnippet)); } + /** + * Registers event listeners for the Article class. + * + * @param subscriptions - An array to which the event listener will be added. + */ + public static registerListeners(subscriptions: unknown[]) { + subscriptions.push(workspace.onWillSaveTextDocument(Article.autoUpdate)); + } + /** * Sets the article date */ @@ -369,15 +378,15 @@ export class Article { * Article auto updater * @param event */ - public static async autoUpdate(event: TextDocumentWillSaveEvent) { + public static autoUpdate(event: TextDocumentWillSaveEvent) { const document = event.document; if (document && ArticleHelper.isSupportedFile(document)) { const autoUpdate = Settings.get(SETTING_AUTO_UPDATE_DATE); // Is article located in one of the content folders - const folders = await Folders.getCachedOrFresh(); + const folders = Folders.getCached(); const documentPath = parseWinPath(document.fileName); - const folder = folders.find((f) => documentPath.startsWith(f.path)); + const folder = folders?.find((f) => documentPath.startsWith(f.path)); if (!folder) { return; } diff --git a/src/extension.ts b/src/extension.ts index 49c560bf..8c523e4e 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,7 +14,7 @@ import ContentProvider from './providers/ContentProvider'; import { PagesListener } from './listeners/dashboard'; import { ModeSwitch } from './services/ModeSwitch'; import { PagesParser } from './services/PagesParser'; -import { ContentType, Telemetry, Extension } from './helpers'; +import { ContentType, Extension } from './helpers'; import * as l10n from '@vscode/l10n'; import { Backers, @@ -121,8 +121,9 @@ export async function activate(context: vscode.ExtensionContext) { // Register the taxonomy commands Taxonomy.registerCommands(subscriptions); - // Register all the article commands + // Register all the article commands and listeners Article.registerCommands(subscriptions); + Article.registerListeners(subscriptions); // Template creation Template.registerCommands(); @@ -181,9 +182,6 @@ export async function activate(context: vscode.ExtensionContext) { // Automatically run the command triggerPageUpdate(`main`); - // Listener for file edit changes - subscriptions.push(vscode.workspace.onWillSaveTextDocument(handleAutoDateUpdate)); - // Listener for file saves subscriptions.push(PagesListener.saveFileWatcher()); @@ -241,16 +239,13 @@ export async function activate(context: vscode.ExtensionContext) { // Subscribe all commands subscriptions.push(PanelView, collapseAll, fmStatusBarItem); + // eslint-disable-next-line no-console console.log(`π–₯π—‹π—ˆπ—‡π— 𝖬𝖺𝗍𝗍𝖾𝗋 𝖒𝖬𝖲 𝖺𝖼𝗍𝗂𝗏𝖺𝗍𝖾𝖽! 𝖱𝖾𝖺𝖽𝗒 π—π—ˆ π—Œπ—π–Ίπ—‹π— 𝗐𝗋𝗂𝗍𝗂𝗇𝗀... πŸ‘©β€πŸ’»πŸ§‘β€πŸ’»πŸ‘¨β€πŸ’»`); } // eslint-disable-next-line @typescript-eslint/no-empty-function export function deactivate() {} -const handleAutoDateUpdate = (e: vscode.TextDocumentWillSaveEvent) => { - Article.autoUpdate(e); -}; - const triggerPageUpdate = (location: string) => { Logger.verbose(`Trigger page update: ${location}`); pageUpdateDebouncer(() => { From c84af8493b9ab1f2ff614a609662dc88bb86ceae Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 28 Oct 2024 10:40:49 +0100 Subject: [PATCH 05/14] Enhancement: dynamic evaluation of commands #882 --- CHANGELOG.md | 1 + src/helpers/CustomScript.ts | 91 +++++++++++++++++++++++++++++++------ src/models/ShellSetting.ts | 3 ++ src/models/index.ts | 1 + src/services/Terminal.ts | 19 +------- src/utils/getPlatform.ts | 20 ++++++++ src/utils/index.ts | 1 + 7 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 src/models/ShellSetting.ts create mode 100644 src/utils/getPlatform.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 61920621..fc852f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### 🎨 Enhancements - [#878](https://github.com/estruyf/vscode-front-matter/issues/878): Allow the `select all` button to work on other pages when there is a selection present +- [#882](https://github.com/estruyf/vscode-front-matter/issues/882): Dynamic evaluation of the `node` executable path ### 🐞 Fixes diff --git a/src/helpers/CustomScript.ts b/src/helpers/CustomScript.ts index 33c0e529..2e83b1e5 100644 --- a/src/helpers/CustomScript.ts +++ b/src/helpers/CustomScript.ts @@ -1,7 +1,7 @@ import { Settings } from './SettingsHelper'; -import { CommandType, EnvironmentType } from './../models/PanelSettings'; +import { CommandType } from './../models/PanelSettings'; import { CustomScript as ICustomScript, ScriptType } from '../models/PanelSettings'; -import { window, env as vscodeEnv, ProgressLocation, Uri, commands } from 'vscode'; +import { window, env as vscodeEnv, ProgressLocation, Uri, commands, workspace } from 'vscode'; import { ArticleHelper, Logger, MediaHelpers } from '.'; import { Folders, WORKSPACE_PLACEHOLDER } from '../commands/Folders'; import { exec, execSync } from 'child_process'; @@ -13,9 +13,10 @@ import { Dashboard } from '../commands/Dashboard'; import { DashboardCommand } from '../dashboardWebView/DashboardCommand'; import { ParsedFrontMatter } from '../parsers'; import { SETTING_CUSTOM_SCRIPTS } from '../constants'; -import { existsAsync } from '../utils'; +import { existsAsync, getPlatform } from '../utils'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../localization'; +import { ShellSetting } from '../models'; export class CustomScript { /** @@ -373,7 +374,7 @@ export class CustomScript { wsPath: string, args: string ): Promise { - const osType = os.type(); + const platform = getPlatform(); // Check the command to use let command = script.nodeBin || 'node'; @@ -381,6 +382,10 @@ export class CustomScript { command = script.command; } + if (script.command === CommandType.Node && platform !== 'windows') { + command = await CustomScript.evaluateCommand(CommandType.Node); + } + let scriptPath = join(wsPath, script.script); if (script.script.includes(WORKSPACE_PLACEHOLDER)) { scriptPath = Folders.getAbsFilePath(script.script); @@ -388,19 +393,15 @@ export class CustomScript { // Check if there is an environments overwrite required if (script.environments) { - let crntType: EnvironmentType | null = null; - if (osType === 'Windows_NT') { - crntType = 'windows'; - } else if (osType === 'Darwin') { - crntType = 'macos'; - } else { - crntType = 'linux'; - } - - const environment = script.environments.find((e) => e.type === crntType); + const environment = script.environments.find((e) => e.type === platform); if (environment && environment.script && environment.command) { if (await CustomScript.validateCommand(environment.command)) { command = environment.command; + + if (command === CommandType.Node && platform !== 'windows') { + command = await CustomScript.evaluateCommand(CommandType.Node); + } + scriptPath = join(wsPath, environment.script); if (environment.script.includes(WORKSPACE_PLACEHOLDER)) { scriptPath = Folders.getAbsFilePath(environment.script); @@ -414,7 +415,7 @@ export class CustomScript { throw new Error(`Script not found: ${scriptPath}`); } - if (osType === 'Windows_NT' && command.toLowerCase() === 'powershell') { + if (platform === 'windows' && command.toLowerCase() === 'powershell') { command = `${command} -File`; } @@ -506,4 +507,64 @@ export class CustomScript { return false; } } + + /** + * Evaluate the command dynamically using `which` command + * @param command + * @returns + */ + private static async evaluateCommand(command: string): Promise { + const shell = CustomScript.getShellPath(); + let shellPath: string | undefined = undefined; + if (typeof shell !== 'string' && !!shell) { + shellPath = shell.path; + } else { + shellPath = shell || undefined; + } + + return new Promise((resolve, reject) => { + exec(`which ${command}`, { shell: shellPath }, (error, stdout) => { + if (error) { + Logger.error(`Error evaluating command: ${command}`); + reject(error); + return; + } + + resolve(stdout.trim()); + }); + }); + } + + /** + * Retrieves the shell path configuration based on the current platform and terminal settings. + * + * This method checks for the following configurations in order: + * 1. `integrated.automationProfile.`: Returns the automation profile if it exists. + * 2. `integrated.defaultProfile.` and `integrated.profiles.`: Returns the shell setting from the default profile if it exists. + * 3. `integrated.shell.`: Returns the shell setting if the above configurations are not found. + * + * @returns {string | ShellSetting | undefined} The shell path configuration or undefined if not found. + */ + private static getShellPath(): string | ShellSetting | undefined { + const platform = getPlatform(); + const terminalSettings = workspace.getConfiguration('terminal'); + + const automationProfile = terminalSettings.get( + `integrated.automationProfile.${platform}` + ); + if (!!automationProfile) { + return automationProfile; + } + + const defaultProfile = terminalSettings.get(`integrated.defaultProfile.${platform}`); + const profiles = terminalSettings.get<{ [prop: string]: ShellSetting }>( + `integrated.profiles.${platform}` + ); + + if (defaultProfile && profiles && profiles[defaultProfile]) { + return profiles[defaultProfile]; + } + + return terminalSettings.get(`integrated.shell.${platform}`); + } } diff --git a/src/models/ShellSetting.ts b/src/models/ShellSetting.ts new file mode 100644 index 00000000..05a90dd8 --- /dev/null +++ b/src/models/ShellSetting.ts @@ -0,0 +1,3 @@ +export interface ShellSetting { + path: string; +} diff --git a/src/models/index.ts b/src/models/index.ts index 82b09148..81684673 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -22,6 +22,7 @@ export * from './Mode'; export * from './PanelSettings'; export * from './PostMessageData'; export * from './Project'; +export * from './ShellSetting'; export * from './Snippets'; export * from './SortOrder'; export * from './SortType'; diff --git a/src/services/Terminal.ts b/src/services/Terminal.ts index fa6b2ff3..9e93c842 100644 --- a/src/services/Terminal.ts +++ b/src/services/Terminal.ts @@ -1,8 +1,8 @@ import { workspace, window, ThemeIcon, TerminalOptions } from 'vscode'; -import * as os from 'os'; import { Folders } from '../commands'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../localization'; +import { getPlatform } from '../utils'; interface ShellSetting { path: string; @@ -96,7 +96,7 @@ export class Terminal { * @returns */ private static getShellPath(): string | ShellSetting | undefined { - const platform = Terminal.getPlatform(); + const platform = getPlatform(); const terminalSettings = workspace.getConfiguration('terminal'); const automationProfile = terminalSettings.get( @@ -117,19 +117,4 @@ export class Terminal { return terminalSettings.get(`integrated.shell.${platform}`); } - - /** - * Get the current platform - * @returns - */ - private static getPlatform = (): 'windows' | 'linux' | 'osx' => { - const platform = os.platform(); - if (platform === 'win32') { - return 'windows'; - } else if (platform === 'darwin') { - return 'osx'; - } - - return 'linux'; - }; } diff --git a/src/utils/getPlatform.ts b/src/utils/getPlatform.ts new file mode 100644 index 00000000..da5b4f77 --- /dev/null +++ b/src/utils/getPlatform.ts @@ -0,0 +1,20 @@ +import * as os from 'os'; + +/** + * Determines the current operating system platform. + * + * @returns {'windows' | 'linux' | 'osx'} - A string representing the platform: + * - 'windows' for Windows OS + * - 'osx' for macOS + * - 'linux' for Linux OS + */ +export const getPlatform = (): 'windows' | 'linux' | 'osx' => { + const platform = os.platform(); + if (platform === 'win32') { + return 'windows'; + } else if (platform === 'darwin') { + return 'osx'; + } + + return 'linux'; +}; diff --git a/src/utils/index.ts b/src/utils/index.ts index f1013c87..ee7fbcfb 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -8,6 +8,7 @@ export * from './flattenObjectKeys'; export * from './getDescriptionField'; export * from './getExtensibilityScripts'; export * from './getLocalizationFile'; +export * from './getPlatform'; export * from './getTitleField'; export * from './getWebviewJsFiles'; export * from './ignoreMsgCommand'; From fc96c8922cf7adfb1d34088031606310b5788b29 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 28 Oct 2024 14:41:50 +0100 Subject: [PATCH 06/14] Feedback: Enum/Select in schema fields #859 --- CHANGELOG.md | 1 + src/components/uniforms-frontmatter/SelectField.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc852f51..ed5e973d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### 🐞 Fixes +- [#859](https://github.com/estruyf/vscode-front-matter/issues/859): Fix label in the data view dropdown field - [#876](https://github.com/estruyf/vscode-front-matter/issues/876): Fix snippet type on the snippet card - [#879](https://github.com/estruyf/vscode-front-matter/issues/879): Fix for auto updating last modified date on save diff --git a/src/components/uniforms-frontmatter/SelectField.tsx b/src/components/uniforms-frontmatter/SelectField.tsx index 05f14200..331de380 100644 --- a/src/components/uniforms-frontmatter/SelectField.tsx +++ b/src/components/uniforms-frontmatter/SelectField.tsx @@ -42,6 +42,7 @@ function Select({ ...props }: SelectFieldProps) { const multiple = fieldType === Array; + return (
@@ -84,11 +85,12 @@ function Select({ }} ref={inputRef} value={value ?? ''} + className='text-[var(--vscode-foreground)] bg-[var(--vscode-list-activeSelectionBackground)] rounded-[2px] active:border-transparent disabled:opacity-40 disabled:cursor-not-allowed focus:outline-none' style={{ width: '100%', padding: '0.5rem' }} > - {(!!placeholder || !required || value === undefined) && !multiple && ( + {(!required || value === undefined) && !multiple && ( )} From f8f539be0d6c7b7c048dcb8cccb583008084bb2e Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 28 Oct 2024 15:07:35 +0100 Subject: [PATCH 07/14] #862 - evaluate the node command --- src/helpers/CustomScript.ts | 99 ++++++-------------------- src/listeners/dashboard/SsgListener.ts | 9 ++- src/services/Terminal.ts | 40 ++--------- src/utils/evaluateCommand.ts | 30 ++++++++ src/utils/getShellPath.ts | 36 ++++++++++ src/utils/index.ts | 2 + 6 files changed, 100 insertions(+), 116 deletions(-) create mode 100644 src/utils/evaluateCommand.ts create mode 100644 src/utils/getShellPath.ts diff --git a/src/helpers/CustomScript.ts b/src/helpers/CustomScript.ts index 2e83b1e5..79d9aa70 100644 --- a/src/helpers/CustomScript.ts +++ b/src/helpers/CustomScript.ts @@ -1,7 +1,7 @@ import { Settings } from './SettingsHelper'; import { CommandType } from './../models/PanelSettings'; import { CustomScript as ICustomScript, ScriptType } from '../models/PanelSettings'; -import { window, env as vscodeEnv, ProgressLocation, Uri, commands, workspace } from 'vscode'; +import { window, env as vscodeEnv, ProgressLocation, Uri, commands } from 'vscode'; import { ArticleHelper, Logger, MediaHelpers } from '.'; import { Folders, WORKSPACE_PLACEHOLDER } from '../commands/Folders'; import { exec, execSync } from 'child_process'; @@ -13,10 +13,8 @@ import { Dashboard } from '../commands/Dashboard'; import { DashboardCommand } from '../dashboardWebView/DashboardCommand'; import { ParsedFrontMatter } from '../parsers'; import { SETTING_CUSTOM_SCRIPTS } from '../constants'; -import { existsAsync, getPlatform } from '../utils'; -import * as l10n from '@vscode/l10n'; -import { LocalizationKey } from '../localization'; -import { ShellSetting } from '../models'; +import { evaluateCommand, existsAsync, getPlatform } from '../utils'; +import { LocalizationKey, localize } from '../localization'; export class CustomScript { /** @@ -102,7 +100,7 @@ export class CustomScript { ); } else { Notifications.warning( - l10n.t(LocalizationKey.helpersCustomScriptSingleRunArticleWarning, script.title) + localize(LocalizationKey.helpersCustomScriptSingleRunArticleWarning, script.title) ); } } @@ -118,7 +116,7 @@ export class CustomScript { if (!folders || folders.length === 0) { Notifications.warning( - l10n.t(LocalizationKey.helpersCustomScriptBulkRunNoFilesWarning, script.title) + localize(LocalizationKey.helpersCustomScriptBulkRunNoFilesWarning, script.title) ); return; } @@ -128,7 +126,7 @@ export class CustomScript { window.withProgress( { location: ProgressLocation.Notification, - title: l10n.t(LocalizationKey.helpersCustomScriptExecuting, script.title), + title: localize(LocalizationKey.helpersCustomScriptExecuting, script.title), cancellable: false }, async (_, __) => { @@ -174,7 +172,7 @@ export class CustomScript { ): Promise { if (!path) { Notifications.error( - l10n.t(LocalizationKey.helpersCustomScriptRunMediaScriptNoFolderWarning, script.title) + localize(LocalizationKey.helpersCustomScriptRunMediaScriptNoFolderWarning, script.title) ); return; } @@ -183,7 +181,7 @@ export class CustomScript { window.withProgress( { location: ProgressLocation.Notification, - title: l10n.t(LocalizationKey.helpersCustomScriptExecuting, script.title), + title: localize(LocalizationKey.helpersCustomScriptExecuting, script.title), cancellable: false }, async () => { @@ -310,7 +308,10 @@ export class CustomScript { throw new Error(`Couldn't update article.`); } Notifications.info( - l10n.t(LocalizationKey.helpersCustomScriptShowOutputFrontMatterSuccess, script.title) + localize( + LocalizationKey.helpersCustomScriptShowOutputFrontMatterSuccess, + script.title + ) ); } } else if (data.fmAction) { @@ -346,10 +347,12 @@ export class CustomScript { window .showInformationMessage( `${script.title}: ${output}`, - l10n.t(LocalizationKey.helpersCustomScriptShowOutputCopyOutputAction) + localize(LocalizationKey.helpersCustomScriptShowOutputCopyOutputAction) ) .then((value) => { - if (value === l10n.t(LocalizationKey.helpersCustomScriptShowOutputCopyOutputAction)) { + if ( + value === localize(LocalizationKey.helpersCustomScriptShowOutputCopyOutputAction) + ) { vscodeEnv.clipboard.writeText(output); } }); @@ -357,7 +360,7 @@ export class CustomScript { } } else { Notifications.info( - l10n.t(LocalizationKey.helpersCustomScriptShowOutputSuccess, script.title) + localize(LocalizationKey.helpersCustomScriptShowOutputSuccess, script.title) ); } } @@ -383,7 +386,7 @@ export class CustomScript { } if (script.command === CommandType.Node && platform !== 'windows') { - command = await CustomScript.evaluateCommand(CommandType.Node); + command = await evaluateCommand(CommandType.Node); } let scriptPath = join(wsPath, script.script); @@ -399,7 +402,7 @@ export class CustomScript { command = environment.command; if (command === CommandType.Node && platform !== 'windows') { - command = await CustomScript.evaluateCommand(CommandType.Node); + command = await evaluateCommand(CommandType.Node); } scriptPath = join(wsPath, environment.script); @@ -420,7 +423,7 @@ export class CustomScript { } const fullScript = `${command} "${scriptPath}" ${args}`; - Logger.info(l10n.t(LocalizationKey.helpersCustomScriptExecuting, fullScript)); + Logger.info(localize(LocalizationKey.helpersCustomScriptExecuting, fullScript)); const output: string = await CustomScript.executeScriptAsync(fullScript, wsPath); @@ -503,68 +506,8 @@ export class CustomScript { return true; } catch (e) { - Logger.error(l10n.t(LocalizationKey.helpersCustomScriptValidateCommandError, command)); + Logger.error(localize(LocalizationKey.helpersCustomScriptValidateCommandError, command)); return false; } } - - /** - * Evaluate the command dynamically using `which` command - * @param command - * @returns - */ - private static async evaluateCommand(command: string): Promise { - const shell = CustomScript.getShellPath(); - let shellPath: string | undefined = undefined; - if (typeof shell !== 'string' && !!shell) { - shellPath = shell.path; - } else { - shellPath = shell || undefined; - } - - return new Promise((resolve, reject) => { - exec(`which ${command}`, { shell: shellPath }, (error, stdout) => { - if (error) { - Logger.error(`Error evaluating command: ${command}`); - reject(error); - return; - } - - resolve(stdout.trim()); - }); - }); - } - - /** - * Retrieves the shell path configuration based on the current platform and terminal settings. - * - * This method checks for the following configurations in order: - * 1. `integrated.automationProfile.`: Returns the automation profile if it exists. - * 2. `integrated.defaultProfile.` and `integrated.profiles.`: Returns the shell setting from the default profile if it exists. - * 3. `integrated.shell.`: Returns the shell setting if the above configurations are not found. - * - * @returns {string | ShellSetting | undefined} The shell path configuration or undefined if not found. - */ - private static getShellPath(): string | ShellSetting | undefined { - const platform = getPlatform(); - const terminalSettings = workspace.getConfiguration('terminal'); - - const automationProfile = terminalSettings.get( - `integrated.automationProfile.${platform}` - ); - if (!!automationProfile) { - return automationProfile; - } - - const defaultProfile = terminalSettings.get(`integrated.defaultProfile.${platform}`); - const profiles = terminalSettings.get<{ [prop: string]: ShellSetting }>( - `integrated.profiles.${platform}` - ); - - if (defaultProfile && profiles && profiles[defaultProfile]) { - return profiles[defaultProfile]; - } - - return terminalSettings.get(`integrated.shell.${platform}`); - } } diff --git a/src/listeners/dashboard/SsgListener.ts b/src/listeners/dashboard/SsgListener.ts index c7199df8..2b5ad5dd 100644 --- a/src/listeners/dashboard/SsgListener.ts +++ b/src/listeners/dashboard/SsgListener.ts @@ -12,7 +12,7 @@ import { } from '../../constants'; import { SettingsListener } from './SettingsListener'; import { Terminal } from '../../services'; -import { existsAsync, readFileAsync } from '../../utils'; +import { evaluateCommand, existsAsync, getPlatform, readFileAsync } from '../../utils'; import { join } from 'path'; export class SsgListener extends BaseListener { @@ -170,7 +170,12 @@ export class SsgListener extends BaseListener { workspace.fs.copy(scriptPath, tempScriptPath, { overwrite: true }); } - const fullScript = `node "${tempScriptPath.fsPath}" "${contentConfigFile.fsPath}"`; + let nodeExecPath = 'node'; + const platform = getPlatform(); + if (platform !== 'windows') { + nodeExecPath = await evaluateCommand('node'); + } + const fullScript = `${nodeExecPath} "${tempScriptPath.fsPath}" "${contentConfigFile.fsPath}"`; try { const result: string = await SsgListener.executeScript(fullScript, wsFolder?.fsPath || ''); diff --git a/src/services/Terminal.ts b/src/services/Terminal.ts index 9e93c842..4c9aa06c 100644 --- a/src/services/Terminal.ts +++ b/src/services/Terminal.ts @@ -1,12 +1,7 @@ import { workspace, window, ThemeIcon, TerminalOptions } from 'vscode'; import { Folders } from '../commands'; -import * as l10n from '@vscode/l10n'; -import { LocalizationKey } from '../localization'; -import { getPlatform } from '../utils'; - -interface ShellSetting { - path: string; -} +import { LocalizationKey, localize } from '../localization'; +import { getShellPath } from '../utils'; export class Terminal { public static readonly terminalName: string = 'Local server'; @@ -15,7 +10,7 @@ export class Terminal { * Return the shell path for the current platform */ public static get shell() { - const shell: string | { path: string } | undefined = Terminal.getShellPath(); + const shell: string | { path: string } | undefined = getShellPath(); let shellPath: string | undefined = undefined; if (typeof shell !== 'string' && !!shell) { @@ -47,7 +42,7 @@ export class Terminal { const terminalOptions: TerminalOptions = { name: Terminal.terminalName, iconPath: new ThemeIcon('server-environment'), - message: l10n.t( + message: localize( LocalizationKey.servicesTerminalOpenLocalServerTerminalTerminalOptionMessage ) }; @@ -90,31 +85,4 @@ export class Terminal { return localServerTerminal; } } - - /** - * Retrieve the automation profile for the current platform - * @returns - */ - private static getShellPath(): string | ShellSetting | undefined { - const platform = getPlatform(); - const terminalSettings = workspace.getConfiguration('terminal'); - - const automationProfile = terminalSettings.get( - `integrated.automationProfile.${platform}` - ); - if (!!automationProfile) { - return automationProfile; - } - - const defaultProfile = terminalSettings.get(`integrated.defaultProfile.${platform}`); - const profiles = terminalSettings.get<{ [prop: string]: ShellSetting }>( - `integrated.profiles.${platform}` - ); - - if (defaultProfile && profiles && profiles[defaultProfile]) { - return profiles[defaultProfile]; - } - - return terminalSettings.get(`integrated.shell.${platform}`); - } } diff --git a/src/utils/evaluateCommand.ts b/src/utils/evaluateCommand.ts new file mode 100644 index 00000000..735c6a5a --- /dev/null +++ b/src/utils/evaluateCommand.ts @@ -0,0 +1,30 @@ +import { exec } from 'child_process'; +import { getShellPath } from '../utils'; +import { Logger } from '../helpers'; + +/** + * Evaluate the command dynamically using `which` command + * @param command + * @returns + */ +export const evaluateCommand = (command: string): Promise => { + const shell = getShellPath(); + let shellPath: string | undefined = undefined; + if (typeof shell !== 'string' && !!shell) { + shellPath = shell.path; + } else { + shellPath = shell || undefined; + } + + return new Promise((resolve, reject) => { + exec(`which ${command}`, { shell: shellPath }, (error, stdout) => { + if (error) { + Logger.error(`Error evaluating command: ${command}`); + reject(error); + return; + } + + resolve(stdout.trim()); + }); + }); +}; diff --git a/src/utils/getShellPath.ts b/src/utils/getShellPath.ts new file mode 100644 index 00000000..62bca2a0 --- /dev/null +++ b/src/utils/getShellPath.ts @@ -0,0 +1,36 @@ +import { workspace } from 'vscode'; +import { ShellSetting } from '../models'; +import { getPlatform } from './getPlatform'; + +/** + * Retrieves the shell path configuration based on the current platform and terminal settings. + * + * This method checks for the following configurations in order: + * 1. `integrated.automationProfile.`: Returns the automation profile if it exists. + * 2. `integrated.defaultProfile.` and `integrated.profiles.`: Returns the shell setting from the default profile if it exists. + * 3. `integrated.shell.`: Returns the shell setting if the above configurations are not found. + * + * @returns {string | ShellSetting | undefined} The shell path configuration or undefined if not found. + */ +export const getShellPath = (): string | ShellSetting | undefined => { + const platform = getPlatform(); + const terminalSettings = workspace.getConfiguration('terminal'); + + const automationProfile = terminalSettings.get( + `integrated.automationProfile.${platform}` + ); + if (!!automationProfile) { + return automationProfile; + } + + const defaultProfile = terminalSettings.get(`integrated.defaultProfile.${platform}`); + const profiles = terminalSettings.get<{ [prop: string]: ShellSetting }>( + `integrated.profiles.${platform}` + ); + + if (defaultProfile && profiles && profiles[defaultProfile]) { + return profiles[defaultProfile]; + } + + return terminalSettings.get(`integrated.shell.${platform}`); +}; diff --git a/src/utils/index.ts b/src/utils/index.ts index ee7fbcfb..49951555 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,7 @@ export * from './cn'; export * from './copyFileAsync'; export * from './encodeEmoji'; +export * from './evaluateCommand'; export * from './existsAsync'; export * from './fetchWithTimeout'; export * from './fieldWhenClause'; @@ -9,6 +10,7 @@ export * from './getDescriptionField'; export * from './getExtensibilityScripts'; export * from './getLocalizationFile'; export * from './getPlatform'; +export * from './getShellPath'; export * from './getTitleField'; export * from './getWebviewJsFiles'; export * from './ignoreMsgCommand'; From 7796d52ff9ef70960ef66baf5295d4f62c07b829 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 28 Oct 2024 16:25:49 +0100 Subject: [PATCH 08/14] Fix beta version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cfcfab5f..98026e38 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "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, Docusaurus, NextJs, Gatsby, and many more...", "icon": "assets/frontmatter-teal-128x128.png", - "version": "10.5.1", + "version": "10.6.0", "preview": false, "publisher": "eliostruyf", "galleryBanner": { From 57b710cc6130ac5ea3638f7a8158ea142b91998f Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 11:23:19 +0100 Subject: [PATCH 09/14] Enhancement: hide WYSIWYG actions in git diff mode #884 --- CHANGELOG.md | 1 + package.json | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed5e973d..11117adb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - [#878](https://github.com/estruyf/vscode-front-matter/issues/878): Allow the `select all` button to work on other pages when there is a selection present - [#882](https://github.com/estruyf/vscode-front-matter/issues/882): Dynamic evaluation of the `node` executable path +- [#884](https://github.com/estruyf/vscode-front-matter/issues/884): Hide WYSIWYG actions when the file is in git diff mode ### 🐞 Fixes diff --git a/package.json b/package.json index 98026e38..747b6d01 100644 --- a/package.json +++ b/package.json @@ -2421,32 +2421,32 @@ "editor/title": [{ "command": "frontMatter.markup.heading", "group": "navigation@-133", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.bold", "group": "navigation@-132", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.italic", "group": "navigation@-131", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.hyperlink", "group": "navigation@-130", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.insertSnippet", "group": "navigation@-129", - "when": "frontMatter:file:isValid == true && frontMatter:dashboard:snippets:enabled" + "when": "frontMatter:file:isValid == true && frontMatter:dashboard:snippets:enabled && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.insertMedia", "group": "navigation@-128", - "when": "frontMatter:file:isValid == true" + "when": "frontMatter:file:isValid == true && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.i18n.createOrOpen", @@ -2456,37 +2456,37 @@ { "command": "frontMatter.markup.options", "group": "navigation@-126", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.orderedlist", "group": "1_markup@1", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.unorderedlist", "group": "1_markup@2", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.tasklist", "group": "1_markup@3", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.code", "group": "1_markup@4", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.codeblock", "group": "1_markup@5", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.markup.blockquote", "group": "1_markup@6", - "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg" + "when": "frontMatter:file:isValid == true && frontMatter:markdown:wysiwyg && activeEditor == 'workbench.editors.files.textFileEditor'" }, { "command": "frontMatter.dashboard", From 3d6359bc2e03da816abcf6eb6aeb999d4bf5539b Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 13:20:18 +0100 Subject: [PATCH 10/14] Issue: Content relationship field type is fetching forever #885 --- CHANGELOG.md | 1 + src/listeners/panel/FieldsListener.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11117adb..a049c497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - [#859](https://github.com/estruyf/vscode-front-matter/issues/859): Fix label in the data view dropdown field - [#876](https://github.com/estruyf/vscode-front-matter/issues/876): Fix snippet type on the snippet card - [#879](https://github.com/estruyf/vscode-front-matter/issues/879): Fix for auto updating last modified date on save +- [#885](https://github.com/estruyf/vscode-front-matter/issues/885): Fix content relationship for none i18n content ## [10.5.1] - 2024-10-23 diff --git a/src/listeners/panel/FieldsListener.ts b/src/listeners/panel/FieldsListener.ts index 6ebc62e0..ef68963f 100644 --- a/src/listeners/panel/FieldsListener.ts +++ b/src/listeners/panel/FieldsListener.ts @@ -39,8 +39,9 @@ export class FieldsListener extends BaseListener { return; } + const isLocaleEnabled = await i18n.isLocaleEnabled(data.activePath); const activeLocale = await i18n.getLocale(data.activePath); - if (!activeLocale?.locale) { + if (isLocaleEnabled && !activeLocale?.locale) { return; } @@ -48,7 +49,7 @@ export class FieldsListener extends BaseListener { const fuseOptions: Fuse.IFuseOptions = { keys: [ { name: 'fmContentType', weight: 1 }, - ...(data.sameLocale ? [{ name: 'fmLocale.locale', weight: 1 }] : []) + ...(isLocaleEnabled && data.sameLocale ? [{ name: 'fmLocale.locale', weight: 1 }] : []) ], findAllMatches: true, threshold: 0 @@ -62,8 +63,10 @@ export class FieldsListener extends BaseListener { const fuse = new Fuse(pages || [], fuseOptions, fuseIndex); const results = fuse.search({ $and: [ - { fmContentType: data.type! }, - ...(data.sameLocale ? [{ 'fmLocale.locale': activeLocale.locale }] : []) + { fmContentType: data.type ?? '' }, + ...(isLocaleEnabled && activeLocale?.locale && data.sameLocale + ? [{ 'fmLocale.locale': activeLocale.locale }] + : []) ] }); const pageResults = results.map((page) => page.item); From e838f18abcf56f18dc842d4f6fabd7cc2b9053a1 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 13:42:36 +0100 Subject: [PATCH 11/14] Remove unused ref --- src/dashboardWebView/components/Header/Filters.tsx | 2 +- src/helpers/DashboardSettings.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dashboardWebView/components/Header/Filters.tsx b/src/dashboardWebView/components/Header/Filters.tsx index c0c714e0..78fae729 100644 --- a/src/dashboardWebView/components/Header/Filters.tsx +++ b/src/dashboardWebView/components/Header/Filters.tsx @@ -10,7 +10,7 @@ import { LanguageFilter } from '../Filters/LanguageFilter'; export interface IFiltersProps { } -export const Filters: React.FunctionComponent = (_: React.PropsWithChildren) => { +export const Filters: React.FunctionComponent = () => { const [crntFilters, setCrntFilters] = useRecoilState(FiltersAtom); const [crntTag, setCrntTag] = useRecoilState(TagAtom); const [crntCategory, setCrntCategory] = useRecoilState(CategoryAtom); diff --git a/src/helpers/DashboardSettings.ts b/src/helpers/DashboardSettings.ts index d2275227..c26a8477 100644 --- a/src/helpers/DashboardSettings.ts +++ b/src/helpers/DashboardSettings.ts @@ -1,5 +1,5 @@ import { GitListener } from './../listeners/general/GitListener'; -import { basename, join } from 'path'; +import { join } from 'path'; import { workspace } from 'vscode'; import { Folders } from '../commands/Folders'; import { Project } from '../commands/Project'; @@ -23,7 +23,6 @@ import { SETTING_MEDIA_SUPPORTED_MIMETYPES, SETTING_TAXONOMY_CUSTOM, SETTING_TEMPLATES_ENABLED, - SETTING_GIT_ENABLED, SETTING_DASHBOARD_CONTENT_PAGINATION, SETTING_SNIPPETS_WRAPPER, SETTING_DASHBOARD_CONTENT_CARD_DATE, From 228c46084d53ddd812e7f5c352e77b9c4e087b65 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 18:39:47 +0100 Subject: [PATCH 12/14] Update categories --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 747b6d01..48cb83aa 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "l10n": "./l10n", "categories": [ "AI", - "Other" + "Visualization" ], "keywords": [ "Front Matter", From 17164df11f351949a7ac6fba56d60cfda01a87aa Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Mon, 4 Nov 2024 19:37:00 +0100 Subject: [PATCH 13/14] Update fuse options --- src/listeners/panel/FieldsListener.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/listeners/panel/FieldsListener.ts b/src/listeners/panel/FieldsListener.ts index ef68963f..65f673b3 100644 --- a/src/listeners/panel/FieldsListener.ts +++ b/src/listeners/panel/FieldsListener.ts @@ -46,11 +46,14 @@ export class FieldsListener extends BaseListener { } PagesListener.getPagesData(false, async (pages) => { + const fuseKeys: Fuse.FuseOptionKey[] = [{ name: 'fmContentType', weight: 1 }]; + + if (isLocaleEnabled && data.sameLocale) { + fuseKeys.push({ name: 'fmLocale.locale', weight: 1 }); + } + const fuseOptions: Fuse.IFuseOptions = { - keys: [ - { name: 'fmContentType', weight: 1 }, - ...(isLocaleEnabled && data.sameLocale ? [{ name: 'fmLocale.locale', weight: 1 }] : []) - ], + keys: fuseKeys, findAllMatches: true, threshold: 0 }; @@ -61,13 +64,14 @@ export class FieldsListener extends BaseListener { ); const fuseIndex = Fuse.parseIndex(pagesIndex); const fuse = new Fuse(pages || [], fuseOptions, fuseIndex); + + const andExpression: Fuse.Expression[] = [{ fmContentType: data.type ?? '' }]; + if (isLocaleEnabled && activeLocale?.locale && data.sameLocale) { + andExpression.push({ 'fmLocale.locale': activeLocale.locale }); + } + const results = fuse.search({ - $and: [ - { fmContentType: data.type ?? '' }, - ...(isLocaleEnabled && activeLocale?.locale && data.sameLocale - ? [{ 'fmLocale.locale': activeLocale.locale }] - : []) - ] + $and: andExpression }); const pageResults = results.map((page) => page.item); From 2c4dbeb1eb12bbeff2d40fbae33edb0829825cf3 Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Wed, 6 Nov 2024 10:54:32 +0100 Subject: [PATCH 14/14] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a049c497..075f4669 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [10.x.x] - 2024-xx-xx +## [10.6.0] - 2024-11-06 - [Release notes](https://beta.frontmatter.codes/updates/v10.6.0) ### 🎨 Enhancements