Use PhantomJS to take screenshots

pull/26/head^2
Adam Porter 7 years ago
parent 5d3e47d1aa
commit 9b63bf2d6e

@ -1,2 +1,7 @@
.PHONY: all screenshots
all:
@./make.py
screenshots:
@./make.py screenshots

@ -1037,64 +1037,6 @@ div.crp {
#fbar {
background-color: #2e2e2e !important;
}
table {
background-color: #262626 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #e05f27 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #262626 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #262626 !important;
}
.title a {
color: #909396 !important;
}
.title a:visited {
color: #5e6263 !important;
}
a.storylink {
color: #a6aaab !important;
font-weight: bold;
}
.sitestr {
color: #2f7bde !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #262626 !important;
}
#hnmain .comhead {
color: #a6aaab !important;
}
#hnmain .c00 {
color: #909396 !important;
}
#hnmain a.hnuser {
color: #b68800 !important;
}
#hnmain span.age a {
color: #5e6263 !important;
}
.cdd {
color: rgba(255,66,56,0.65) !important;
}
.comment i {
color: #5e6263 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #262626 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #e05f27 !important;
}
tr.Even {
background-color: #2e2e2e !important;
}
@ -1263,6 +1205,64 @@ table.wikitable {
table.wikitable > * > tr > th {
background-color: #2e2e2e !important;
}
table {
background-color: #262626 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #e05f27 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #262626 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #262626 !important;
}
.title a {
color: #909396 !important;
}
.title a:visited {
color: #5e6263 !important;
}
a.storylink {
color: #a6aaab !important;
font-weight: bold;
}
.sitestr {
color: #2f7bde !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #262626 !important;
}
#hnmain .comhead {
color: #a6aaab !important;
}
#hnmain .c00 {
color: #909396 !important;
}
#hnmain a.hnuser {
color: #b68800 !important;
}
#hnmain span.age a {
color: #5e6263 !important;
}
.cdd {
color: rgba(255,66,56,0.65) !important;
}
.comment i {
color: #5e6263 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #262626 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #e05f27 !important;
}
div#page div#header {
background-color: #262626 !important;
}

@ -1037,64 +1037,6 @@ div.crp {
#fbar {
background-color: #3c3836 !important;
}
table {
background-color: #282828 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #fb4934 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #282828 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #282828 !important;
}
.title a {
color: #83a598 !important;
}
.title a:visited {
color: #b8bb26 !important;
}
a.storylink {
color: #8ec07c !important;
font-weight: bold;
}
.sitestr {
color: #458588 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #282828 !important;
}
#hnmain .comhead {
color: #8ec07c !important;
}
#hnmain .c00 {
color: #83a598 !important;
}
#hnmain a.hnuser {
color: #d79921 !important;
}
#hnmain span.age a {
color: #b8bb26 !important;
}
.cdd {
color: rgba(255,34,23,0.65) !important;
}
.comment i {
color: #b8bb26 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #282828 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #fb4934 !important;
}
tr.Even {
background-color: #3c3836 !important;
}
@ -1263,6 +1205,64 @@ table.wikitable {
table.wikitable > * > tr > th {
background-color: #3c3836 !important;
}
table {
background-color: #282828 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #fb4934 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #282828 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #282828 !important;
}
.title a {
color: #83a598 !important;
}
.title a:visited {
color: #b8bb26 !important;
}
a.storylink {
color: #8ec07c !important;
font-weight: bold;
}
.sitestr {
color: #458588 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #282828 !important;
}
#hnmain .comhead {
color: #8ec07c !important;
}
#hnmain .c00 {
color: #83a598 !important;
}
#hnmain a.hnuser {
color: #d79921 !important;
}
#hnmain span.age a {
color: #b8bb26 !important;
}
.cdd {
color: rgba(255,34,23,0.65) !important;
}
.comment i {
color: #b8bb26 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #282828 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #fb4934 !important;
}
div#page div#header {
background-color: #282828 !important;
}

