build-site.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from github import Github, Repository
  2. from gftools.utils import download_file
  3. from zipfile import ZipFile
  4. from pathlib import Path
  5. import tempfile
  6. import os
  7. import json
  8. from io import BytesIO
  9. from pybars import Compiler, strlist
  10. import humanize
  11. import re
  12. import subprocess
  13. EXCLUDE_LIST = ["Arimo", "Cousine", "Tinos"]
  14. results = json.load(open("docs/noto.json"))
  15. versions = json.load(open("docs/versions.json"))
  16. def _basename(this, item):
  17. return strlist([os.path.basename(item)])
  18. def _denoto(this, item):
  19. return strlist([item.replace("Noto ", "")])
  20. def _sizeof(this, item):
  21. return strlist([humanize.naturalsize(os.path.getsize(item))])
  22. def _gt1(this, options, context):
  23. if hasattr(context, "__call__"):
  24. context = context(this)
  25. if context > 1:
  26. return options["fn"](this)
  27. else:
  28. return options["inverse"](this)
  29. def _ifslim(this, options, context):
  30. if hasattr(context, "__call__"):
  31. context = context(this)
  32. if "slim-variable-ttf" in context:
  33. return options["fn"](this)
  34. else:
  35. return options["inverse"](this)
  36. helpers = {
  37. "basename": _basename,
  38. "gt1": _gt1,
  39. "sizeof": _sizeof,
  40. "ifslim": _ifslim,
  41. "denoto": _denoto,
  42. }
  43. def icon_for_platform(platform):
  44. if "Android" in platform:
  45. return f'<span class="material-icons" data-toggle="tooltip" title="{platform}"> android </span>'
  46. if "iOS" in platform:
  47. return f'<span class="material-icons" data-toggle="tooltip" title="{platform}"> phone_iphone </span>'
  48. if "macOS" in platform:
  49. return f'<span class="material-icons" data-toggle="tooltip" title="{platform}"> laptop_mac </span>'
  50. if "Google Fonts" in platform:
  51. return f'<img data-toggle="tooltip" title="{platform}" src="gflogo.png" width=18 height=18></img>'
  52. if "Fedora" in platform:
  53. return f'<img data-toggle="tooltip" title="{platform}" src="fedora.png" width=18 height=18></img>'
  54. return platform
  55. compiler = Compiler()
  56. template = open("scripts/template.html", "r").read()
  57. template = compiler.compile(template)
  58. for result in results.values():
  59. result["has_releases"] = False
  60. for family_name, family in result.get("families", []).items():
  61. if family.get("latest_release"):
  62. result["has_releases"] = True
  63. latest_version = family["latest_release"]["version"][1:]
  64. if family_name in versions:
  65. family["third_party_versions"] = {
  66. k: {
  67. "version": versions[family_name][k],
  68. "up_to_date": versions[family_name][k] == latest_version,
  69. "icon": icon_for_platform(k)
  70. }
  71. for k in sorted(versions[family_name].keys())
  72. }
  73. result["issue_count"] = len(result["issues"])
  74. result["families_count"] = len(result["families"])
  75. for excluded in EXCLUDE_LIST:
  76. if excluded in results:
  77. del results[excluded]
  78. output = template({"results": results}, helpers=helpers)
  79. with open("docs/index.html", "w") as fh:
  80. fh.write(output)
  81. bug_template = open("scripts/bugreporter.html", "r").read()
  82. bug_template = compiler.compile(bug_template)
  83. output = bug_template({"results": results})
  84. with open("docs/reporter.html", "w") as fh:
  85. fh.write(output)
  86. json.dump(
  87. results, open("debug.json", "w"), indent=True, sort_keys=True
  88. )