My experiment for a "topic export/save to PDF/HTML" feature
-
Unrelated to what I asked about yesterday, I was looking for a way to let any user export the full history of any given topic on my forum as a local file on their machine...
Well, NodeBB lacks a "print view" feature, or any kind of exporting. I've seen some people (1? https://community.nodebb.org/post/76342 lol) ask for it on here in the past, but apparently it's never been such a must-have. Given that the classic paginated view is a pain to export in one go, and the modern infinitely scrolling one is an even bigger issue (since, understandably for performance, posts in a thread are loaded and unloaded as they fit in and out of view), this is just impossible with standard browser tools.
Today then I've had a go at writing a small JavaScript snippet that, when fired on the page for any topic on any (!) NodeBB forum, uses the read API to fetch the entire history, puts it into the DOM in a dedicated view element independent from the one the NodeBB frontend controls, which is visualized properly for the standard browser print dialog to catch it and, well, print it fully (to PDF probably, I hope no one really needs to print forums to paper in 2024). See below:
I've currently only tested it on my own forum and on this one, which means I've only tested it with the Persona and Harmony themes, and your mileage may vary. Also, it doesn't have sophisticated error handling, which means it could fail strangely in some circumstances. I hope I can get some tips on how to turn this into a plugin, however; specifically, make it installable by any admin on their NodeBB board, in a way that adds an "export" button to the post sharing options (see mockup below)... is there an API for that?
I've also added a button to also export to HTML, in the GUI it creates, but I've noticed that the exported HTML file fails to load CSS and images, because HTTP headers for a standard NodeBB installation seem to prevent loading of the server's resources if a page from
file:///
embeds them (which is the case when opening the exported HTML).For now, this is available as a so-called userscript, which should work on both Firefox and Chromium, but I only tested it with the Violentmonkey script manager, and not Tampermonkey. If you'd like to test it for yourself, here is v1.0.0! Let me know what you think and of any possible improvements, and if you'd install such a plugin on your board.
-
julian@community.nodebb.organtwortete an bboctt@community.nodebb.org zuletzt editiert von
@bboctt Nice nice nice.
Okay, here are my thoughts on it...
- there are some applications for print view even in 2024/2025. One of those is reader mode. For whatever reason, NodeBB doesn't format well at all when sites try to remove extraneous elements and keep just the post text.
- if you don't care so much about getting the entire topic history, you could just get the existing topic data on-page by querying
ajaxify.data
. You can retrieve additional pages by passing?page=
param.