Add auto-wrapping media queries for CSS static resources.
This commit is contained in:
parent
31a303ab55
commit
29a9d25381
@ -42,7 +42,7 @@ ARTICLE_TEMPLATE_NAME = 'article.tmpl.html'
|
|||||||
STATIC_RESOURCES = (
|
STATIC_RESOURCES = (
|
||||||
('style.css', 'css/style.css'),
|
('style.css', 'css/style.css'),
|
||||||
('light-syntax.css', 'css/light-syntax.css'),
|
('light-syntax.css', 'css/light-syntax.css'),
|
||||||
('dark-syntax.css', 'css/dark-syntax.css'),
|
('dark-syntax.css', 'css/dark-syntax.css', ('@media (prefers-color-scheme: dark) {\n', '\n}')),
|
||||||
)
|
)
|
||||||
|
|
||||||
JINJA_ENV = jinja2.Environment(
|
JINJA_ENV = jinja2.Environment(
|
||||||
@ -176,10 +176,22 @@ def regen_all(source_top, dest_top, docs=None):
|
|||||||
with open(doc_full_path + '.html', 'wt') as f:
|
with open(doc_full_path + '.html', 'wt') as f:
|
||||||
render_article(doc, front_matter, f)
|
render_article(doc, front_matter, f)
|
||||||
|
|
||||||
for src, dest in STATIC_RESOURCES:
|
for static in STATIC_RESOURCES:
|
||||||
target_dest = os.path.join(dest_top, dest)
|
src_path = static[0]
|
||||||
|
dest_path = static[1]
|
||||||
|
|
||||||
|
if len(static) > 2:
|
||||||
|
before, after = static[2]
|
||||||
|
else:
|
||||||
|
before, after = '', ''
|
||||||
|
target_dest = os.path.join(dest_top, dest_path)
|
||||||
os.makedirs(os.path.dirname(target_dest), exist_ok=True)
|
os.makedirs(os.path.dirname(target_dest), exist_ok=True)
|
||||||
shutil.copy(os.path.join(STATIC_PATH, src), target_dest)
|
with open(os.path.join(STATIC_PATH, src_path), 'rt') as src:
|
||||||
|
data = before + src.read() + after
|
||||||
|
|
||||||
|
with open(target_dest, 'wt') as f:
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
return docs
|
return docs
|
||||||
|
|
||||||
|
|
||||||
@ -201,10 +213,22 @@ def main(source_top, dest_top):
|
|||||||
if filepath.startswith(STATIC_PATH):
|
if filepath.startswith(STATIC_PATH):
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
update_statics()
|
update_statics()
|
||||||
for src, dest in STATIC_RESOURCES:
|
for static in STATIC_RESOURCES:
|
||||||
target_dest = os.path.join(dest_top, dest)
|
src_path = static[0]
|
||||||
|
dest_path = static[1]
|
||||||
|
|
||||||
|
if len(static) > 2:
|
||||||
|
before, after = static[2]
|
||||||
|
else:
|
||||||
|
before, after = '', ''
|
||||||
|
target_dest = os.path.join(dest_top, dest_path)
|
||||||
os.makedirs(os.path.dirname(target_dest), exist_ok=True)
|
os.makedirs(os.path.dirname(target_dest), exist_ok=True)
|
||||||
shutil.copy(os.path.join(STATIC_PATH, src), target_dest)
|
with open(os.path.join(STATIC_PATH, src_path), 'rt') as src:
|
||||||
|
data = before + src.read() + after
|
||||||
|
|
||||||
|
with open(target_dest, 'wt') as f:
|
||||||
|
f.write(data)
|
||||||
|
|
||||||
docs = regen_all(source_top, dest_top, docs)
|
docs = regen_all(source_top, dest_top, docs)
|
||||||
logging.info("Updated all in {:.2f}s".format(time.time() - t0))
|
logging.info("Updated all in {:.2f}s".format(time.time() - t0))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user