diff --git a/manifest.json b/manifest.json index 1e0663a..b4fae7c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "gridexplorer", "name": "GridExplorer", - "version": "1.9.14", + "version": "1.9.15", "minAppVersion": "1.1.0", "description": "Browse note files in a grid view.", "author": "Devon22", diff --git a/package-lock.json b/package-lock.json index 8e3af41..678a868 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gridexplorer", - "version": "1.9.14", + "version": "1.9.15", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "gridexplorer", - "version": "1.9.14", + "version": "1.9.15", "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", diff --git a/package.json b/package.json index 2bd6b24..6649507 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gridexplorer", - "version": "1.9.14", + "version": "1.9.15", "description": "Browse note files in a grid view.", "main": "main.js", "scripts": { diff --git a/src/GridView.ts b/src/GridView.ts index 2709caa..4433a90 100644 --- a/src/GridView.ts +++ b/src/GridView.ts @@ -1,5 +1,4 @@ -import { WorkspaceLeaf, ItemView, TFolder, TFile, Menu, Notice, Platform } from 'obsidian'; -import { setIcon, getFrontMatterInfo } from 'obsidian'; +import { WorkspaceLeaf, ItemView, TFolder, TFile, Menu, Notice, Platform, setIcon, getFrontMatterInfo } from 'obsidian'; import { showFolderSelectionModal } from './FolderSelectionModal'; import { findFirstImageInNote } from './mediaUtils'; import { MediaModal } from './MediaModal'; diff --git a/src/fileUtils.ts b/src/fileUtils.ts index 7b95abd..1998728 100644 --- a/src/fileUtils.ts +++ b/src/fileUtils.ts @@ -1,4 +1,4 @@ -import { TFile, TFolder } from 'obsidian'; +import { TFile, TFolder, getFrontMatterInfo } from 'obsidian'; import { type GallerySettings } from './settings'; import { GridView } from './GridView'; @@ -240,7 +240,7 @@ export async function getFiles(gridView: GridView): Promise { return sortFiles(Array.from(backlinks) as TFile[], gridView); } else if (sourceMode === 'outgoinglinks') { - // 外部連結模式:找出當前筆記所引用的檔案 + // 外部連結模式:找出當前筆記所引用的檔案,並包含所有媒體連結 const activeFile = app.workspace.getActiveFile(); if (!activeFile) { return []; @@ -261,6 +261,34 @@ export async function getFiles(gridView: GridView): Promise { } } + // 讀取目前筆記內容,找出所有媒體連結 + if (settings.showMediaFiles) { + try { + const content = await app.vault.cachedRead(activeFile); + // 去除 frontmatter + const frontMatterInfo = getFrontMatterInfo(content); + const contentWithoutFrontmatter = content.substring(frontMatterInfo.contentStart); + + // 正則找出所有媒體連結 + const mediaMatches = Array.from(contentWithoutFrontmatter.matchAll(/(?:!\[\[(.*?)(?:\|.*?)?\]\]|!\[(.*?)\]\((.*?)\))/g)); + for (const match of mediaMatches) { + // 內部連結 ![[xxx]] + let mediaPath = match[1] || match[3]; + if (mediaPath) { + // 處理內部連結路徑(去除 | 之後的部分) + mediaPath = mediaPath.split('|')[0].trim(); + // 取得對應的 TFile + const mediaFile = app.metadataCache.getFirstLinkpathDest(mediaPath, activeFile.path); + if (mediaFile && isMediaFile(mediaFile)) { + outgoingLinks.add(mediaFile); + } + } + } + } catch (e) { + // 忽略讀取錯誤 + } + } + return sortFiles(Array.from(outgoingLinks), gridView); } else if(sourceMode === 'bookmarks') { // 書籤模式 diff --git a/versions.json b/versions.json index b39bd43..e2d3ad7 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.9.14": "1.1.0" + "1.9.15": "1.1.0" } \ No newline at end of file