Skip to content

Commit

Permalink
Keep empty property
Browse files Browse the repository at this point in the history
  • Loading branch information
johansan committed Dec 11, 2024
1 parent aff2d93 commit 7c35e9a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,38 @@ 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:
- `youtube/` for YouTube thumbnails
- `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)

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
});

Expand Down
15 changes: 15 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface FeaturedImageSettings {
excludedFolders: string[];
frontmatterProperty: string;
onlyUpdateExisting: boolean;
keepEmptyProperty: boolean;
useMediaLinks: boolean;

// YouTube settings
Expand All @@ -19,6 +20,7 @@ export interface FeaturedImageSettings {
// Developer options
debugMode: boolean;
dryRun: boolean;

}

export const DEFAULT_SETTINGS: FeaturedImageSettings = {
Expand All @@ -28,6 +30,7 @@ export const DEFAULT_SETTINGS: FeaturedImageSettings = {
// Frontmatter settings
frontmatterProperty: 'feature',
onlyUpdateExisting: false,
keepEmptyProperty: false,
useMediaLinks: false,

// YouTube settings
Expand Down Expand Up @@ -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.')
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 7c35e9a

Please sign in to comment.