mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add support for bloomberg newsletters
This commit is contained in:
parent
89ae114820
commit
bd8178a464
3 changed files with 46 additions and 3 deletions
28
packages/api/src/utils/bloomberg-handler.ts
Normal file
28
packages/api/src/utils/bloomberg-handler.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { DOMWindow } from 'jsdom'
|
||||
|
||||
export class SubstackHandler {
|
||||
name = 'bloomberg'
|
||||
|
||||
shouldPrehandle = (url: URL, dom: DOMWindow): boolean => {
|
||||
const host = this.name + '.com'
|
||||
// check if url ends with bloomberg.com
|
||||
return url.hostname.endsWith(host)
|
||||
}
|
||||
|
||||
prehandle = (url: URL, dom: DOMWindow): Promise<DOMWindow> => {
|
||||
const body = dom.document.querySelector('.wrapper')
|
||||
|
||||
// this removes header
|
||||
body?.querySelector('.sailthru-variables')?.remove()
|
||||
body?.querySelector('.preview-text')?.remove()
|
||||
body?.querySelector('.logo-wrapper')?.remove()
|
||||
body?.querySelector('.by-the-number-wrapper')?.remove()
|
||||
// this removes footer
|
||||
body?.querySelector('.quote-box-wrapper')?.remove()
|
||||
body?.querySelector('.header-wrapper')?.remove()
|
||||
body?.querySelector('.component-wrapper')?.remove()
|
||||
body?.querySelector('.footer')?.remove()
|
||||
|
||||
return Promise.resolve(dom)
|
||||
}
|
||||
}
|
||||
|
|
@ -6,9 +6,11 @@ const EMAIL_CONFIRMATION_CODE_RECEIVED_TOPIC = 'emailConfirmationCodeReceived'
|
|||
const EMAIL_FORWARDING_SENDER_ADDRESSES = [
|
||||
'Gmail Team <forwarding-noreply@google.com>',
|
||||
]
|
||||
const NEWSLETTER_SENDER_REGEX = '<.+@axios.com>'
|
||||
const NEWSLETTER_SENDER_REGEX =
|
||||
'<.+@((axios.com)|(mail.bloombergbusiness.com))>'
|
||||
const CONFIRMATION_CODE_PATTERN = '^\\(#\\d+\\)'
|
||||
const AXIOS_URL_PATTERN = 'View in browser at <.+>'
|
||||
const BLOOMBERG_URL_PATTERN = '<a class="view-in-browser__url".+>'
|
||||
|
||||
export const handleConfirmation = async (email: string, subject: string) => {
|
||||
console.log('confirmation email')
|
||||
|
|
@ -114,11 +116,19 @@ export const getNewsletterUrl = (
|
|||
}
|
||||
|
||||
// axios newsletter url from html
|
||||
const re = new RegExp(AXIOS_URL_PATTERN)
|
||||
const matches = html.match(re)
|
||||
let re = new RegExp(AXIOS_URL_PATTERN)
|
||||
let matches = html.match(re)
|
||||
if (matches) {
|
||||
const match = matches[0]
|
||||
return match.slice(match.indexOf('>') + 1, match.lastIndexOf('<'))
|
||||
}
|
||||
|
||||
// bloomberg newsletter url from html
|
||||
re = new RegExp(BLOOMBERG_URL_PATTERN)
|
||||
matches = html.match(re)
|
||||
if (matches) {
|
||||
const match = matches[0]
|
||||
return match.slice(match.indexOf('href=') + 1, match.lastIndexOf('style'))
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,11 @@ describe('Newsletter email test', () => {
|
|||
|
||||
expect(isNewsletter('', from)).to.be.true
|
||||
})
|
||||
|
||||
it('should return true when email is from bloomberg', () => {
|
||||
const from = 'From: Bloomberg <noreply@mail.bloombergbusiness.com>'
|
||||
expect(isNewsletter('', from)).to.be.true
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getNewsletterUrl()', () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue