From a5583b16cd6c857ade6a9eeee127d8cb2cdf392c Mon Sep 17 00:00:00 2001 From: Devon22 Date: Sun, 6 Jul 2025 22:31:31 +0800 Subject: [PATCH] 1.9.11 --- README.md | 2 +- README_ja.md | 2 +- README_zhTW.md | 1 + manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/galleryBlock.ts | 20 +++++++++++++++++++- src/imageUpload.ts | 7 +++++-- versions.json | 2 +- 9 files changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 50b72ba..d74300c 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ After creation, you can directly drag and drop images into the block to add them | pagination: `number` | Display pagination when the number of images in the Gallery exceeds this number | | alt: `text or [[link]]` | Placed on the line above the image link, can serve as a description for the image | | img: `image.jpg or ![[image.jpg]]` | Placed on the line above the note link, can be displayed as a thumbnail | - +| filter: `text` | Used to filter Gallery content | ````markdown ```gallery diff --git a/README_ja.md b/README_ja.md index 80b5891..8ac1e96 100644 --- a/README_ja.md +++ b/README_ja.md @@ -61,7 +61,7 @@ Media Viewerは、Obsidian用に設計されたプラグインで、ノート内 | pagination: `数字` | ギャラリー内の画像数がこの数を超えると、ページネーションを表示 | | alt: `テキストまたは[[リンク]]` | 画像リンクの上の行に配置し、画像の説明として機能 | | img: `image.jpg または ![[image.jpg]]` | ノートリンクの上の行に配置し、サムネイルとして表示 | - +| filter: `テキスト` | ギャラリーのコンテンツをフィルタリングするために使用 | ````markdown ```gallery diff --git a/README_zhTW.md b/README_zhTW.md index 9e6b9d9..11e8623 100644 --- a/README_zhTW.md +++ b/README_zhTW.md @@ -53,6 +53,7 @@ Media Viewer 是一個為 Obsidian 設計的插件,旨在提供一個直觀的 | pagination: `數字` | Gallery 的圖片大於幾張時以分頁顯示 | | alt: `文字 or [[連結]]` | 放在圖片連結的上一行,可作為圖片的說明 | | img: `image.jpg or ![[image.jpg]]` | 放在筆記連結的上一行,可顯示為縮圖 | +| filter: `文字` | 用於過濾 Gallery 的內容 | ````markdown ```gallery diff --git a/manifest.json b/manifest.json index dba4ebb..3f88ac3 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "mediaviewer", "name": "Media Viewer", - "version": "1.9.10", + "version": "1.9.11", "minAppVersion": "1.1.0", "description": "View and manage media files within your notes.", "author": "Devon22", diff --git a/package-lock.json b/package-lock.json index cd2529c..ecac842 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mediaviewer", - "version": "1.9.10", + "version": "1.9.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mediaviewer", - "version": "1.9.10", + "version": "1.9.11", "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", diff --git a/package.json b/package.json index a2ccf46..6414c49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mediaviewer", - "version": "1.9.10", + "version": "1.9.11", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/galleryBlock.ts b/src/galleryBlock.ts index 5d2db25..8b9a539 100644 --- a/src/galleryBlock.ts +++ b/src/galleryBlock.ts @@ -75,6 +75,7 @@ export class GalleryBlock { let addButtonEnabled = false; let gridSize = this.plugin.settings.galleryGridSize || 'medium'; let paginationEnabled = this.plugin.settings.itemsPerPage || 0; // 設定變數以決定是否開啟分頁功能 + let filterKeyword: string | null = null; // 新增搜尋關鍵字 // 產生基於內容的唯一識別碼 const galleryId = 'gallery-' + this.hashString(content.trim()); @@ -152,6 +153,16 @@ export class GalleryBlock { continue; } + // 新增 filter 參數的處理 + const filterMatch = trimmedLine.match(/^filter:\s*(.*?)\s*$/i); + if (filterMatch) { + const keyword = filterMatch[1].trim().toLowerCase(); + if (keyword && keyword !== 'null' && keyword !== 'undefined') { + filterKeyword = keyword; + } + continue; + } + // 新增 size 參數的處理 const sizeMatch = trimmedLine.match(/^size:\s*(small|medium|large)$/i); if (sizeMatch) { @@ -360,8 +371,15 @@ export class GalleryBlock { } } + const shouldFilter = !!filterKeyword && filterKeyword.trim() !== ''; + const finalItems = shouldFilter ? items.filter(item => { + const titleText = typeof item.title === 'string' ? item.title : (item.title ? (item.title as any).text : ''); + const textToFilter = (titleText || '') + (item.path || '') + (item.url || ''); + return textToFilter.toLowerCase().includes(filterKeyword!); + }) : items; + return { - items, + items: finalItems, containerInfo: { title: containerTitle, addButtonEnabled: addButtonEnabled, diff --git a/src/imageUpload.ts b/src/imageUpload.ts index cbf1ba1..7da7e55 100644 --- a/src/imageUpload.ts +++ b/src/imageUpload.ts @@ -225,8 +225,11 @@ export class ImageUploadModal extends Modal { // 處理一般檔案 if (file instanceof File) { - // 檢查是否為支援的媒體類型 - if (file.type.startsWith('image/') || file.type.startsWith('video/') || file.type.startsWith('audio/')) { + // 檢查是否為支援的媒體類型(MIME)或副檔名 + const lowerName = file.name.toLowerCase(); + const isSupportedExt = /\.(jpg|jpeg|png|gif|webp|mp4|mov|webm|mp3|m4a|flac|ogg|wav|3gp)$/i.test(lowerName); + const isSupportedMime = file.type && (file.type.startsWith('image/') || file.type.startsWith('video/') || file.type.startsWith('audio/')); + if (isSupportedMime || isSupportedExt) { // 取得附件資料夾路徑 const attachmentFolderPath = this.getAttachmentFolderPath(activeFile); diff --git a/versions.json b/versions.json index 99c8c4b..674c018 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.9.10": "1.1.0" + "1.9.11": "1.1.0" } \ No newline at end of file