This commit is contained in:
Jackson Harper
2022-03-02 23:14:10 -08:00
parent 65ce8353dc
commit 484cd78ac5
2 changed files with 8 additions and 4 deletions

View File

@ -57,7 +57,9 @@ export function emailsServiceRouter() {
title: data.subject,
content: data.html,
author: data.from,
url: (await findNewsletterUrl(data.html)) || 'https://omnivore.app/no_url',
url:
(await findNewsletterUrl(data.html)) ||
'https://omnivore.app/no_url',
})
res.status(200).send('Newsletter')
return

View File

@ -402,7 +402,9 @@ export const isProbablyNewsletter = (html: string): boolean => {
// Given an HTML blob tries to find a URL to use for
// a canonical URL.
export const findNewsletterUrl = async (html: string): Promise<string | undefined> => {
export const findNewsletterUrl = async (
html: string
): Promise<string | undefined> => {
const dom = new JSDOM(html).window
// If there is an <h1 element with a URL, use that
@ -416,8 +418,8 @@ export const findNewsletterUrl = async (html: string): Promise<string | undefine
method: 'HEAD',
url: href,
})
.then(res => res.request.res.responseUrl)
.catch((e) => href)
.then((res) => res.request.res.responseUrl as string | undefined)
.catch((e) => href)
}
}