From 54f5cdcfd98aac3add7182b168fb0fbe03ba81ef Mon Sep 17 00:00:00 2001 From: obsidianforensics Date: Thu, 27 Jun 2024 16:31:47 +0000 Subject: [PATCH] Add function for generating Scenario sitemap Markdown --- dfiq/dfiq.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/dfiq/dfiq.py b/dfiq/dfiq.py index 954f60c..437d525 100644 --- a/dfiq/dfiq.py +++ b/dfiq/dfiq.py @@ -235,6 +235,8 @@ def __init__( } self.components = {} self.graph = None + self.templates_path = Path(templates_path) + logging.debug(f'"templates_path" set to "{self.templates_path.resolve()}"') self.jinja_env = jinja2.Environment( loader=jinja2.FileSystemLoader(templates_path), trim_blocks=True ) @@ -584,6 +586,27 @@ def write_content_to_file(content: str, file_path: Path) -> None: output_file.parent.mkdir(exist_ok=True, parents=True) output_file.write_text(content, encoding="utf-8") + def generate_scenario_sitemap_md(self, allow_internal: bool = False) -> None: + """Generates a Markdown sitemap for the Scenarios. + + Args: + allow_internal (bool): Check if generating internal items is allowed. + """ + if not self.markdown_output_path: + raise ValueError("Markdown output path not specified") + + template = self.jinja_env.get_template("scenario_sitemap.jinja2") + context = { + "components": self.components, + "allow_internal": allow_internal, + } + + content = template.render(context) + output_path = Path(self.markdown_output_path, "scenarios", "sitemap.md") + output_file = Path(output_path) + output_file.parent.mkdir(exist_ok=True, parents=True) + output_file.write_text(content, encoding="utf-8") + def generate_question_index_md(self, allow_internal: bool = False) -> None: """Generates Markdown for the index page listing all Questions. @@ -632,7 +655,7 @@ def generate_approach_glossary_md(self, allow_internal: bool = False) -> None: for step in analysis["steps"]: analysis_step_types.add(step["type"]) - m = re.findall(r"\{.*?\}", step["value"]) + m = re.findall(r"\{[A-z0-9_ -]{2,}?\}", step["value"]) if m: step_variables.update(m)