Skip to content

Instantly share code, notes, and snippets.

@Thesola10
Created May 18, 2021 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thesola10/a071e2da6281dba40aeff13ffd730589 to your computer and use it in GitHub Desktop.
Save Thesola10/a071e2da6281dba40aeff13ffd730589 to your computer and use it in GitHub Desktop.
Generate a static redirect page. Can be useful on IPFS for link shortening for instance.
#!/usr/bin/env python3
# mk302 by Karim Vergnes <me@thesola.io>
# License: CC0 1.0 Universal
# Requires Jinja2
'''<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="REFRESH" content="0;url={{ href }}"" />
<script>window.location.href="{{ href }}"</script>
<title>Redirecting...</title>
</head>
<body>
<h1>Redirecting...</h1>
<p>This page redirects to <a href="{{ href }}">{{ href }}</a>.</p>
</body>
</html>'''
if __name__ == "__main__":
import sys
from jinja2 import Template
if len(sys.argv) != 2:
print("Usage: %s <url>" %sys.argv[0])
sys.exit(1)
template = Template(__doc__)
result = template.render(href=sys.argv[1])
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment