-
-
Save ukiahsmith/e1378659a8d1cd911c327792c8fd8113 to your computer and use it in GitHub Desktop.
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 python3 | |
import os | |
import fnmatch | |
import subprocess | |
import json | |
import sys | |
''' | |
open asset directory | |
for each file do these | |
get hash | |
process sass, output filename w/ hash | |
add to data, data structure | |
then output data.js file | |
''' | |
data = {} | |
path = os.path.abspath(sys.argv[1]) | |
out_path = os.path.abspath(sys.argv[2]) | |
j_data = os.path.abspath('data/snowblind/css.json') | |
if not os.path.isdir(path): | |
sys.exit() | |
if not os.path.isdir(out_path): | |
os.mkdir(out_path, mode=0o755) | |
for fname in fnmatch.filter(os.listdir(path), '*scss'): | |
hash = subprocess.getoutput("git log --format='%h' -n1 {}/{}".format(path,fname)) | |
base_name = os.path.splitext(fname)[0] | |
out_name = "{}-{}.css".format(base_name, hash) | |
# sassc -t compressed ${THEME_PATH}/assets/css/core.scss ${THEME_PATH}/static/css/core-${HUGO_NUM}.css | |
sass_cmd = "sassc -t compressed {}/{} {}/{}".format(path, fname, out_path, out_name) | |
if os.path.isfile(out_path + "/" + out_name): | |
print("File already exists, skipping: {}/{}".format(out_path, out_name)) | |
else: | |
print("Generating: {}/{}".format(out_path, out_name)) | |
subprocess.run(sass_cmd, shell=True, check=True) | |
data[base_name] = out_name | |
with open(j_data, 'w') as outfile: | |
print("Generating CSS json data file. ", end="") | |
json.dump(data, outfile) | |
print("Done.") | |
print("CSS Processing Complete.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment