diff --git a/docs/pylib/copy_from_wiki.py b/docs/pylib/copy_from_wiki.py index 933cdb15d3..0a8ff8cc22 100644 --- a/docs/pylib/copy_from_wiki.py +++ b/docs/pylib/copy_from_wiki.py @@ -17,6 +17,7 @@ import glob import re _RE_MD_LINK = re.compile(r"\[(?P[\w -\[\]]+?)\]\((?P.+?)\)", re.I + re.S + re.U) +_RE_REF_LINK = re.compile(r"\[[\w -\[\]]+?\]\(.+?\)", re.I + re.S + re.U) _IGNORE_FILES = ( "_Sidebar.md", @@ -55,6 +56,16 @@ _CUSTOM_LINK_REMAP = { "Adding-Object-Typeclass-tutorial": "Adding-Object-Typeclass-Tutorial", "EvTable": _API_PREFIX + "evennia.utils#module-evennia.utils.evtable", } +# complete reference remaps +_REF_REMAP = { + "[![Getting Started][icon_new]](Getting-Started)": "![Getting Started][icon_new]", + "[![Admin Docs][icon_admin]](Administrative-Docs)": "![Admin Docs][icon_admin]", + "[![Builder Docs][icon_builder]](Builder-Docs)": "![Builder Docs][icon_builder]", + "[![Developer-Central][icon_devel]](Developer-Central)": "![Developer-Central][icon_devel]", + "[![tutorial][icon_tutorial]](Tutorials)": "![Tutorials][icon_tutorial]", + "[![API][icon_api]](evennia)": "![API][icon_api]", +} + # absolute links (mainly github links) that should not be converted. This # should be given without any #anchor. @@ -82,6 +93,17 @@ _REF_SKIP = ( _CURRENT_TITLE = "" + +def _sub_remap(match): + """Total remaps""" + ref = match.group(0) + if ref in _REF_REMAP: + new_ref = _REF_REMAP[ref] + print(f" Replacing reference {ref} -> {new_ref}") + return new_ref + return ref + + def _sub_link(match): mdict = match.groupdict() @@ -92,6 +114,7 @@ def _sub_link(match): # return "" print(f" [{txt}]({url})") + url = _CUSTOM_LINK_REMAP.get(url, url) url, *anchor = url.rsplit("#", 1) @@ -168,6 +191,9 @@ def create_toctree(files): ref = filename.rsplit(".", 1)[0] linkname = ref.replace("-", " ") + if ref == "Home": + ref = "index" + fil.write(f"\n* [{linkname}]({ref}.md)") def convert_links(files, outdir): @@ -186,6 +212,7 @@ def convert_links(files, outdir): with open(inpath) as fil: text = fil.read() _CURRENT_TITLE = title.replace(" ", "-") + text = _RE_REF_LINK.sub(_sub_remap, text) text = _RE_MD_LINK.sub(_sub_link, text) text = text.split('\n')[1:] if text.split('\n')[0].strip().startswith('[]') else text.split('\n') text = f"# {title}\n\n" + '\n'.join(text) diff --git a/docs/source/conf.py b/docs/source/conf.py index 53d10b7412..c0293faad5 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -163,9 +163,11 @@ def url_resolver(url): elif url.startswith(urlstart): return _github_code_root + url[len(urlstart):] elif url.startswith(apistart): + print("api: -> api ref") return "api/" + url[len(apistart):] + ".html" - else: - return _github_doc_root + url + return url + # else: + # return _github_doc_root + url # auto-create TOCs if a list of links is under these headers diff --git a/docs/source/index.md b/docs/source/index.md index 8bb0bc6892..8ccdb87d45 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -11,7 +11,8 @@ suggestion box][form]! There is [a lengthier introduction](Evennia-Introduction) to read. You might also want to read about [how to get and give help](How-To-Get-And-Give-Help). -| [![Getting Started][icon_new]](Getting-Started)| [![Admin Docs][icon_admin]](Administrative-Docs) | [![Builder Docs][icon_builder]](Builder-Docs) | [![Developer-Central][icon_devel]](Developer-Central) | [![tutorial][icon_tutorial]](Tutorials) | [![API][icon_API]](api:evennia) | + +| ![Getting Started][icon_new]| ![Admin Docs][icon_admin] | ![Builder Docs][icon_builder] | ![Developer-Central][icon_devel] | ![Tutorials][icon_tutorial] | [![API][icon_API]](api:evennia) | |-----------------|----------------------|--------------------------|----------------------|----------------------------|--------------------| |[Getting Started](Getting-Started)| [Admin Docs](Administrative-Docs) | [Builder Docs](Builder-Docs) | [Developer Central](Developer-Central) | [Tutorials & Examples](Tutorials) | [API](api:evennia) | diff --git a/docs/source/toc.md b/docs/source/toc.md index 2b2603d4e9..2fd487d440 100644 --- a/docs/source/toc.md +++ b/docs/source/toc.md @@ -69,7 +69,7 @@ * [HAProxy Config (Optional)](HAProxy-Config-(Optional).md) * [Help System Tutorial](Help-System-Tutorial.md) * [Help System](Help-System.md) -* [Home](Home.md) +* [Home](index.md) * [How To Get And Give Help](How-To-Get-And-Give-Help.md) * [How to connect Evennia to Twitter](How-to-connect-Evennia-to-Twitter.md) * [IRC](IRC.md)