diff --git a/README.md b/README.md index c89160d..ac7d5c0 100644 --- a/README.md +++ b/README.md @@ -128,22 +128,27 @@ Featured Image offers several customizable settings to tailor the plugin to your - Description: When enabled, the plugin will only update notes that already have a featured image property. - Usage: Enable this if you want to manually control which notes have featured images. -5. **Use Media Links** +5. **Keep Empty Property** + - Default: `false` + - Description: When enabled, the frontmatter property will be kept but set to an empty string if no featured image is found. + - Usage: Enable this if you want to preserve the frontmatter property even when there's no featured image. + +6. **Use Media Links** - Default: `false` - Description: When enabled, the plugin will store the featured image as a media link in the frontmatter property (e.g. `![[path/to/image.png]]`). - Usage: Enable this if you want to use the media link format for featured images. -6. **Require Exclamation Mark for YouTube Thumbnails** +7. **Require Exclamation Mark for YouTube Thumbnails** - Default: `true` - Description: When enabled, YouTube links must be prefixed with `!` to be considered for featured images. - Usage: Keep this enabled if you want more control over which YouTube links become featured images. -7. **Download WebP** +8. **Download WebP** - Default: `true` - Description: When enabled, the plugin will attempt to download WebP format thumbnails for YouTube videos. - Usage: Disable this if you prefer JPG thumbnails or if you're experiencing issues with WebP images. -8. **Thumbnail Download Folder** +9. **Thumbnail Download Folder** - Default: `thumbnails` - Description: The folder where external images, YouTube thumbnails, and Auto Card Link images will be downloaded and stored. - Usage: Set this to your preferred location for storing downloaded images. The plugin will automatically create subfolders: @@ -151,10 +156,10 @@ Featured Image offers several customizable settings to tailor the plugin to your - `external/` for external images - `autocardlink/` for Auto Card Link external images -9. **Image Extensions** - - Default: `["png", "jpg", "jpeg", "gif", "webp"]` - - Description: List of image file extensions to consider when searching for featured images. - - Usage: Add or remove extensions based on the image types you use in your vault. +10. **Image Extensions** + - Default: `["png", "jpg", "jpeg", "gif", "webp"]` + - Description: List of image file extensions to consider when searching for featured images. + - Usage: Add or remove extensions based on the image types you use in your vault. ![Settings](images/settings.png) diff --git a/manifest.json b/manifest.json index bb053b2..0f274a8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "featured-image", "name": "Featured Image", - "version": "1.1.3", + "version": "1.1.4", "minAppVersion": "1.4.4", "description": "Automatically sets a featured image property in your notes based on the first image, YouTube link, or Auto Card Link image found in your document.", "author": "Johan Sanneblad", diff --git a/package.json b/package.json index d7e76d6..a3bd665 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-featured-image", - "version": "1.1.3", + "version": "1.1.4", "description": "Automatically sets a featured image property in your notes based on the first image, YouTube link, or Auto Card Link image found in your document.", "main": "main.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index b28d107..3497435 100644 --- a/src/main.ts +++ b/src/main.ts @@ -503,7 +503,11 @@ export default class FeaturedImage extends Plugin { const featureValue = this.settings.useMediaLinks ? `![[${newFeature}]]` : newFeature; frontmatter[this.settings.frontmatterProperty] = featureValue; } else { - delete frontmatter[this.settings.frontmatterProperty]; + if (this.settings.keepEmptyProperty) { + frontmatter[this.settings.frontmatterProperty] = ''; + } else { + delete frontmatter[this.settings.frontmatterProperty]; + } } }); diff --git a/src/settings.ts b/src/settings.ts index a838fdd..7b85688 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -6,6 +6,7 @@ export interface FeaturedImageSettings { excludedFolders: string[]; frontmatterProperty: string; onlyUpdateExisting: boolean; + keepEmptyProperty: boolean; useMediaLinks: boolean; // YouTube settings @@ -19,6 +20,7 @@ export interface FeaturedImageSettings { // Developer options debugMode: boolean; dryRun: boolean; + } export const DEFAULT_SETTINGS: FeaturedImageSettings = { @@ -28,6 +30,7 @@ export const DEFAULT_SETTINGS: FeaturedImageSettings = { // Frontmatter settings frontmatterProperty: 'feature', onlyUpdateExisting: false, + keepEmptyProperty: false, useMediaLinks: false, // YouTube settings @@ -108,6 +111,18 @@ export class FeaturedImageSettingsTab extends PluginSettingTab { }) }) + // Keep empty property + new Setting(containerEl) + .setName('Keep empty property') + .setDesc('When enabled, the frontmatter property will be kept but set to an empty string if no featured image is found. When disabled, the property will be removed.') + .addToggle(toggle => { toggle + .setValue(this.plugin.settings.keepEmptyProperty) + .onChange(async value => { + this.plugin.settings.keepEmptyProperty = value + await this.plugin.saveSettings() + }) + }) + new Setting(containerEl) .setName('Use media links') .setDesc('Use Obsidian media links (e.g. ![[image.png]]) instead of plain text (e.g. image.png) for the featured image property.') diff --git a/versions.json b/versions.json index 59b4d96..d2bd57d 100644 --- a/versions.json +++ b/versions.json @@ -10,5 +10,6 @@ "1.1.0": "1.4.4", "1.1.1": "1.4.4", "1.1.2": "1.4.4", - "1.1.3": "1.4.4" + "1.1.3": "1.4.4", + "1.1.4": "1.4.4" }