From 8fd635ea94ec7f12dcfaa7d9661a55eb6daca88d Mon Sep 17 00:00:00 2001 From: Tom Short Date: Thu, 26 Jan 2023 19:46:27 -0500 Subject: [PATCH 1/3] feat: add a config option for other file exts --- src/utils/utils.spec.ts | 17 ++++++++++ src/utils/utils.ts | 66 ++++++++++++++++++++---------------- src/workspace/cache/cache.ts | 5 ++- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/utils/utils.spec.ts b/src/utils/utils.spec.ts index 9e2f638d..3ff36d53 100644 --- a/src/utils/utils.spec.ts +++ b/src/utils/utils.spec.ts @@ -1181,6 +1181,23 @@ describe('findNonIgnoredFiles()', () => { }); }); + describe('when config includes py files', () => { + it('should find non-ignored files', async () => { + const prevConfig = getConfigProperty('memo.links.extensions.other', []); + await updateConfigProperty('memo.links.extensions.other', ['py']); + const allowedName = rndName(); + + await createFile(`${allowedName}.py`); + + const files = await findNonIgnoredFiles('**/*.py'); + + expect(files).toHaveLength(1); + expect(path.basename(files[0].fsPath)).toBe(`${allowedName}.py`); + + await updateConfigProperty('memo.links.extensions.other', prevConfig); + }); + }); + describe('when exclude param passed explicitly and search.exclude set', () => { it('should find non-ignored files', async () => { const prevConfig = getConfigProperty('search.exclude', {}); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index fbe27a5e..995b7505 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -12,7 +12,38 @@ export const imageExts = ['png', 'jpg', 'jpeg', 'svg', 'gif', 'webp']; const imageExtsRegex = new RegExp(`.(${imageExts.join('|')})$`, 'i'); -export const otherExts = [ +export function getMemoConfigProperty( + property: 'links.format', + fallback: 'short', +): 'short' | 'long'; + +export function getMemoConfigProperty( + property: 'backlinksPanel.collapseParentItems', + fallback: null | boolean, +): boolean; + +export function getMemoConfigProperty( + property: 'links.preview.imageMaxHeight', + fallback: null | number, +): number; + +export function getMemoConfigProperty( + property: 'links.rules', + fallback: null | Array, +): LinkRuleT[]; + +export function getMemoConfigProperty(property: MemoBoolConfigProp, fallback: boolean): boolean; + +export function getMemoConfigProperty( + property: 'links.extensions.other', + fallback: null | Array, +): String[]; + +export function getMemoConfigProperty(property: string, fallback: T): T { + return getConfigProperty(`memo.${property}`, fallback); +} + +export const otherExts = getMemoConfigProperty('links.extensions.other', [ 'doc', 'docx', 'rtf', @@ -39,9 +70,12 @@ export const otherExts = [ '3gp', 'flac', 'msg', -]; +]); -const otherExtsRegex = new RegExp(`.(${otherExts.join('|')})$`, 'i'); +export const otherExtsRegex = + otherExts.length == 1 && otherExts[0] == '*' + ? new RegExp(`.*`, 'i') + : new RegExp(`.(${otherExts.join('|')})$`, 'i'); // Remember to edit accordingly when extensions above edited export const commonExtsHint = @@ -160,32 +194,6 @@ export type MemoBoolConfigProp = | 'backlinksPanel.enabled' | 'markdownPreview.enabled'; -export function getMemoConfigProperty( - property: 'links.format', - fallback: 'short', -): 'short' | 'long'; - -export function getMemoConfigProperty( - property: 'backlinksPanel.collapseParentItems', - fallback: null | boolean, -): boolean; - -export function getMemoConfigProperty( - property: 'links.preview.imageMaxHeight', - fallback: null | number, -): number; - -export function getMemoConfigProperty( - property: 'links.rules', - fallback: null | Array, -): LinkRuleT[]; - -export function getMemoConfigProperty(property: MemoBoolConfigProp, fallback: boolean): boolean; - -export function getMemoConfigProperty(property: string, fallback: T): T { - return getConfigProperty(`memo.${property}`, fallback); -} - export const matchAll = (pattern: RegExp, text: string): Array => { let match: RegExpMatchArray | null; const out: RegExpMatchArray[] = []; diff --git a/src/workspace/cache/cache.ts b/src/workspace/cache/cache.ts index 73a562d8..4b7289f7 100644 --- a/src/workspace/cache/cache.ts +++ b/src/workspace/cache/cache.ts @@ -92,7 +92,10 @@ export const cacheUris = async () => { const { findNonIgnoredFiles, imageExts, otherExts } = utils(); const markdownUris = await findNonIgnoredFiles('**/*.md'); const imageUris = await findNonIgnoredFiles(`**/*.{${imageExts.join(',')}}`); - const otherUris = await findNonIgnoredFiles(`**/*.{${otherExts.join(',')}}`); + const otherUris = + otherExts.length == 1 && otherExts[0] == '*' + ? await findNonIgnoredFiles('**/*') + : await findNonIgnoredFiles(`**/*.{${otherExts.join(',')}}`); workspaceCache.markdownUris = sortPaths(markdownUris, { pathKey: 'path', shallowFirst: true }); workspaceCache.imageUris = sortPaths(imageUris, { pathKey: 'path', shallowFirst: true }); From e52d78dcfbf071541e97c77e8fe31f958fc07c28 Mon Sep 17 00:00:00 2001 From: Tom Short Date: Thu, 26 Jan 2023 19:59:34 -0500 Subject: [PATCH 2/3] feat: include config --- package.json | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4b547055..ee312e14 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,39 @@ "description": "Whether to enable links completion in the editor. Reload required!", "type": "boolean" }, + "memo.links.extensions.other": { + "scope": "resource", + "description": "Other file extensions supported by links. Use a single entry of '*' to include all extensions.", + "default": [ + "doc", + "docx", + "rtf", + "txt", + "odt", + "xls", + "xlsx", + "ppt", + "pptm", + "pptx", + "pdf", + "pages", + "mp4", + "mov", + "wmv", + "flv", + "avi", + "mkv", + "mp3", + "webm", + "wav", + "m4a", + "ogg", + "3gp", + "flac", + "msg" + ], + "type": "array" + }, "memo.links.following.enabled": { "default": true, "scope": "resource", @@ -169,8 +202,7 @@ "scope": "resource", "description": "Whether to enhance built-in VSCode Markdown preview with links highlight, navigation and resource embedding. Reload required!", "type": "boolean" - } - } + } } }, "keybindings": [ { From d4639ed6908cc6072d3607df842a044c1873669a Mon Sep 17 00:00:00 2001 From: Tom Short Date: Sun, 5 Feb 2023 16:06:35 -0500 Subject: [PATCH 3/3] feat: change config name; add docs --- help/Features/Accepted File Formats.md | 2 +- package.json | 2 +- src/utils/utils.spec.ts | 6 +++--- src/utils/utils.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/help/Features/Accepted File Formats.md b/help/Features/Accepted File Formats.md index 1951cc24..eb3410ce 100644 --- a/help/Features/Accepted File Formats.md +++ b/help/Features/Accepted File Formats.md @@ -4,7 +4,7 @@ Memo recognizes the following file formats: 1. Markdown files: `md`; 2. Image files: `png`, `jpg`, `jpeg`, `svg`, `gif`, `webp`; -3. Other formats: `doc`, `docx`, `rtf`, `txt`, `odt`, `xls`, `xlsx`, `ppt`, `pptm`, `pptx`, `pdf`. See full list of extensions [here](https://github.com/svsool/memo/blob/51d65f594978d30ee049feda710c3ce52ab64bad/src/utils/utils.ts#L12-L44). +3. Other formats: `doc`, `docx`, `rtf`, `txt`, `odt`, `xls`, `xlsx`, `ppt`, `pptm`, `pptx`, `pdf`. See full list of extensions [here](https://github.com/svsool/memo/blob/51d65f594978d30ee049feda710c3ce52ab64bad/src/utils/utils.ts#L12-L44). These default extensions can be changed using the `memo.links.customExtensions` configuration variable. This configuration variable is an array. Use the special case of `["*"]` to allow all extensions. Markdown files and image files can be referenced via regular links `[[image.png]]` or attached using embed links `![[image.png]]`. These file types also support on-hover and built-in previews ([[Notes and images preview.gif|see how it works]]). diff --git a/package.json b/package.json index ee312e14..aa58fe80 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ "description": "Whether to enable links completion in the editor. Reload required!", "type": "boolean" }, - "memo.links.extensions.other": { + "memo.links.customExtensions": { "scope": "resource", "description": "Other file extensions supported by links. Use a single entry of '*' to include all extensions.", "default": [ diff --git a/src/utils/utils.spec.ts b/src/utils/utils.spec.ts index 3ff36d53..8fbcae00 100644 --- a/src/utils/utils.spec.ts +++ b/src/utils/utils.spec.ts @@ -1183,8 +1183,8 @@ describe('findNonIgnoredFiles()', () => { describe('when config includes py files', () => { it('should find non-ignored files', async () => { - const prevConfig = getConfigProperty('memo.links.extensions.other', []); - await updateConfigProperty('memo.links.extensions.other', ['py']); + const prevConfig = getConfigProperty('memo.links.customExtensions', []); + await updateConfigProperty('memo.links.customExtensions', ['py']); const allowedName = rndName(); await createFile(`${allowedName}.py`); @@ -1194,7 +1194,7 @@ describe('findNonIgnoredFiles()', () => { expect(files).toHaveLength(1); expect(path.basename(files[0].fsPath)).toBe(`${allowedName}.py`); - await updateConfigProperty('memo.links.extensions.other', prevConfig); + await updateConfigProperty('memo.links.customExtensions', prevConfig); }); }); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 995b7505..ca4398eb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -35,7 +35,7 @@ export function getMemoConfigProperty( export function getMemoConfigProperty(property: MemoBoolConfigProp, fallback: boolean): boolean; export function getMemoConfigProperty( - property: 'links.extensions.other', + property: 'links.customExtensions', fallback: null | Array, ): String[]; @@ -43,7 +43,7 @@ export function getMemoConfigProperty(property: string, fallback: T): T { return getConfigProperty(`memo.${property}`, fallback); } -export const otherExts = getMemoConfigProperty('links.extensions.other', [ +export const otherExts = getMemoConfigProperty('links.customExtensions', [ 'doc', 'docx', 'rtf',