Skip to content

Commit 964ae16

Browse files
authored
feat: support YouTube video thumbnail in link preview (#4427)
1 parent f17774c commit 964ae16

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

plugin/httpgetter/html_meta.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package httpgetter
22

33
import (
4+
"fmt"
45
"io"
56
"net"
67
"net/http"
@@ -53,6 +54,7 @@ func GetHTMLMeta(urlStr string) (*HTMLMeta, error) {
5354
// TODO: limit the size of the response body
5455

5556
htmlMeta := extractHTMLMeta(response.Body)
57+
enrichSiteMeta(response.Request.URL, htmlMeta)
5658
return htmlMeta, nil
5759
}
5860

@@ -151,3 +153,14 @@ func validateURL(urlStr string) error {
151153

152154
return nil
153155
}
156+
157+
func enrichSiteMeta(url *url.URL, meta *HTMLMeta) {
158+
if url.Hostname() == "www.youtube.com" {
159+
if url.Path == "/watch" {
160+
vid := url.Query().Get("v")
161+
if vid != "" {
162+
meta.Image = fmt.Sprintf("https://img.youtube.com/vi/%s/mqdefault.jpg", vid)
163+
}
164+
}
165+
}
166+
}

web/src/components/MemoContent/Link.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ const Link: React.FC<Props> = ({ text, url }: Props) => {
5454
{linkMetadata.description && (
5555
<p className="mt-1 w-full text-sm leading-snug opacity-80 line-clamp-3">{linkMetadata.description}</p>
5656
)}
57+
{linkMetadata.image && (
58+
<img className="mt-1 w-full h-32 object-cover rounded" src={linkMetadata.image} alt={linkMetadata.title} />
59+
)}
5760
</div>
5861
)
5962
}

0 commit comments

Comments
 (0)