Created
January 5, 2025 19:17
-
-
Save ShadowNinja/ae535e1589a1037d5a20125ff6c8eb32 to your computer and use it in GitHub Desktop.
Minetest Doxygen scripts
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 | |
""" | |
Optimize size of documentation files. | |
""" | |
import argparse | |
import os | |
import shutil | |
import subprocess | |
import sys | |
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) | |
HTML_DIR = "/opt/minetest/build/doc/html" | |
def find_files(path): | |
for dirpath, _, files in os.walk(path): | |
for fn in files: | |
yield os.path.join(dirpath, fn) | |
filter_endswith = lambda f, e: [n for n in f if n.endswith(e)] | |
def cmd_hcj(args): | |
print("Optimizing HTML, CSS, and JavaScript...") | |
subprocess.check_call([ | |
os.path.join(SCRIPT_DIR, "css-html-js-minify", "css-html-js-minify.py"), | |
"--overwrite", | |
"--sort", | |
HTML_DIR, | |
]) | |
def cmd_gz(args): | |
print("GZiping HTML, CSS, and Javascript...") | |
output_files = find_files(HTML_DIR) | |
html_files = filter_endswith(output_files, ".html") | |
css_files = filter_endswith(output_files, ".css") | |
js_files = filter_endswith(output_files, ".js") | |
subprocess.check_call( | |
["gzip", "--keep", "--best", "--force"] + | |
html_files + | |
css_files + | |
js_files | |
) | |
def cmd_svg(args): | |
svg_path = os.path.join(HTML_DIR, "svg") | |
print("Optimizing SVGs...") | |
os.makedirs(svg_path, exist_ok=True) | |
link_path = os.path.join(svg_path, "links") | |
if os.path.isdir(link_path): | |
shutil.rmtree(link_path) | |
os.mkdir(link_path) | |
optimized = [] | |
for fn in os.listdir(HTML_DIR): | |
# minetest.svg should be processed separately | |
if not fn.endswith(".svg") or fn == "minetest.svg": | |
continue | |
in_path = os.path.join(HTML_DIR, fn) | |
out_path = os.path.join(svg_path, fn) | |
try: | |
out_mtime = os.stat(out_path).st_mtime | |
st = os.stat(in_path) | |
if st.st_mtime < out_mtime: | |
continue | |
except os.error: | |
# Optimized file doesn't exist, create it | |
pass | |
os.symlink(in_path, os.path.join(link_path, fn)) | |
optimized.append(out_path) | |
print("Optimizing %d SVGs" % (len(optimized),)) | |
if len(optimized) > 0: | |
subprocess.check_call([ | |
"svgo", | |
# Graphs don't have to be very precise | |
"--precision", "0", | |
"--enable=sortAttrs", # Disabled by default, makes compression more effective | |
"--folder", link_path, | |
"--output", svg_path | |
]) | |
# But minetest.svg needs higher precision to look right | |
print("Optimizing logo SVG") | |
subprocess.check_call([ | |
"svgo", | |
"--precision", "1", | |
"--enable=sortAttrs", | |
"--input", os.path.join(HTML_DIR, "minetest.svg"), | |
"--output", os.path.join(svg_path, "minetest.svg") | |
]) | |
shutil.rmtree(link_path) | |
print("GZiping SVGs...") | |
subprocess.check_call( | |
["gzip", "--keep", "--best", "--force", os.path.join(svg_path, "minetest.svg")] + optimized | |
) | |
def cmd_all(args): | |
# Currently breaks the treeview | |
#cmd_hcj(args) | |
cmd_gz(args) | |
cmd_svg(args) | |
COMMANDS = { | |
"hcj": cmd_hcj, | |
"gz": cmd_gz, | |
"svg": cmd_svg, | |
"all": cmd_all, | |
} | |
def main(): | |
parser = argparse.ArgumentParser(description=__doc__) | |
parser.add_argument("cmd", choices=COMMANDS.keys()) | |
args = parser.parse_args() | |
COMMANDS[args.cmd](args) | |
if __name__ == "__main__": | |
main() |
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
#!/bin/bash | |
set -euo pipefail | |
SCRIPT_DIR=$(dirname -- "$(realpath -- "${BASH_SOURCE[0]}")") | |
cd /opt/minetest | |
git pull | |
cmake --build build -t doc | |
"$SCRIPT_DIR/optimize-doxy.py" all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment