| @@ -10,3 +10,4 @@ Dependencies | |||||
| * [earwigbot](https://github.com/earwig/earwigbot) | * [earwigbot](https://github.com/earwig/earwigbot) | ||||
| * [mako](http://www.makotemplates.org/) | * [mako](http://www.makotemplates.org/) | ||||
| * [oursql](http://packages.python.org/oursql/) | * [oursql](http://packages.python.org/oursql/) | ||||
| * [uglifyjs](https://github.com/mishoo/UglifyJS/) | |||||
| @@ -4,6 +4,7 @@ | |||||
| import logging | import logging | ||||
| import os | import os | ||||
| import shutil | import shutil | ||||
| import subprocess | |||||
| page_src = """#! /usr/bin/env python | page_src = """#! /usr/bin/env python | ||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
| @@ -95,6 +96,15 @@ class Builder(object): | |||||
| logger.debug("copytree {0} -> {1}".format(self.static_dir, dest)) | logger.debug("copytree {0} -> {1}".format(self.static_dir, dest)) | ||||
| shutil.copytree(self.static_dir, dest) | shutil.copytree(self.static_dir, dest) | ||||
| for dirpath, dirnames, filenames in os.walk(dest): | |||||
| for filename in filenames: | |||||
| if filename.endswith(".js"): | |||||
| name = os.path.join(dirpath, filename) | |||||
| logger.debug("uglifyjs {0}".format(name)) | |||||
| uglified = subprocess.check_output(["uglifyjs", name]) | |||||
| os.remove(name) | |||||
| with open(name, "w") as fp: | |||||
| fp.write(uglified) | |||||
| def gen_pages(self): | def gen_pages(self): | ||||
| logger = self.root.getChild("pages") | logger = self.root.getChild("pages") | ||||
| @@ -18,18 +18,27 @@ function get_cookie(name) { | |||||
| return null; | return null; | ||||
| } | } | ||||
| function set_cookie(name, value, days) { | |||||
| function set_cookie_with_date(name, value, date) { | |||||
| value = window.btoa("--ets1" + value); | value = window.btoa("--ets1" + value); | ||||
| var path = window.location.pathname.split("/", 2)[1]; | var path = window.location.pathname.split("/", 2)[1]; | ||||
| if (date) { | |||||
| var expires = "; expires=" + date.toUTCString(); | |||||
| } | |||||
| else { | |||||
| var expires = ""; | |||||
| } | |||||
| document.cookie = name + "=" + value + expires + "; path=/" + path; | |||||
| } | |||||
| function set_cookie(name, value, days) { | |||||
| if (days) { | if (days) { | ||||
| var date = new Date(); | var date = new Date(); | ||||
| date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | ||||
| var expires = "; expires=" + date.toGMTString(); | |||||
| set_cookie_with_date(name, value, date); | |||||
| } | } | ||||
| else { | else { | ||||
| var expires = ""; | |||||
| set_cookie_with_date(name, value); | |||||
| } | } | ||||
| document.cookie = name + "=" + value + expires + "; path=/" + path; | |||||
| } | } | ||||
| function delete_cookie(name) { | function delete_cookie(name) { | ||||
| @@ -1,4 +1,20 @@ | |||||
| function potd_set_background() { | function potd_set_background() { | ||||
| var cookie = get_cookie("EarwigBackgroundCache"); | |||||
| if (cookie) { | |||||
| try { | |||||
| data = JSON.parse(cookie); | |||||
| var url = data.url; | |||||
| var descurl = data.descurl; | |||||
| var imgwidth = data.imgwidth; | |||||
| var imgheight = data.imgheight; | |||||
| if (url && descurl && imgwidth && imgheight) { | |||||
| set_background(url, descurl, imgwidth, imgheight); | |||||
| return; | |||||
| } | |||||
| } | |||||
| catch (SyntaxError) {} | |||||
| } | |||||
| var d = new Date(); | var d = new Date(); | ||||
| var callback = "earwigpotd1"; | var callback = "earwigpotd1"; | ||||
| var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2); | var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2); | ||||
| @@ -55,7 +71,12 @@ function parse_file_url(data, filename) { | |||||
| imgwidth = r["width"]; | imgwidth = r["width"]; | ||||
| imgheight = r["height"]; | imgheight = r["height"]; | ||||
| } | } | ||||
| set_background(url, descurl, imgwidth, imgheight); | set_background(url, descurl, imgwidth, imgheight); | ||||
| var data = {"url": url, "descurl": descurl, "imgwidth": imgwidth, "imgheight": imgheight}; | |||||
| var now = new Date(); | |||||
| var expires = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1); | |||||
| set_cookie_with_date("EarwigBackgroundCache", JSON.stringify(data), expires); | |||||
| } | } | ||||
| function set_background(url, descurl, imgwidth, imgheight) { | function set_background(url, descurl, imgwidth, imgheight) { | ||||