Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
964ae168
Unverified
Commit
964ae168
authored
Feb 22, 2025
by
MHZ
Committed by
GitHub
Feb 22, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support YouTube video thumbnail in link preview (#4427)
parent
f17774cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
html_meta.go
plugin/httpgetter/html_meta.go
+13
-0
Link.tsx
web/src/components/MemoContent/Link.tsx
+3
-0
No files found.
plugin/httpgetter/html_meta.go
View file @
964ae168
package
httpgetter
import
(
"fmt"
"io"
"net"
"net/http"
...
...
@@ -53,6 +54,7 @@ func GetHTMLMeta(urlStr string) (*HTMLMeta, error) {
// TODO: limit the size of the response body
htmlMeta
:=
extractHTMLMeta
(
response
.
Body
)
enrichSiteMeta
(
response
.
Request
.
URL
,
htmlMeta
)
return
htmlMeta
,
nil
}
...
...
@@ -151,3 +153,14 @@ func validateURL(urlStr string) error {
return
nil
}
func
enrichSiteMeta
(
url
*
url
.
URL
,
meta
*
HTMLMeta
)
{
if
url
.
Hostname
()
==
"www.youtube.com"
{
if
url
.
Path
==
"/watch"
{
vid
:=
url
.
Query
()
.
Get
(
"v"
)
if
vid
!=
""
{
meta
.
Image
=
fmt
.
Sprintf
(
"https://img.youtube.com/vi/%s/mqdefault.jpg"
,
vid
)
}
}
}
}
web/src/components/MemoContent/Link.tsx
View file @
964ae168
...
...
@@ -54,6 +54,9 @@ const Link: React.FC<Props> = ({ text, url }: Props) => {
{
linkMetadata
.
description
&&
(
<
p
className=
"mt-1 w-full text-sm leading-snug opacity-80 line-clamp-3"
>
{
linkMetadata
.
description
}
</
p
>
)
}
{
linkMetadata
.
image
&&
(
<
img
className=
"mt-1 w-full h-32 object-cover rounded"
src=
{
linkMetadata
.
image
}
alt=
{
linkMetadata
.
title
}
/>
)
}
</
div
>
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment