mirror of https://github.com/microsoft/autogen.git
Add redirects for old website URLs
This commit is contained in:
parent
1dc91bddd2
commit
4ea1f7a8b3
|
@ -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:
|
||||
|
|
|
@ -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>
|
|
@ -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()
|
Loading…
Reference in New Issue