From 2246e7882a31422e401a03e8548991dde539d1ee Mon Sep 17 00:00:00 2001 From: htfab Date: Mon, 6 May 2024 14:09:45 +0200 Subject: [PATCH] feat(datasheet): use mustache for hugo_template --- ...ate.md => hugo_index_template.md.mustache} | 8 ++-- docs/hugo_template.md | 34 -------------- docs/hugo_template.md.mustache | 29 ++++++++++++ documentation.py | 44 +++++++++++++------ 4 files changed, 64 insertions(+), 51 deletions(-) rename docs/{hugo_index_template.md => hugo_index_template.md.mustache} (79%) delete mode 100644 docs/hugo_template.md create mode 100644 docs/hugo_template.md.mustache diff --git a/docs/hugo_index_template.md b/docs/hugo_index_template.md.mustache similarity index 79% rename from docs/hugo_index_template.md rename to docs/hugo_index_template.md.mustache index 2fa55a5..f5076f0 100644 --- a/docs/hugo_index_template.md +++ b/docs/hugo_index_template.md.mustache @@ -1,10 +1,10 @@ --- -title: "{shuttle_name}" +title: "{{shuttle_name}}" weight: 50 -description: {project_count} designs, closed {end_date} +description: {{project_count}} designs, closed {{end_date}} --- -{{{{% toc %}}}} +{{#hugo}}% toc %{{/hugo}} # Design details @@ -22,5 +22,5 @@ description: {project_count} designs, closed {end_date} # Chip map -{{{{< shuttle-map "{shuttle_id}" >}}}} +{{#hugo}}< shuttle-map "{shuttle_id}" >{{/hugo}} diff --git a/docs/hugo_template.md b/docs/hugo_template.md deleted file mode 100644 index 78da27c..0000000 --- a/docs/hugo_template.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -hidden: true -title: "{mux_address} {title}" -weight: {weight} ---- - -## {mux_address} : {title} - -* Author: {author} -* Description: {description} -* [GitHub repository]({git_url}) -* [GDS submitted]({git_action}) -* {project_type} project -* [Extra docs]({doc_link}) -* Clock: {clock_hz} Hz - -{user_docs} - -### IO - -| # | Input | Output | Bidirectional | -| - | -------------- | -------------- | --------------- | -| 0 | {pinout.ui[0]} | {pinout.uo[0]} | {pinout.uio[0]} | -| 1 | {pinout.ui[1]} | {pinout.uo[1]} | {pinout.uio[1]} | -| 2 | {pinout.ui[2]} | {pinout.uo[2]} | {pinout.uio[2]} | -| 3 | {pinout.ui[3]} | {pinout.uo[3]} | {pinout.uio[3]} | -| 4 | {pinout.ui[4]} | {pinout.uo[4]} | {pinout.uio[4]} | -| 5 | {pinout.ui[5]} | {pinout.uo[5]} | {pinout.uio[5]} | -| 6 | {pinout.ui[6]} | {pinout.uo[6]} | {pinout.uio[6]} | -| 7 | {pinout.ui[7]} | {pinout.uo[7]} | {pinout.uio[7]} | - -### Chip location - -{{{{< shuttle-map "{shuttle_id}" "{mux_address}" >}}}} diff --git a/docs/hugo_template.md.mustache b/docs/hugo_template.md.mustache new file mode 100644 index 0000000..ddbf547 --- /dev/null +++ b/docs/hugo_template.md.mustache @@ -0,0 +1,29 @@ +--- +hidden: true +title: "{{mux_address}} {{title}}" +weight: {{weight}} +--- + +## {{mux_address}} : {{title}} + +* Author: {{author}} +* Description: {{&description}} +* [GitHub repository]({{git_url}}) +* [GDS submitted]({{git_action}}) +* {{project_type}} project +* [Extra docs]({{doc_link}}) +* Clock: {{clock_hz}} Hz + +{{&user_docs}} + +### IO + +| # | Input | Output | Bidirectional | +| ------------- | -------- | -------- | --------------- | +{{#pins}} +| {{pin_index}} | {{&ui}} | {{&uo}} | {{&uio[0]}} | +{{/pins}} + +### Chip location + +{{#hugo}}< shuttle-map "{{shuttle_id}}" "{{mux_address}}" >{{/hugo}} diff --git a/documentation.py b/documentation.py index 7514299..87ad5c4 100644 --- a/documentation.py +++ b/documentation.py @@ -152,11 +152,13 @@ class Docs: os.makedirs(hugo_root) os.makedirs(hugo_images) - with open(os.path.join(self.script_dir, "docs", "hugo_template.md")) as fh: + with open( + os.path.join(self.script_dir, "docs", "hugo_template.md.mustache") + ) as fh: doc_template = fh.read() with open( - os.path.join(self.script_dir, "docs", "hugo_index_template.md") + os.path.join(self.script_dir, "docs", "hugo_index_template.md.mustache") ) as fh: index_template = fh.read() @@ -169,6 +171,7 @@ class Docs: # index page logging.info("building pages") + hugo_tag = {"hugo": lambda text, render: "{{" + render(text) + "}}"} shuttle_info = { "shuttle_name": self.config["name"], "shuttle_id": self.config["id"], @@ -176,7 +179,8 @@ class Docs: "end_date": self.config["end_date"], } with open(os.path.join(hugo_root, "_index.md"), "w") as fh: - fh.write(index_template.format(**shuttle_info)) + shuttle_info.update(hugo_tag) + fh.write(chevron.render(index_template, shuttle_info)) fh.write("# All projects\n") fh.write("| Index | Title | Author |\n") fh.write("| ----- | ----- | -------|\n") @@ -190,17 +194,31 @@ class Docs: os.makedirs(project_dir) os.makedirs(project_image_dir) yaml_data = project.get_project_docs_dict() - yaml_data["mux_address"] = project.mux_address - yaml_data["index"] = project.index - yaml_data["weight"] = project.index + 1 - yaml_data["git_action"] = project.get_workflow_url_when_submitted() - yaml_data["shuttle_id"] = self.config["id"] - yaml_data["user_docs"] = rewrite_image_paths_for_website( - yaml_data["user_docs"], - os.path.join(project.src_dir, "docs"), - project_image_dir, + yaml_data.update( + { + "mux_address": project.mux_address, + "index": project.index, + "weight": project.index, + "git_action": project.get_workflow_url_when_submitted(), + "shuttle_id": self.config["id"], + "user_docs": rewrite_image_paths_for_website( + yaml_data["user_docs"], + os.path.join(project.src_dir, "docs"), + project_image_dir, + ), + "pins": [ + { + "pin_index": str(i), + "ui": project.info.pinout.ui[i], + "uo": project.info.pinout.uo[i], + "uio": project.info.pinout.uio[i], + } + for i in range(8) + ], + } ) - doc = doc_template.format(**yaml_data) + yaml_data.update(hugo_tag) + doc = chevron.render(doc_template, yaml_data) with open(os.path.join(project_dir, "_index.md"), "w") as pfh: pfh.write(doc)