* change return value for new version of pubsub

* add support for the other bloomberg newsletters not only business

* add default fallback url if newsletter url not found

* revert pubsub version change
This commit is contained in:
Hongbo Wu
2022-02-23 11:17:59 +08:00
committed by GitHub
parent 2645566e18
commit 610c9c6348
6 changed files with 32 additions and 14 deletions

View File

@ -1,10 +1,18 @@
import { NewsletterHandler } from './newsletter'
import addressparser from 'addressparser'
export class SubstackHandler extends NewsletterHandler {
constructor() {
super()
this.defaultUrl = 'https://www.substack.com/'
}
getNewsletterUrl(rawUrl: string, _html: string): string | undefined {
// raw SubStack newsletter url is like <https://hongbo130.substack.com/p/tldr>
// we need to get the real url
return rawUrl.slice(1, -1)
// we need to get the real url from the raw url
return addressparser(rawUrl).length > 0
? addressparser(rawUrl)[0].name
: undefined
}
isNewsletter(rawUrl: string, _from: string): boolean {