This commit is contained in:
Devon22 2025-07-06 22:31:31 +08:00
parent 0ae4237117
commit a5583b16cd
9 changed files with 32 additions and 10 deletions

View file

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

View file

@ -61,7 +61,7 @@ Media Viewerは、Obsidian用に設計されたプラグインで、ート内
| pagination: `数字` | ギャラリー内の画像数がこの数を超えると、ページネーションを表示 |
| alt: `テキストまたは[[リンク]]` | 画像リンクの上の行に配置し、画像の説明として機能 |
| img: `image.jpg または ![[image.jpg]]` | ノートリンクの上の行に配置し、サムネイルとして表示 |
| filter: `テキスト` | ギャラリーのコンテンツをフィルタリングするために使用 |
````markdown
```gallery

View file

@ -53,6 +53,7 @@ Media Viewer 是一個為 Obsidian 設計的插件,旨在提供一個直觀的
| pagination: `數字` | Gallery 的圖片大於幾張時以分頁顯示 |
| alt: `文字 or [[連結]]` | 放在圖片連結的上一行,可作為圖片的說明 |
| img: `image.jpg or ![[image.jpg]]` | 放在筆記連結的上一行,可顯示為縮圖 |
| filter: `文字` | 用於過濾 Gallery 的內容 |
````markdown
```gallery

View file

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

4
package-lock.json generated
View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,3 @@
{
"1.9.10": "1.1.0"
"1.9.11": "1.1.0"
}