BASC-Archiver
BASC-Archiver copied to clipboard
JSON HTML Templating with Jinja2
It's about time for us to create a JSON templating system, which will be integrated as part of the .chan.arc
standard. This way, we don't have to manually retrieve the CSS and HTML on every thread grab, nor do we need to deal with regex'ing current files (which has many problems on systems with non-UTF encoding)...
Jinja2 is fairly simple, basically html file that uses {% %} and {{ }} tags to play with input data and insert data.
basically have a file like:<html><head><title>{{ title }}</title></head><body>{% for thread in threads %}{{ thread.title }} etc etc{% endfor %}</body></html>
and then you just call the templator with something like(title='Page title', threads=[thread1, thread2, thread3])
You'll still have an option that allows you to grab the original HTML and CSS the way we currently do it (for events such as CSS madness on /pol/ and /b/). But you only need to grab them when they are an important aspect of the thread.
In any case, we will make a WARC option someday that grabs a thread snapshot the way the Internet Archive demands it.
Since the CSS Themes used on a board is an important part of the environment, we should try to match each board to a certain color.
Perhaps we could have a list of all NSFW boards in the HTML templater that get red Yotsuba theme. The rest of the boards get Yotsublue.
- 4chan - 4chan boards use different colors to differentiate between NSFW and SFW boards.
- Fuuka: FoolFuuka - Uses a suave green CSS theme, with handy Google Image Search/SauceNAO/TinEye links if only thumbnails were saved.
There is a good use case for this. Mostly, 4chan sometimes totally stuffs the HTML output of threads. Along with what's proposed in #26, it could be nice to write a standardised output template (with js to do provide those nice features like we have on 4chan.
I have this functional, I call it jinjaChan. It currently has some issues, but it mostly works. I can setup an example page, if you want.
Getting the extensions js to work has some caveats though:
- You have to serve the content with a legit webserver.
- The HTML must be minified in a somewhat specific way, I use django-htmlmin to do this.
- You're going to have to change your folder structure to something like
http://example.com/b/thread/9001/
.
Awesome. We'll look into integrating this. You can actually make a quick and dirty webserver at:
$ cd /home/somedir
$ python -m SimpleHTTPServer
I have it integrated and functional, but not entirely complete. I've opened PR #36 for you guys to look at the code, and discuss further.