mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
commit
54032bdc97
6 changed files with 28 additions and 7 deletions
|
|
@ -54,6 +54,7 @@ import { ContentParseError } from '../../utils/errors'
|
|||
import {
|
||||
authorized,
|
||||
generateSlug,
|
||||
isBase64Image,
|
||||
isParsingTimeout,
|
||||
pageError,
|
||||
stringToHash,
|
||||
|
|
@ -889,6 +890,10 @@ export const searchResolver = authorized<
|
|||
}
|
||||
|
||||
const edges = results.map((r) => {
|
||||
let siteIcon = r.siteIcon
|
||||
if (siteIcon && !isBase64Image(siteIcon)) {
|
||||
siteIcon = createImageProxyUrl(siteIcon, 128, 128)
|
||||
}
|
||||
return {
|
||||
node: {
|
||||
...r,
|
||||
|
|
@ -900,7 +905,7 @@ export const searchResolver = authorized<
|
|||
publishedAt: validatedDate(r.publishedAt),
|
||||
ownedByViewer: r.userId === claims.uid,
|
||||
pageType: r.pageType || PageType.Highlights,
|
||||
siteIcon: r.siteIcon && createImageProxyUrl(r.siteIcon, 32, 32),
|
||||
siteIcon,
|
||||
} as SearchItem,
|
||||
cursor: endCursor,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ export const subscriptionsResolver = authorized<
|
|||
return {
|
||||
subscriptions: subscriptions.map((s) => ({
|
||||
...s,
|
||||
icon: s.icon && createImageProxyUrl(s.icon, 32, 32),
|
||||
icon: s.icon && createImageProxyUrl(s.icon, 128, 128),
|
||||
})),
|
||||
}
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import { saveSubscription } from './subscriptions'
|
|||
import { NewsletterEmail } from '../entity/newsletter_email'
|
||||
import { fetchFavicon } from '../utils/parser'
|
||||
import { updatePage } from '../elastic/pages'
|
||||
import { isBase64Image } from '../utils/helpers'
|
||||
|
||||
interface NewsletterMessage {
|
||||
email: string
|
||||
|
|
@ -69,8 +70,8 @@ export const saveNewsletterEmail = async (
|
|||
return false
|
||||
}
|
||||
|
||||
if (!page.siteIcon) {
|
||||
// fetch favicon if not already set
|
||||
if (!page.siteIcon || isBase64Image(page.siteIcon)) {
|
||||
// fetch favicon if not already set or is a base64 image
|
||||
const favicon = await fetchFavicon(page.url)
|
||||
if (favicon) {
|
||||
page.siteIcon = favicon
|
||||
|
|
|
|||
|
|
@ -269,3 +269,7 @@ export const wordsCount = (text: string, isHtml = true): number => {
|
|||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
export const isBase64Image = (str: string): boolean => {
|
||||
return str.startsWith('data:image/')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -442,7 +442,7 @@ export const fetchFavicon = async (
|
|||
const response = await axios.head(url, { timeout: 5000 })
|
||||
const realUrl = response.request.res.responseUrl
|
||||
const domain = new URL(realUrl).hostname
|
||||
return `https://api.faviconkit.com/${domain}/32`
|
||||
return `https://api.faviconkit.com/${domain}/128`
|
||||
} catch (e) {
|
||||
console.log('Error fetching favicon', e)
|
||||
return undefined
|
||||
|
|
|
|||
|
|
@ -1909,10 +1909,21 @@ Readability.prototype = {
|
|||
values["og:site_name"] || null;
|
||||
|
||||
// get website icon
|
||||
const iconLink = this._doc.querySelector(
|
||||
const siteIcon = this._doc.querySelector(
|
||||
"link[rel='apple-touch-icon'], link[rel='shortcut icon'], link[rel='icon']"
|
||||
);
|
||||
metadata.siteIcon = iconLink?.href;
|
||||
if (siteIcon) {
|
||||
const iconHref = siteIcon.getAttribute("href");
|
||||
if (iconHref) {
|
||||
if (this.REGEXPS.b64DataUrl.test(iconHref)) {
|
||||
// base64 encoded image
|
||||
metadata.siteIcon = iconHref;
|
||||
} else {
|
||||
// allow relative URLs
|
||||
metadata.siteIcon = this.toAbsoluteURI(iconHref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get published date
|
||||
metadata.publishedDate = jsonld.publishedDate ||
|
||||
|
|
|
|||
Loading…
Reference in a new issue