Skip to content

Commit

Permalink
cleanup(website): remove hugo related functionality
Browse files Browse the repository at this point in the history
Project pages are now dynamically generated based on the shuttle index.
  • Loading branch information
urish committed Jul 16, 2024
1 parent 63eb3d5 commit 3c88e6e
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 175 deletions.
7 changes: 0 additions & 7 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ def build_metrics(self):
"--dump-markdown", help="dump markdown of all project data to given file"
)
parser.add_argument("--dump-pdf", help="create pdf from the markdown")
parser.add_argument(
"--build-hugo-content", help="directory to where to build hugo content"
)
parser.add_argument(
"--metrics", help="print some project metrics", action="store_const", const=True
)
Expand Down Expand Up @@ -330,7 +327,3 @@ def build_metrics(self):
if args.dump_markdown:
shuttle.configure_mux()
docs.write_datasheet(args.dump_markdown, args.dump_pdf)

if args.build_hugo_content:
shuttle.configure_mux()
docs.build_hugo_content(args.build_hugo_content)
26 changes: 0 additions & 26 deletions docs/hugo_index_template.md.mustache

This file was deleted.

39 changes: 0 additions & 39 deletions docs/hugo_template.md.mustache

This file was deleted.

92 changes: 1 addition & 91 deletions documentation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
import shutil
import subprocess
from typing import List, Optional

Expand All @@ -10,7 +9,7 @@

from config import Config
from git_utils import get_first_remote
from markdown_utils import rewrite_image_paths, rewrite_image_paths_for_website
from markdown_utils import rewrite_image_paths
from project import Project


Expand Down Expand Up @@ -161,92 +160,3 @@ def write_datasheet(self, markdown_file: str, pdf_file: Optional[str] = None):
if p.returncode != 0:
logging.error("pdf generation failed")
raise RuntimeError(f"pdf generation failed with code {p.returncode}")

def build_hugo_content(self, hugo_root: str) -> None:
hugo_images = os.path.join(hugo_root, "images")
shutil.rmtree(hugo_root)
os.makedirs(hugo_root)
os.makedirs(hugo_images)

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.mustache")
) as fh:
index_template = fh.read()

# copy image
# TODO, need to get image from somewhere
# shutil.copyfile(
# "tt/docs/pics/tinytapeout_numbered.png",
# os.path.join(hugo_images, f'tinytapeout-{self.config["id"]}.png'),
# )

# 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"],
"project_count": len(self.projects),
"end_date": self.config["end_date"],
}
with open(os.path.join(hugo_root, "_index.md"), "w") as fh:
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")
self.projects.sort(key=lambda x: x.mux_address)
for project in self.projects:
logging.info(project)
fh.write(project.get_hugo_row())

project_dir = os.path.join(hugo_root, f"{project.mux_address :03}")
project_image_dir = os.path.join(project_dir, "images")
os.makedirs(project_dir)
os.makedirs(project_image_dir)
yaml_data = project.get_project_docs_dict()
analog_pins = project.info.analog_pins
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)
],
"analog_pins": [
{
"ua_index": str(i),
"analog_index": str(project.analog_pins[i]),
"desc": desc,
}
for i, desc in enumerate(
project.info.pinout.ua[:analog_pins]
)
],
"is_analog": analog_pins > 0,
}
)

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)
9 changes: 0 additions & 9 deletions markdown_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,3 @@ def image(self, token, state):
url = f"images/{filename}"
token["attrs"]["url"] = url
return super().image(token, state)


def rewrite_image_paths_for_website(
source: str, source_dir: str, target_dir: str
) -> str:
markdown = mistune.create_markdown(
renderer=WebsiteImagePathRewriterRenderer(source_dir, target_dir)
)
return unescape_braces(markdown(source))
3 changes: 0 additions & 3 deletions project.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ def check_num_cells(self):
if num_cells < 11:
logging.warning(f"{self} only has {num_cells} cells")

def get_hugo_row(self) -> str:
return f"| {self.mux_address} | [{self.info.title}]({self.mux_address :03}) | {self.info.author}|\n"

# docs stuff for index on README.md
def get_index_row(self):
return f"| {self.mux_address} | {self.info.author} | {self.info.title} | {self.get_project_type_string()} | {self.git_url} |\n"
Expand Down

0 comments on commit 3c88e6e

Please sign in to comment.