copy opentree static CSS and JS files into a file - but forget to deal with relative paths changing...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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