BASC-Archiver icon indicating copy to clipboard operation
BASC-Archiver copied to clipboard

JSON HTML Templating with Jinja2

Open antonizoon opened this issue 10 years ago • 5 comments

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.

antonizoon avatar Feb 21 '15 19:02 antonizoon

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.
    • NSFW: Yotsuba - All non-worksafe boards on 4chan use the classic Yotsuba theme, which is a salmon red color (based on the original Futaba theme)
    • Worksafe: Yotsublue/Burichan - All worksafe boards on 4chan use the Burichan theme, which is a light blue color.
  • Fuuka: FoolFuuka - Uses a suave green CSS theme, with handy Google Image Search/SauceNAO/TinEye links if only thumbnails were saved.

antonizoon avatar Feb 21 '15 20:02 antonizoon

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.

DanielOaks avatar Oct 29 '15 22:10 DanielOaks

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/.

HuggableSquare avatar Dec 14 '15 01:12 HuggableSquare

Awesome. We'll look into integrating this. You can actually make a quick and dirty webserver at:

$ cd /home/somedir
$ python -m SimpleHTTPServer

antonizoon avatar Dec 15 '15 18:12 antonizoon

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.

HuggableSquare avatar Apr 04 '16 01:04 HuggableSquare