Skip to content

A programming framework for agentic AI

Add redirects for old website URLs

Jack Gerrits4ea1f7a8b31e
diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index aace3556c..230a6ce66 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -43,6 +43,9 @@ jobs:
mkdir -p docs-staging/dev
mv ./packages/autogen-core/docs/build/* docs-staging/dev/
working-directory: ./python
+ - name: generate redirects
+ run: |
+ python python/packages/autogen-core/docs/redirects/redirects.py python/docs-staging
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
diff --git a/python/packages/autogen-core/docs/redirects/redirect_template.html b/python/packages/autogen-core/docs/redirects/redirect_template.html
new file mode 100644
index 000000000..b16e78800
--- /dev/null
+++ b/python/packages/autogen-core/docs/redirects/redirect_template.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Redirecting...</title>
+ <meta http-equiv="refresh" content="0; url=$to_url">
+ <!-- JavaScript redirect as a fallback -->
+ <script type="text/javascript">
+ setTimeout(function() {
+ window.location.href = "$to_url";
+ }, 0);
+ </script>
+</head>
+<body>
+ <p>If you are not redirected automatically, follow this <a href="$to_url">link to example.com</a>.</p>
+ <!-- noscript fallback for users with JavaScript disabled -->
+ <noscript>
+ <meta http-equiv="refresh" content="0; url=$to_url">
+ <p>If you are not redirected automatically, follow this <a href="$to_url">link to example.com</a>.</p>
+ </noscript>
+</body>
+</html>
\ No newline at end of file
diff --git a/python/packages/autogen-core/docs/redirects/redirects.py b/python/packages/autogen-core/docs/redirects/redirects.py
new file mode 100644
index 000000000..a12ac2382
--- /dev/null
+++ b/python/packages/autogen-core/docs/redirects/redirects.py
@@ -0,0 +1,43 @@
+from pathlib import Path
+from string import Template
+import sys
+
+THIS_FILE_DIR = Path(__file__).parent
+
+
+# Contains single text template $to_url
+HTML_PAGE_TEMPLATE_FILE = THIS_FILE_DIR / "redirect_template.html"
+HTML_REDIRECT_TEMPLATE = HTML_PAGE_TEMPLATE_FILE.open("r").read()
+
+def generate_redirect(old_url: str, new_url: str, base_dir: Path):
+ # Create a new redirect page
+ redirect_page = Template(HTML_REDIRECT_TEMPLATE).substitute(to_url=new_url)
+
+ # If the url ends with /, add index.html
+ if old_url.endswith("/"):
+ old_url += "index.html"
+
+ if old_url.startswith("/"):
+ old_url = old_url[1:]
+
+ # Create the path to the redirect page
+ redirect_page_path = base_dir / old_url
+
+ # Create the directory if it doesn't exist
+ base_dir.mkdir(parents=True, exist_ok=True)
+
+ # Write the redirect page
+ with open(redirect_page_path, "w") as f:
+ f.write(redirect_page)
+
+
+def main():
+ if len(sys.argv) != 2:
+ print("Usage: python redirects.py <base_dir>")
+ sys.exit(1)
+
+ base_dir = Path(sys.argv[1])
+ generate_redirect("/", "/0.2/", base_dir)
+
+if __name__ == '__main__':
+ main()
\ No newline at end of file