Files
anki/docs/cogdocs.py
Luc Mcgrady 7cf1d29896 docs: Replace docs/ with symlinks (#5031)
<!--
Title (for the Pull Request title field at the top):
Use a short prefix so the change type is obvious. You do not need to
repeat it in the body below.

Examples:
- fix: — bugfix
- feat: — feature
- refactor: — internal change without user-facing feature
- docs: — documentation only
- chore: — tooling, CI, deps, build housekeeping
- test: — tests only
-->

## Linked issue (required)

<!-- Fixes #123 / Closes #123 / Refs #123 -->
closes #5001

This PR replaces the contents of `docs/` with symlinks to
`docs-site/developers/`

A caveat of this is that the metadata appears at the top of the file
instead of the title.
<img width="885" height="275" alt="image"
src="https://github.com/user-attachments/assets/430f9a71-e5a5-4412-983a-e4cfd7dc4714"
/>

We could either:
- Use ninja to copy the files from docs-site/developers and convert it
from .mdx to .md (Might be a problem with the symlink approach if mdx is
added to the contributor file later)
- Leave placeholder "For contribution instructions see: (link to
mintlify site)"s in the folder, which would have to wait until the
domain of the site is set. (Probably the best solution).

---------

Co-authored-by: Abdo <abdo@abdnh.net>
2026-08-04 22:01:31 +03:00

31 lines
1.2 KiB
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import re
ANKI_DOCS_URL = "https://anki.mintlify.app"
def get_file_contents(file_path):
file_path = f"docs-site/developers/{file_path}.mdx"
with open(file_path, "r", encoding="utf-8") as f:
text = "".join(f.readlines()[3:]) + "\n" # Skip the first three lines (front matter)
def rewrite_link(match):
target = match.group(1)
# Keep already-absolute links untouched.
if re.match(r"^[a-zA-Z][a-zA-Z0-9+.-]*:", target):
return f"]({target})"
# Resolve same-page anchors against the current document.
if target.startswith("#"):
target = f"/{file_path.split('/')[-1].removesuffix('.mdx')}{target}"
elif target.startswith("./"):
target = target[1:]
elif not target.startswith("/"):
target = f"/{target}"
return f"]({ANKI_DOCS_URL}{target})"
# Convert relative links to absolute links.
text = re.sub(r"\]\(([^)]+)\)", rewrite_link, text)
return text