This commit is contained in:
Devon22 2025-04-19 01:03:17 +08:00
parent 89f1f311c3
commit 68db1e71fc
6 changed files with 36 additions and 9 deletions

View file

@ -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",

4
package-lock.json generated
View file

@ -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",

View file

@ -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": {

View file

@ -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';

View file

@ -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<TFile[]> {
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<TFile[]> {
}
}
// 讀取目前筆記內容,找出所有媒體連結
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') {
// 書籤模式

View file

@ -1,3 +1,3 @@
{
"1.9.14": "1.1.0"
"1.9.15": "1.1.0"
}