@ -1037,64 +1037,6 @@ div.crp {
#fbar {
background-color: #073642 !important;
}
table {
background-color: #002b36 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #cb4b16 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #002b36 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #002b36 !important;
}
.title a {
color: #839496 !important;
}
.title a:visited {
color: #586e75 !important;
}
a.storylink {
color: #93a1a1 !important;
font-weight: bold;
}
.sitestr {
color: #268bd2 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #002b36 !important;
}
#hnmain .comhead {
color: #93a1a1 !important;
}
#hnmain .c00 {
color: #839496 !important;
}
#hnmain a.hnuser {
color: #b58900 !important;
}
#hnmain span.age a {
color: #586e75 !important;
}
.cdd {
color: rgba(255,54,43,0.65) !important;
}
.comment i {
color: #586e75 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #002b36 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #cb4b16 !important;
}
tr.Even {
background-color: #073642 !important;
}
@ -1263,6 +1205,64 @@ table.wikitable {
table.wikitable > * > tr > th {
background-color: #073642 !important;
}
table {
background-color: #002b36 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #cb4b16 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #002b36 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #002b36 !important;
}
.title a {
color: #839496 !important;
}
.title a:visited {
color: #586e75 !important;
}
a.storylink {
color: #93a1a1 !important;
font-weight: bold;
}
.sitestr {
color: #268bd2 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #002b36 !important;
}
#hnmain .comhead {
color: #93a1a1 !important;
}
#hnmain .c00 {
color: #839496 !important;
}
#hnmain a.hnuser {
color: #b58900 !important;
}
#hnmain span.age a {
color: #586e75 !important;
}
.cdd {
color: rgba(255,54,43,0.65) !important;
}
.comment i {
color: #586e75 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #002b36 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #cb4b16 !important;
}
div#page div#header {
background-color: #002b36 !important;
}

@ -1037,64 +1037,6 @@ div.crp {
#fbar {
background-color: #eee8d5 !important;
}
table {
background-color: #fdf6e3 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #cb4b16 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #fdf6e3 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #fdf6e3 !important;
}
.title a {
color: #657b83 !important;
}
.title a:visited {
color: #93a1a1 !important;
}
a.storylink {
color: #586e75 !important;
font-weight: bold;
}
.sitestr {
color: #268bd2 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #fdf6e3 !important;
}
#hnmain .comhead {
color: #586e75 !important;
}
#hnmain .c00 {
color: #657b83 !important;
}
#hnmain a.hnuser {
color: #b58900 !important;
}
#hnmain span.age a {
color: #93a1a1 !important;
}
.cdd {
color: rgba(202,0,0,0.65) !important;
}
.comment i {
color: #93a1a1 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #fdf6e3 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #cb4b16 !important;
}
tr.Even {
background-color: #eee8d5 !important;
}
@ -1263,6 +1205,64 @@ table.wikitable {
table.wikitable > * > tr > th {
background-color: #eee8d5 !important;
}
table {
background-color: #fdf6e3 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > table {
background-color: #cb4b16 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) a,
#hnmain > tbody:nth-child(1) > tr:nth-child(1) a {
color: #000 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2),
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #fdf6e3 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(2) {
background-color: #fdf6e3 !important;
}
.title a {
color: #657b83 !important;
}
.title a:visited {
color: #93a1a1 !important;
}
a.storylink {
color: #586e75 !important;
font-weight: bold;
}
.sitestr {
color: #268bd2 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(1) {
background-color: #fdf6e3 !important;
}
#hnmain .comhead {
color: #586e75 !important;
}
#hnmain .c00 {
color: #657b83 !important;
}
#hnmain a.hnuser {
color: #b58900 !important;
}
#hnmain span.age a {
color: #93a1a1 !important;
}
.cdd {
color: rgba(202,0,0,0.65) !important;
}
.comment i {
color: #93a1a1 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) {
background-color: #fdf6e3 !important;
}
#hnmain > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(1) > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) {
background-color: #cb4b16 !important;
}
div#page div#header {
background-color: #fdf6e3 !important;
}

