Browse Source

standalone/integrated HTML exports

master
Lephenixnoir 2 months ago
parent
commit
f5a94667e5
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
2 changed files with 41 additions and 20 deletions
  1. +14
    -6
      Makefile
  2. +27
    -14
      tools/render-html.py

+ 14
- 6
Makefile View File

@ -1,27 +1,35 @@
#! /usr/bin/env make -f
all: json json-min html-fr html-en
all: json json-min html-fr html-en index-fr index-en
json: out/calcdb.json
json-min: out/calcdb-min.json
html-fr: out/calcdb-fr.html
html-en: out/calcdb-en.html
index-fr: out/index-fr.html
index-en: out/index-en.html
DEPS = $(wildcard calculators/* lang/*) model.yaml tools/calcdb.py | out/
out/calcdb.json: tools/convert-json.py $(DEPS)
tools/convert-json.py > out/calcdb.json
tools/convert-json.py > $@
out/calcdb-min.json: tools/convert-json.py $(DEPS)
tools/convert-json.py --min > out/calcdb-min.json
tools/convert-json.py --min > $@
out/calcdb-fr.html: tools/render-html.py $(DEPS)
tools/render-html.py fr > out/calcdb-fr.html
tools/render-html.py fr --standalone > $@
out/calcdb-en.html: tools/render-html.py $(DEPS)
tools/render-html.py en > out/calcdb-en.html
tools/render-html.py en --standalone > $@
out/index-fr.html: tools/render-html.py $(DEPS)
tools/render-html.py fr > $@
out/index-en.html: tools/render-html.py $(DEPS)
tools/render-html.py en > $@
%/:
@ mkdir -p $@
.PHONY: json json-min html-fr html-en
.PHONY: json json-min html-fr html-en index-fr index-en

+ 27
- 14
tools/render-html.py View File

@ -11,20 +11,26 @@ md = markdown.Markdown()
# Parse arguments
args = sys.argv[1:]
if len(args) != 1:
print(f"usage: {sys.argv[0]} <lang>", file=sys.stderr)
def usage():
print(f"usage: {sys.argv[0]} <lang> [--standalone]", file=sys.stderr)
sys.exit(1)
args = sys.argv[1:]
if len(args) < 1:
usage()
if args[0] not in db.lang:
print(f"error: no language data for '{args[0]}'", file=sys.stderr)
sys.exit(1)
lang = db.lang[args[0]]
if args[1:] != [] and args[1:] != ["--standalone"]:
usage()
standalone = ("--standalone" in args)
# HTML bits
print("""
header = """
<!doctype html>
<html>
<head>
@ -84,16 +90,24 @@ print("""
a:hover { text-decoration: underline; }
</style>
</head>
<body>
<table>""")
<body>"""
if standalone:
print(header)
print("<table>")
# Photo
print(f"<tr><th class='borderless' class='field'></th>")
print(f"<tr><th class='borderless field'></th>")
for (name, calc) in db.all_calcs():
print(f"<td class='borderless'><img src='../images/small/{name}.jpg'</td>")
if standalone:
url = f"../images/small/{name}.jpg"
else:
url = "https://gitea.planet-casio.com/Lephenixnoir/CalcDB/raw/"\
f"branch/master/images/small/{name}.jpg"
print(f"<td class='borderless'><img src='{url}'></td>")
print("</tr>")
# Full name
print(f"<tr><th class='borderless' class='field'></th>")
print(f"<tr><th class='borderless field'></th>")
for (name, calc) in db.all_calcs():
value = calc["general"]["full_name"]
active = " st-active" if calc["general"]["active"] else ""
@ -128,7 +142,6 @@ for category in db.all_categories():
print(f"<td{classes}>{r}</td>")
print("</tr>")
print("""
</table>
</body>
</html>""")
print("</table>")
if standalone:
print("</body></html>")

Loading…
Cancel
Save