|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import json |
| 4 | +from datetime import date |
| 5 | +from convert_policy import markdown, obtain_link_mapping |
| 6 | + |
| 7 | + |
| 8 | +def create_biblio(db): |
| 9 | + biblio = {} |
| 10 | + |
| 11 | + for workstream in db["workstreams"]: |
| 12 | + for standard in workstream["standards"]: |
| 13 | + reference, contents = standard_or_idea_to_biblio(standard) |
| 14 | + contents["title"] += " Standard" |
| 15 | + biblio[reference] = contents |
| 16 | + |
| 17 | + for idea in db["ideas"]: |
| 18 | + reference, contents = standard_or_idea_to_biblio(idea) |
| 19 | + contents["status"] = "Living Idea" |
| 20 | + biblio[reference] = contents |
| 21 | + |
| 22 | + for biblio_item in db["biblio"]: |
| 23 | + reference, contents = biblio_item_to_biblio(biblio_item) |
| 24 | + biblio[reference] = contents |
| 25 | + |
| 26 | + string = json.dumps(biblio, ensure_ascii=False, allow_nan=False, sort_keys=True, indent=2) |
| 27 | + return string + "\n" |
| 28 | + |
| 29 | +def standard_or_idea_to_biblio(document): |
| 30 | + return (document["reference"], { |
| 31 | + "authors": [author_to_biblio(author) for author in document["authors"]], |
| 32 | + "href": document["href"], |
| 33 | + "title": document["name"] |
| 34 | + }) |
| 35 | + |
| 36 | +def biblio_item_to_biblio(item): |
| 37 | + contents = { |
| 38 | + "href": item["href"], |
| 39 | + "title": item["title"] |
| 40 | + } |
| 41 | + if len(item["authors"]): |
| 42 | + contents["authors"] = [author_to_biblio(author) for author in item["authors"]] |
| 43 | + if "obsoletedBy" in item: |
| 44 | + contents["obsoletedBy"] = item["obsoletedBy"] |
| 45 | + return (item["reference"], contents) |
| 46 | + |
| 47 | +def author_to_biblio(person): |
| 48 | + return person["name"] |
| 49 | + |
| 50 | + |
| 51 | +def create_spec_whatwg_org(db, template): |
| 52 | + content = "<p>The WHATWG works on a number of technologies that are fundamental parts of the web platform. They are organised somewhat arbitrarily based on the preferences of those editing the standard for those technologies.</p>\n\n" |
| 53 | + content += "<dl>" |
| 54 | + for workstream in db["workstreams"]: |
| 55 | + for standard in workstream["standards"]: |
| 56 | + content += standard_or_idea_to_html(standard) |
| 57 | + content += "</dl>\n\n<p>The WHATWG also works on a <a href=\"https://idea.whatwg.org/\">number of ideas</a> that aspire to become standards one day.</p>\n\n" |
| 58 | + |
| 59 | + template = template.replace("<a href=\"https://spec.whatwg.org/\">Standards</a>", "<a>Standards</a>") |
| 60 | + return wrap_in_site_template(template, "Standards", content) |
| 61 | + |
| 62 | +def create_idea_whatwg_org(db, template): |
| 63 | + content = "<p>The WHATWG works on a number of ideas that aspire to become web platform standards.</p>\n\n" |
| 64 | + content += "<dl>" |
| 65 | + for idea in db["ideas"]: |
| 66 | + content += standard_or_idea_to_html(idea) |
| 67 | + content += "</dl>\n\n" |
| 68 | + |
| 69 | + return wrap_in_site_template(template, "Ideas", content) |
| 70 | + |
| 71 | +def standard_or_idea_to_html(document): |
| 72 | + output = "\n <dt><a href=\"{0}\">{1}</a></dt>".format(document["href"], document["name"]) |
| 73 | + return output + "\n <dd>{}</dd>\n".format(markdown(document["description"])[:-1]) # Strip trailing \n |
| 74 | + |
| 75 | + |
| 76 | +def create_workstreams(db, template): |
| 77 | + introduction = open("sg/Workstreams Introduction.md", "r", encoding="utf-8").read() |
| 78 | + introduction = introduction.replace("<!-- This ends up being included at https://whatwg.org/workstreams -->\n", "") |
| 79 | + content = markdown(introduction, obtain_link_mapping()) |
| 80 | + for workstream in db["workstreams"]: |
| 81 | + content += "\n<h3>{}</h3>".format(workstream["name"]) |
| 82 | + content += """\n<dl class="compact">""" |
| 83 | + content += "\n <div>" |
| 84 | + content += "\n <dt>Scope</dt>" |
| 85 | + content += "\n <dd>{}</dd>".format(markdown(workstream["scope"])[3:-5]) # Strip leading <p> and trailing </p>\n |
| 86 | + content += "\n </div>" |
| 87 | + content += "\n <div>" |
| 88 | + content += "\n <dt>Editor{}</dt>".format("" if len(workstream["editors"]) == 1 else "s") |
| 89 | + for editor in workstream["editors"]: |
| 90 | + content += """\n <dd>{0}, <a href="mailto:{1}">{1}</a></dd>""".format(editor["name"], editor["email"]) |
| 91 | + content += "\n </div>" |
| 92 | + content += "\n <div>" |
| 93 | + content += "\n <dt>Standard{}</dt>".format("" if len(workstream["standards"]) == 1 else "s") |
| 94 | + for standard in workstream["standards"]: |
| 95 | + content += """\n <dd><a href="{0}">{1}</a></dd>""".format(standard["href"], standard["name"]) |
| 96 | + content += "\n </div>" |
| 97 | + content += "\n</dl>" |
| 98 | + |
| 99 | + return wrap_in_site_template(template, "Workstreams", content) |
| 100 | + |
| 101 | + |
| 102 | +def wrap_in_site_template(template, title, content): |
| 103 | + output = template.replace("@TITLE_GOES_HERE@", title) |
| 104 | + return output.replace("@CONTENT_GOES_HERE@", content) |
| 105 | + |
| 106 | +def main(): |
| 107 | + template = open("site-template.html", "r", encoding="utf-8").read() |
| 108 | + copyright = """<footer> |
| 109 | + <p><small>Copyright © {} WHATWG (Apple, Google, Mozilla, Microsoft). This work is licensed under a <a rel="license" href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.</small></p> |
| 110 | +</footer>""".format(str(date.today().year)) |
| 111 | + template = template.replace("@CONTENT_GOES_HERE@", "@CONTENT_GOES_HERE@" + copyright) |
| 112 | + db = json.load(open("sg/db.json", "r", encoding="utf-8")) |
| 113 | + |
| 114 | + for filename, content in [ |
| 115 | + ("resources.whatwg.org/biblio.json", create_biblio(db)), |
| 116 | + ("spec.whatwg.org/index.html", create_spec_whatwg_org(db, template)), |
| 117 | + ("idea.whatwg.org/index.html", create_idea_whatwg_org(db, template)), |
| 118 | + ("whatwg.org/workstreams", create_workstreams(db, template)) |
| 119 | + ]: |
| 120 | + open(filename, "w", encoding="utf-8").write(content) |
| 121 | + |
| 122 | +main() |
0 commit comments