Skip to content

Instantly share code, notes, and snippets.

@mtholder
Created September 20, 2015 18:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mtholder/b0296d7402b65fc51b6d to your computer and use it in GitHub Desktop.
copy opentree static CSS and JS files into a file - but forget to deal with relative paths changing...
#!/usr/bin/env python
import sys
import re
inp = sys.stdin
outp = sys.stdout
JS_PAT = re.compile(r'^<script src="/opentree/static/(.+)" type="text/javascript"></script>\s+$')
CSS_PAT = re.compile(r'^<link href="/opentree/static/(.+)" rel="stylesheet" type="text/css" />\s+$')
for line in inp:
m = JS_PAT.match(line)
if m:
fn = m.group(1)
outp.write('<script type="text/javascript">\n')
with open(fn, 'rU') as to_inline:
outp.write(to_inline.read())
outp.write('\n</script>\n')
else:
m = CSS_PAT.match(line)
if m:
fn = m.group(1)
outp.write('<style type="text/css">\n')
with open(fn, 'rU') as to_inline:
outp.write(to_inline.read())
outp.write('\n</style>\n')
else:
outp.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment