42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { ContentHandler } from '../content-handler'
|
|
import { parseHTML } from 'linkedom'
|
|
|
|
export class ConvertkitHandler extends ContentHandler {
|
|
constructor() {
|
|
super()
|
|
this.name = 'convertkit'
|
|
}
|
|
|
|
findNewsletterHeaderHref(dom: Document): string | undefined {
|
|
const readOnline = dom.querySelectorAll('table tr td a')
|
|
let res: string | undefined = undefined
|
|
readOnline.forEach((e) => {
|
|
if (e.textContent === 'View this email in your browser') {
|
|
res = e.getAttribute('href') || undefined
|
|
}
|
|
})
|
|
return res
|
|
}
|
|
|
|
async isNewsletter(input: {
|
|
postHeader: string
|
|
from: string
|
|
unSubHeader: string
|
|
html: string
|
|
}): Promise<boolean> {
|
|
const dom = parseHTML(input.html).document
|
|
return Promise.resolve(
|
|
dom.querySelectorAll(
|
|
'img[src*="convertkit.com"], img[src*="convertkit-mail.com"]'
|
|
).length > 0
|
|
)
|
|
}
|
|
|
|
async parseNewsletterUrl(
|
|
postHeader: string,
|
|
html: string
|
|
): Promise<string | undefined> {
|
|
return this.findNewsletterUrl(html)
|
|
}
|
|
}
|