-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PDF generation feature #29
Conversation
Fixes #19 Add feature to save Medium articles as PDFs. * **Backend Changes:** - Add a new endpoint `generate_pdf` in `web/server/handlers/post.py` to handle PDF generation requests. - Import `WeasyPrint` for rendering HTML to PDF. - Update the `render_medium_post_link` function to support PDF generation. * **Template Changes:** - Ensure compatibility with PDF rendering by adjusting styles in `web/server/templates/post.html`. - Add a hidden div with the article content for PDF generation. * **Frontend Changes:** - Add a "Save as PDF" button in `new-web/src/routes/[slug]/+page.svelte` to trigger the PDF generation. - Implement a function to call the new PDF generation endpoint. * **Documentation:** - Update `README.md` to include instructions for the new PDF generation feature. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Freedium-cfd/web/issues/19?shareId=XXXX-XXXX-XXXX-XXXX).
Hey. Thanks for the PR. |
from html5lib import serialize | ||
from html5lib.html5parser import parse | ||
from async_lru import alru_cache | ||
from loguru import logger | ||
from medium_parser import medium_parser_exceptions | ||
from weasyprint import HTML |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add weasyprint as a dependency
@@ -114,3 +114,10 @@ <h1 class="font-bold font-sans break-normal text-gray-900 dark:text-gray-100 pt- | |||
cursor: pointer; | |||
} | |||
</style> | |||
<div id="pdf-content" style="display: none;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't understand what is this
return HTMLResponse(serialized_rendered_post) | ||
|
||
|
||
async def generate_pdf(path: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see endpoint registration
@@ -68,6 +68,19 @@ Stay tuned for more exciting updates as we continue to revolutionize the world o | |||
contentLoaded = true; | |||
}, 500); | |||
}); | |||
|
|||
async function saveAsPDF() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nahhh, this should be definetly refactored
Closed with no response. |
Fixes #19
Add feature to save Medium articles as PDFs.
Backend Changes:
generate_pdf
inweb/server/handlers/post.py
to handle PDF generation requests.WeasyPrint
for rendering HTML to PDF.render_medium_post_link
function to support PDF generation.Template Changes:
web/server/templates/post.html
.Frontend Changes:
new-web/src/routes/[slug]/+page.svelte
to trigger the PDF generation.Documentation:
README.md
to include instructions for the new PDF generation feature.For more details, open the Copilot Workspace session.