From 934533e971b1bfd702c9fb54ef3e3b60f5fa135b Mon Sep 17 00:00:00 2001 From: matekelemen Date: Wed, 7 Aug 2024 11:45:41 +0200 Subject: [PATCH] fix readme for doxygen --- docs/.gitignore | 1 + docs/prepareDocs.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 docs/prepareDocs.py diff --git a/docs/.gitignore b/docs/.gitignore index 70f9068..9a0c12e 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,3 +1,4 @@ !.gitignore !doxyfile !doxygen-awesome.css +!prepareDocs.py diff --git a/docs/prepareDocs.py b/docs/prepareDocs.py new file mode 100644 index 0000000..c338f82 --- /dev/null +++ b/docs/prepareDocs.py @@ -0,0 +1,40 @@ +# The main readme.md at the repository's root is used as the landing +# page of the doxygen documentation, which becomes an issue when +# resolving links (github vs local docs). This script creates a +# separate readme.md for doxygen and replaces the links to point to +# local or github links, depending in the provided arguments. + +# --- STD Imports --- +import pathlib +import re +import argparse + + +parser = argparse.ArgumentParser("prepareDocs") +parser.add_argument("-w", + dest = "web", + action = "store_const", + const = True, + default = False, + help = "prepare docs for the web") +arguments = parser.parse_args() + +rootPath = "https://matekelemen.github.io/mcgs/" if arguments.web else "../../" +docPath = rootPath + "docs/html/" +assetPath = rootPath + ".github/assets/" + +docLinkPattern = re.compile(r"\[mcgs::(\w+)\]\(([\w0-9\.#]+)\)") +docLinkReplace = r"[mcgs::\1](" + docPath + r"\2)" +assetLinkPattern = re.compile(r"\.github/assets/") +assetLinkReplace = assetPath + +readme = "" +with open(pathlib.Path(__file__).absolute().parent.parent / "readme.md", "r") as inputFile: + readme = inputFile.read() + +with open(pathlib.Path(__file__).parent / "readme.md", "w") as outputFile: + outputFile.write(re.sub(assetLinkPattern, + assetLinkReplace, + re.sub(docLinkPattern, + docLinkReplace, + readme)))