Skip to content

Commit

Permalink
Fixed issue with certain Youtube links
Browse files Browse the repository at this point in the history
  • Loading branch information
johansan committed Dec 19, 2024
1 parent 03f3791 commit b0a047f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
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.5",
"version": "1.1.6",
"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.5",
"version": "1.1.6",
"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
19 changes: 11 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export default class FeaturedImage extends Plugin {
let codeBlockBuffer = '';

for (const line of lines) {
// First check for Auto Card Link images
const codeBlockMatch = this.codeBlockStartRegex.exec(line);
if (codeBlockMatch) {
if (!inCodeBlock) {
Expand All @@ -275,8 +276,17 @@ export default class FeaturedImage extends Plugin {
continue;
}

// Process regular lines for images and YouTube links
// Then check for YouTube links, e.g. ![Movie title](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
const match = this.combinedLineRegex.exec(line);
if (match?.groups?.youtube) {
const videoId = this.getVideoId(match.groups.youtube);
if (videoId) {
return await this.downloadThumbnail(videoId, currentFeature);
}
continue;
}

// Then check for other images (local or external)
if (match) {
// Wiki image pattern, e.g. ![[image.jpg]]
if (match.groups?.wikiImage) {
Expand All @@ -291,13 +301,6 @@ export default class FeaturedImage extends Plugin {
}
return mdImage;
}
// YouTube pattern, e.g. ![Movie title](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
if (match.groups?.youtube) {
const videoId = this.getVideoId(match.groups.youtube);
if (videoId) {
return await this.downloadThumbnail(videoId, currentFeature);
}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"1.1.2": "1.4.4",
"1.1.3": "1.4.4",
"1.1.4": "1.4.4",
"1.1.5": "1.4.4"
"1.1.5": "1.4.4",
"1.1.6": "1.4.4"
}

0 comments on commit b0a047f

Please sign in to comment.