Add auto-wrapping media queries for CSS static resources.

This commit is contained in:
Sergio Martínez Portela 2022-07-24 23:08:38 +02:00
parent 31a303ab55
commit 29a9d25381

View File

@ -42,7 +42,7 @@ ARTICLE_TEMPLATE_NAME = 'article.tmpl.html'
STATIC_RESOURCES = (
('style.css', 'css/style.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(
@ -176,10 +176,22 @@ def regen_all(source_top, dest_top, docs=None):
with open(doc_full_path + '.html', 'wt') as f:
render_article(doc, front_matter, f)
for src, dest in STATIC_RESOURCES:
target_dest = os.path.join(dest_top, dest)
for static in STATIC_RESOURCES:
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)
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
@ -201,10 +213,22 @@ def main(source_top, dest_top):
if filepath.startswith(STATIC_PATH):
t0 = time.time()
update_statics()
for src, dest in STATIC_RESOURCES:
target_dest = os.path.join(dest_top, dest)
for static in STATIC_RESOURCES:
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)
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)
logging.info("Updated all in {:.2f}s".format(time.time() - t0))