From 37439c662276a213025f5f63f77333a79212c71c Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Mon, 17 Oct 2022 17:59:27 +0800 Subject: [PATCH] Save fs.blog newsletter correctly --- .../src/newsletters/convertkit-handler.ts | 9 +- .../test/data/convertkit-newsletter.html | 1292 +++++++++++++++++ .../content-handler/test/newsletter.test.ts | 36 + 3 files changed, 1334 insertions(+), 3 deletions(-) create mode 100644 packages/content-handler/test/data/convertkit-newsletter.html diff --git a/packages/content-handler/src/newsletters/convertkit-handler.ts b/packages/content-handler/src/newsletters/convertkit-handler.ts index 72e65f5da..a77951178 100644 --- a/packages/content-handler/src/newsletters/convertkit-handler.ts +++ b/packages/content-handler/src/newsletters/convertkit-handler.ts @@ -8,10 +8,13 @@ export class ConvertkitHandler extends ContentHandler { } findNewsletterHeaderHref(dom: Document): string | undefined { - const readOnline = dom.querySelectorAll('table tr td a') + const readOnline = dom.querySelectorAll('a') let res: string | undefined = undefined readOnline.forEach((e) => { - if (e.textContent === 'View this email in your browser') { + if ( + e.textContent === 'View this email in your browser' || + e.textContent === 'Read on FS' + ) { res = e.getAttribute('href') || undefined } }) @@ -27,7 +30,7 @@ export class ConvertkitHandler extends ContentHandler { const dom = parseHTML(input.html).document return Promise.resolve( dom.querySelectorAll( - 'img[src*="convertkit.com"], img[src*="convertkit-mail.com"]' + 'img[src*="convertkit.com"], img[src*="convertkit-mail"]' ).length > 0 ) } diff --git a/packages/content-handler/test/data/convertkit-newsletter.html b/packages/content-handler/test/data/convertkit-newsletter.html new file mode 100644 index 000000000..ab2131adb --- /dev/null +++ b/packages/content-handler/test/data/convertkit-newsletter.html @@ -0,0 +1,1292 @@ + + + + + + +
+ + There are a lot of things in life that only work when you commit. + + + +  ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ + +
+ +
+

+ FS | BRAIN FOOD +

+
+ + + +
+

+ No. 494 — October 16th, 2022 — Read on FS +

+

+ Brain Food is a weekly newsletter with the insights you need.
+

+

+ FS +

+

+ One of the biggest things that hold people back they're not aware + of: +

+

+ When we want to improve our value to an organization, we gravitate + toward the skills we need to develop, working extra hours or increasing + our responsibilities. We miss the secret hiding in plain sight: reducing + friction. +

+

+ — + Source +

+

+ TKP +

+

+ Marshall Goldsmith on self-limiting beliefs: +

+

+ "I think we have a lot of self-limiting beliefs. And the self-limiting + beliefs, a lot of these come from inside us. Basically, I can’t do this. + I can’t do that. This is just the way I am. One of the most common + problems is, this is just the way I am as if we have some “real” fixed + identity that lives throughout time. And I have to really work on people + to change that. Even smart people say things like this, “I can’t listen. + I can’t listen. I’ve never been able to listen.” I’ll look in their + ears. “Why not? You got something stuck in there? Why can’t you listen? + Do you have an incurable genetic defect that is prohibiting you from + listening?” As long as we tell ourselves, “That’s the way I am.” Two + things happen, both bad. One, we inhibit the odds of ever getting + better. Two, even if we do change our behavior we don’t seem authentic + to ourselves. We feel like a phony because if the real me can’t listen + and you say, “I’m a good listener. You know what I’m thinking?” Well, + that’s not the real me. I’m just pretending to be a good listener + because the real me is no good at that.” +

+

+ — + Listen and Learn + or + read the transcript. +

+

+ Insight +

+

+ Jeff Bezos on wandering as a counter-balance to efficiency: +

+

+ "Sometimes (often actually) in business, you do know where you’re going, + and when you do, you can be efficient. Put in place a plan and execute. + In contrast, wandering in business is not efficient … but it’s also not + random. It’s guided – by hunch, gut, intuition, curiosity, and powered + by a deep conviction that the prize for customers is big enough that + it’s worth being a little messy and tangential to find our way there. + Wandering is an essential counterbalance to efficiency. You need to + employ both. The outsized discoveries – the “non-linear” ones – are + highly likely to require wandering." +

+

+ — + Source +

+

+ Tiny Thought +

+

+ There are a lot of things in life that only work when you commit. +

+

+ I don’t mean dabble. I don’t mean half-in. I mean commit. +

+

+ Commitment means all in, all the time. +

+

+ It’s easy to trick yourself into thinking that if you put in half the + effort, you can get 80 percent of the results. While that might work for + some things, it doesn’t work for anything important. +

+

+ If you’re half trustworthy, you’re not trustworthy. +

+

+ If you’re often reliable, you’re not reliable. +

+

+ If you’re mostly consistent, you’re not consistent. +

+

+ The key to doing anything well is commitment. Not only does commitment + help you become better at what you do, but it also makes other people + want to help you. +

+

+ If you see your job as punching the clock, not only will you never be + great at it, but your employer won’t invest in you. The best + relationships are the ones where both partners go all in all the time to + make the relationship amazing. +

+

+ If committing sounds like a lot of work, it is. That’s why so many + people are half-in. The problem with half-in and half-committed is that + it doesn’t get you the results you want. If you're not committed, get + out. +

+

+ The committed person gets both the opportunity and the results. +

+

+ All in, all the time. +

+

+ (Share this Tiny Thought on Twitter)
+

+

+ Etc. +

+

+ Rafal Nadal on why hard is good: +

+

+ "One lesson I’ve learned is that if the job I do were easy, I wouldn’t + derive so much satisfaction from it. The thrill of winning is in direct + proportion to the effort I put in before. I also know, from long + experience, that if you make an effort in training when you don’t + especially feel like making it, the payoff is that you will win games + when you are not feeling your best. That is how you win championships, + that is what separates the great player from the merely good player. The + difference lies in how well you’ve prepared." +

+

+ — + Source +

+

+ Fatal flaws that everyone sees: +

+

+ "Everyone knew, deep-down, that middle-school geometry doomed the + design, but everyone also fervently believed that it could somehow be + overcome by sheer will, or hard work, or a stroke of genius. The theme + here is that the cultures that arise around products, methods, and + inventions often grow to exclude discussion of their fatal flaws, and + instead find elaborate ways to paper over them -- to find more and more + clever ways to pretend they don't exist." +

+

+ — + Source +

+

+
+

+ + + + + + +
+ Sponsored by Royce Investment Partners +
+

+ +

+

+ +

+

+ The Royce Funds. + Small-cap specialists. + +

+

+

+ Cheers,
— Shane +

+

+ P.S. Brilliant (and surprising) + design. +

+

+ P.P.S. “Most successful people are just an anxiety disorder + harnessed for productivity.” +

+

+
+

+ Free Version +

+

+ You're getting the Free version. Not only do members support our free + content, but they also get access to a community, hand-edited + transcripts, ad-free everything, and early access. +

+

+ See What You're Missing +

+
+

+

+ +

+ +

+
+

+

+
+

+

+
+

+

+
+

+

+
+

+

+
+

+ + + + + + + +
+ + + diff --git a/packages/content-handler/test/newsletter.test.ts b/packages/content-handler/test/newsletter.test.ts index 46e3eb3d4..4a9524498 100644 --- a/packages/content-handler/test/newsletter.test.ts +++ b/packages/content-handler/test/newsletter.test.ts @@ -12,6 +12,7 @@ import nock from 'nock' import { generateUniqueUrl } from '../src/content-handler' import fs from 'fs' import { BeehiivHandler } from '../src/newsletters/beehiiv-handler' +import { ConvertkitHandler } from '../src/newsletters/convertkit-handler' chai.use(chaiAsPromised) chai.use(chaiString) @@ -147,6 +148,17 @@ describe('Newsletter email test', () => { }) ).to.eventually.be.true }) + it('returns true for convertkit newsletter', async () => { + const html = load('./test/data/convertkit-newsletter.html') + await expect( + new ConvertkitHandler().isNewsletter({ + html, + postHeader: '', + from: '', + unSubHeader: '', + }) + ).to.eventually.be.true + }) }) describe('findNewsletterUrl', async () => { @@ -203,6 +215,30 @@ describe('Newsletter email test', () => { }).timeout(10000) }) + context('when email is from convertkit', () => { + before(() => { + nock('https://u25184427.ct.sendgrid.net') + .head( + '/ls/click?upn=MnmHBiCwIPe9TmIJeskmA7wDTJvdVU1ACmSJ753YuhScf71JWthxqM8RnVh-2FZG0rYzrbR04P99S2ld2OkTtQmrx2FDwArpYdk5N0jVpN9dLBZ-2BdPNqkRHxNvuygY8-2F-2FtRNFoPjxjtTuyWM6L3tcYDYnAnL2xCueddWcFlUNrQWsvLotmgvC-2BrQc7bxsZhW0pUBmS_vVXscVLXlj5UtQe3aqo5RMTdTq2PepdZjP86UOmA8nzSBnnaDN-2FNHWDodWnbUOPZ063v3w3z8QtcaPpE1qNu8xYkNJJFb-2F1uZEG-2BzsLfyDkjvvVX5zYs5OyyRYlhMOlXDJcr4-2FtMrFwii0uFAvwbhxDdnTxEpi-2F7maufyH39AEO-2BtCeSUg5V4FM43UpI1zUSXeWK-2Fh5JumSmR5XhrrRAig-3D-3D' + ) + .reply(302, undefined, { + Location: 'https://fs.blog/brain-food/october-16-2022/', + }) + .get('/brain-food/october-16-2022/') + .reply(200, '') + }) + + after(() => { + nock.restore() + }) + + it('gets the URL from the header', async () => { + const html = load('./test/data/convertkit-newsletter.html') + const url = await new ConvertkitHandler().findNewsletterUrl(html) + expect(url).to.startWith('https://fs.blog/brain-food/october-16-2022/') + }).timeout(10000) + }) + it('returns undefined if it is not a newsletter', async () => { const html = load('./test/data/substack-forwarded-welcome-email.html') const url = await new SubstackHandler().findNewsletterUrl(html)