@ -4,16 +4,21 @@
import os
import subprocess
import sys
import multiprocessing
import functools
from collections import namedtuple
from tempfile import mkstemp
# * Variables
sites_dir="sites"
themes_dir = "themes"
css_dir = "css"
screenshots_dir="screenshots"
phantomjs_command = "phantomjs --ssl-protocol=any --ignore-ssl-errors=true screenshot.js".split()
common_deps = ["styl/index.styl", "styl/mixins.styl"]
@ -23,6 +28,16 @@ Theme = namedtuple("Theme", ['name', 'styl_path', 'support_files'])
# * Functions
def main():
"Update CSS files by default, or update screenshots."
if len(sys.argv) > 1 and sys.argv[1] == "screenshots":
update_screenshots()
else:
update_css_files()
# ** CSS
def update_css_files():
"Build CSS files that need to be built."
css_files = list_css(themes(), sites())
@ -65,6 +80,79 @@ def stylus(css):
f.write(result)
print(output_file)
# ** Screenshots
def update_screenshots():
"Update screenshots."
css_files = list_css(themes(), sites())
# Make directories first to avoid race condition
for css in css_files:
output_dir = os.path.join(screenshots_dir, css.theme.name)
if not os.path.isdir(output_dir):
os.makedirs(output_dir)
pool = multiprocessing.Pool(multiprocessing.cpu_count())
pool.map(update_screenshot, css_files)
def update_screenshot(css):
"Update screenshot for CSS if necessary."
screenshot_path = screenshot_path_for_css(css)
if mtime(css.path) > mtime(screenshot_path):
save_screenshot(css)
def screenshot_path_for_css(css):
"Return path of screenshot for CSS."
return os.path.join(screenshots_dir, css.theme.name, "%s.png" % css.site)
def save_screenshot(css):
"Save screenshot for CSS."
# Prepare filename
screenshot_path = screenshot_path_for_css(css)
# Get URL
url = css_screenshot_url(css)
if not url:
# Screenshot disabled
return False
# Prepare command
command = list(phantomjs_command)
command.extend([url, screenshot_path, css.path])
# Run PhantomJS
subprocess.check_output(command)
# Compress with pngcrush
_, tempfile_path = mkstemp(suffix=".png")
subprocess.check_output(["pngcrush", screenshot_path, tempfile_path], stderr=subprocess.DEVNULL)
os.replace(tempfile_path, screenshot_path)
print(screenshot_path)
def css_screenshot_url(css):
"Return URL for taking screenshots of CSS."
# Get site URL
site_url_filename = os.path.join(sites_dir, css.site + ".url")
if os.path.exists(site_url_filename):
with open(site_url_filename, "r") as f:
url = f.readlines()
if url:
# Use URL given in .url file
url = url[0].strip()
else:
# Use name of site file (without .styl extension)
url = "http://" + css.site
return url
# ** Support
def list_css(themes, sites):
"Return list of CSS files for THEMES and SITES."
@ -79,21 +167,30 @@ def themes():
theme_names = []
themes = []
# Make list of theme directories
for d in os.listdir(themes_dir):
theme_names.append(d)
# Iterate over theme directories
for theme in theme_names:
support_files = []
variant_files = []
directory = os.path.join(themes_dir, theme)
# Iterate over files in theme directory
for f in os.listdir(directory):
path = os.path.join(themes_dir, theme, f)
if f == "colors.styl":
# Support file
support_files.append(path)
else:
elif f.endswith(".styl"):
# Theme file
variant_files.append({'variant': without_styl(f), 'path': path})
# Otherwise, not a relevant file
# Add theme object to list
if len(variant_files) == 1:
# Only one variant: omit variant name from theme name
themes.append(Theme(theme, variant_files[0]['path'], support_files))
@ -108,7 +205,9 @@ def sites():
"Return list of sites."
for path, dirs, files in os.walk(sites_dir):
return [site.replace(".styl", "") for site in files]
return [site.replace(".styl", "")
for site in files
if site.endswith(".styl")]
def dependencies(theme, site):
"Return list of dependency .styl files for THEME and SITE."
@ -133,6 +232,8 @@ def mtime(path):
return 0
def without_styl(s):
"""Return string S without ".styl" extension."""
return s.replace(".styl", "")
# * Footer

@ -0,0 +1,86 @@
"use strict";
// * Variables
var page = require('webpage').create(),
system = require('system'),
url, output_filename, size, pageWidth, pageHeight;
pageWidth = 1000;
// A shorter height would be nice, but with the enormous page headers
// nowadays (e.g. the stupid one inserted by GitHub unless you are
// logged in), you can't see anything!
pageHeight = 1000;
// ** Args
url = system.args[1];
output_filename = system.args[2];
// * Functions
function insert_css (stylesheet) {
// Insert HTML STYLE element with contents of string STYLESHEET.
var element = document.createElement('style');
element.type = "text/css";
element.innerHTML = stylesheet;
document.getElementsByTagName("head")[0].appendChild(element);
}
function process_page (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
}
else {
// Add stylesheet
page.evaluate(insert_css, stylesheet);
// Take screenshot
window.setTimeout(
function () {
page.render(output_filename);
phantom.exit();
},
200
);
}
}
// * Main
// Fix console output from page.evaluate()
page.onConsoleMessage = function (msg) {
console.log("LOG: page.evaluate: " + msg);
};
// Log all external requests
// page.onResourceRequested = function (requestData, request) {
// console.log('LOG: LOADING RESOURCE: ', requestData['url']);
// };
// ** Check args
page.viewportSize = {
width: pageWidth,
height: pageHeight
};
page.clipRect = {
top: 0,
left: 0,
width: pageWidth,
height: pageHeight
};
// ** Read CSS file from disk
var css_file = system.args[3];
var fs = require("fs");
var stylesheet = fs.read(css_file);
// ** Load and render page
page.open(url, process_page);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 181 KiB

@ -0,0 +1 @@
https://github.com/alphapapa/solarized-everything-css
Loading…
Cancel
Save