Skip to content

Commit

Permalink
[docusaurus] Also resolve iframe links inside Markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
VladNastase committed Sep 21, 2023
1 parent 9a5dc27 commit a1bccaf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions openedu_builder/plugins/docusaurus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import logging
import os
import re
Expand Down Expand Up @@ -321,6 +322,7 @@ def _resolve_links(self):
log.debug(dst_to_src)

md_link_regex = re.compile(r"\[.*?\]\((\.(?:\.)?\/.*?)\)")
iframe_link_regex = re.compile(r"<iframe.*?src=\"(\.(?:\.)?\/.*?)\".*?>")

dst_files = []

Expand Down Expand Up @@ -363,7 +365,10 @@ def _walk_struct(structure):
with open(_file, "r") as f:
content = f.read()

for match in re.finditer(md_link_regex, content):
for match in itertools.chain(
re.finditer(md_link_regex, content),
re.finditer(iframe_link_regex, content),
):
src_link = match.group(1)
log.info(f"Found link {src_link}")
# dst_link = src_to_dst[path_utils.real_join(src_dir, src_link)]
Expand Down Expand Up @@ -432,7 +437,7 @@ def run(self):
log.error(f"Command {self.init_command} failed with code {p.returncode}")
log.error(f"STDOUT: {p.stdout.decode('utf-8')}")
log.error(f"STDERR: {p.stderr.decode('utf-8')}")
raise PluginRunError(f"Error while running init command")
raise PluginRunError("Error while running init command")

# Folders we need to delete:
# - blog
Expand Down Expand Up @@ -490,16 +495,14 @@ def run(self):
log.error(f"Command {math_command} failed with code {p.returncode}")
log.error(f"STDOUT: {p.stdout.decode('utf-8')}")
log.error(f"STDERR: {p.stderr.decode('utf-8')}")
raise PluginRunError(
f"Error while installing math dependencies command"
)
raise PluginRunError("Error while installing math dependencies command")

p = subprocess.run(self.build_command, capture_output=True)
if p.returncode != 0:
log.error(f"Command {self.build_command} failed with code {p.returncode}")
log.error(f"STDOUT: {p.stdout.decode('utf-8')}")
log.error(f"STDERR: {p.stderr.decode('utf-8')}")
raise PluginRunError(f"Error while running build command")
raise PluginRunError("Error while running build command")

# os.mkdir(path_utils.real_join(self.output_dir, "output"))
if not self.config.get("debug", False):
Expand Down

0 comments on commit a1bccaf

Please sign in to comment.