mirror of
https://github.com/TinyTapeout/tt-support-tools.git
synced 2026-11-03 04:36:09 +01:00
fix(website): images missing from website
TinyTapeout/tinytapeout_www#84
This commit is contained in:
+6
-1
@@ -9,7 +9,7 @@ import git # type: ignore
|
|||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from git_utils import get_first_remote
|
from git_utils import get_first_remote
|
||||||
from markdown_utils import rewrite_image_paths
|
from markdown_utils import rewrite_image_paths, rewrite_image_paths_for_website
|
||||||
from project import Project
|
from project import Project
|
||||||
|
|
||||||
|
|
||||||
@@ -175,6 +175,11 @@ class Docs:
|
|||||||
yaml_data["weight"] = project.index + 1
|
yaml_data["weight"] = project.index + 1
|
||||||
yaml_data["git_action"] = project.get_workflow_url_when_submitted()
|
yaml_data["git_action"] = project.get_workflow_url_when_submitted()
|
||||||
yaml_data["shuttle_id"] = self.config["id"]
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
doc = doc_template.format(**yaml_data)
|
doc = doc_template.format(**yaml_data)
|
||||||
with open(os.path.join(project_dir, "_index.md"), "w") as pfh:
|
with open(os.path.join(project_dir, "_index.md"), "w") as pfh:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
import mistune
|
import mistune
|
||||||
@@ -42,3 +43,34 @@ class ImagePathRewriterRenderer(MarkdownRenderer):
|
|||||||
def rewrite_image_paths(source: str, prefix: str) -> str:
|
def rewrite_image_paths(source: str, prefix: str) -> str:
|
||||||
markdown = mistune.create_markdown(renderer=ImagePathRewriterRenderer(prefix))
|
markdown = mistune.create_markdown(renderer=ImagePathRewriterRenderer(prefix))
|
||||||
return markdown(source)
|
return markdown(source)
|
||||||
|
|
||||||
|
|
||||||
|
class WebsiteImagePathRewriterRenderer(MarkdownRenderer):
|
||||||
|
def __init__(self, source_dir: str, target_dir: str):
|
||||||
|
super().__init__()
|
||||||
|
self.source_dir = source_dir
|
||||||
|
self.target_dir = target_dir
|
||||||
|
|
||||||
|
def image(self, token, state):
|
||||||
|
url = token["attrs"]["url"]
|
||||||
|
if ".." in url:
|
||||||
|
token["attrs"]["url"] = ""
|
||||||
|
elif "://" not in url and not url.startswith("/"):
|
||||||
|
filename = os.path.basename(url)
|
||||||
|
if url.startswith("/"):
|
||||||
|
url = "../" + url[1:]
|
||||||
|
shutil.copyfile(
|
||||||
|
os.path.join(self.source_dir, url),
|
||||||
|
os.path.join(self.target_dir, filename),
|
||||||
|
)
|
||||||
|
token["attrs"]["url"] = f"images/{filename}"
|
||||||
|
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 markdown(source)
|
||||||
|
|||||||
Reference in New Issue
Block a user