chore(link-preview): remove site-specific image fallback
This commit is contained in:
parent
f36ca9317d
commit
79baf2eab7
2 changed files with 1 additions and 22 deletions
|
|
@ -2,7 +2,6 @@ package httpgetter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -265,7 +264,7 @@ func (f *HTMLMetaFetcher) fetch(ctx context.Context, urlStr string) (*HTMLMeta,
|
|||
oEmbed, _ = f.fetchOEmbed(ctx, endpoint)
|
||||
}
|
||||
|
||||
meta := mergeMetadata(baseURL, oEmbed, sources.openGraph, sources.twitter, sources.jsonLD, sources.standard, siteImageSource(pageURL), sources.semantic)
|
||||
meta := mergeMetadata(baseURL, oEmbed, sources.openGraph, sources.twitter, sources.jsonLD, sources.standard, sources.semantic)
|
||||
return meta, nil
|
||||
}
|
||||
|
||||
|
|
@ -396,15 +395,3 @@ func cloneHTMLMeta(meta *HTMLMeta) *HTMLMeta {
|
|||
copy := *meta
|
||||
return ©
|
||||
}
|
||||
|
||||
// siteImageSource supplies deterministic site-specific thumbnails that outrank
|
||||
// the low-confidence semantic <img> fallback but lose to metadata the site
|
||||
// itself declares.
|
||||
func siteImageSource(pageURL *url.URL) metadataSource {
|
||||
if pageURL.Hostname() == "www.youtube.com" && pageURL.Path == "/watch" {
|
||||
if videoID := pageURL.Query().Get("v"); videoID != "" {
|
||||
return metadataSource{image: fmt.Sprintf("https://img.youtube.com/vi/%s/mqdefault.jpg", url.PathEscape(videoID))}
|
||||
}
|
||||
}
|
||||
return metadataSource{}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,14 +257,6 @@ func TestHTMLMetaFetcherDefaultHeadersAndDeadline(t *testing.T) {
|
|||
require.Equal(t, fetchTimeout, newHTTPClient().Timeout)
|
||||
}
|
||||
|
||||
func TestSiteImageSourceEscapesYouTubeVideoID(t *testing.T) {
|
||||
pageURL, err := url.Parse("https://www.youtube.com/watch?v=video%2Fsegment%3Fvariant")
|
||||
require.NoError(t, err)
|
||||
|
||||
source := siteImageSource(pageURL)
|
||||
require.Equal(t, "https://img.youtube.com/vi/video%2Fsegment%3Fvariant/mqdefault.jpg", source.image)
|
||||
}
|
||||
|
||||
func TestHTMLMetaFetcherResolvesAgainstFinalResponseURL(t *testing.T) {
|
||||
fetcher := newTestFetcher(roundTripFunc(func(req *http.Request) (*http.Response, error) {
|
||||
finalRequest := req.Clone(req.Context())
|
||||
|
|
|
|||
Loading…
Reference in a new issue