Last active
February 8, 2026 18:38
-
-
Save joelgriffith/0e6a2a774317e845206ca8d107969550 to your computer and use it in GitHub Desktop.
Conver Toughest Sell to PDF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Create a free account at browserless.io, then run this in the BaaS debugger (it'll return a PDF) | |
| export default async ({ page }) => { | |
| const chapters = []; | |
| await page.goto('https://derekyan.com/ma-book/'); | |
| const chapterLinks = await page.evaluate(() => [...document.querySelectorAll('a.toc-item')].map(i => i.href)); | |
| for (const chapter of chapterLinks) { | |
| await page.goto(chapter); | |
| const content = await page.evaluate(() => document.querySelector('.chapter-content').innerHTML); | |
| chapters.push(content); | |
| } | |
| // Now, let's get some simple markdown CSS for print | |
| await page.goto('https://raw.githubusercontent.com/simonlc/Markdown-CSS/master/markdown.css'); | |
| const stylesheet = await page.evaluate(() => document.body.innerText); | |
| // Finally, let's inject the above in a blank page and print it. | |
| await page.goto('about:blank'); | |
| await page.setContent(chapters.join('\n')); | |
| await page.addStyleTag({ content: stylesheet }); | |
| // Return a PDF buffer to trigger the editor to download. | |
| return page.pdf(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment