Skip to content

Instantly share code, notes, and snippets.

@brianwisti
Created December 28, 2015 02:12
Show Gist options
  • Save brianwisti/96b2cdf0bd93c432c9ab to your computer and use it in GitHub Desktop.
Save brianwisti/96b2cdf0bd93c432c9ab to your computer and use it in GitHub Desktop.
First pass at previewing randomgeekery.org content with all themes in Hugo themes repository
#!/usr/bin/env python3
import os
import os.path
import subprocess
import time
from splinter import Browser
def is_theme_dir(folder, item):
"""Simple check for hidden and non-dir files"""
if item[0] == '.':
return False
full_path = os.path.join(folder, item)
if os.path.isfile(full_path):
return False
return True
if __name__ == '__main__':
theme_dir = "themes"
url = "http://127.0.0.1:1313"
listing = [ item for item in os.listdir(theme_dir)
if is_theme_dir(theme_dir, item) ]
browser_name = 'chrome'
browser = Browser(browser_name)
browser.visit(url) # visit out here, reload down there because browser cache
for theme in listing:
command = [ "/usr/local/bin/hugo", "server", "--theme", theme ]
proc = subprocess.Popen(command)
time.sleep(1) # More than enough time for Hugo to build the site.
browser.reload()
time.sleep(2) # Allow browser to get external resources.
message = "Theme: {}, Status: {}".format(theme, browser.status_code)
print(message)
screenshot_name = "{}-{}".format(browser_name, theme)
screenshot_file = os.path.join(os.getcwd(), "screenshots", screenshot_name)
browser.screenshot(screenshot_file)
print("Screenshot saved as: {}".format(screenshot_file))
proc.kill()
browser.quit()
# Make an animated GIF of the whole thing.
# (When in doubt, ImageMagick)
convert_command = [ "/usr/local/bin/convert",
"-delay", '35',
"-loop", '0',
"-scale", '50%',
"screenshots/*.png",
"hugo-themes.gif" ]
subprocess.run(convert_command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment