Add tutorial redirect

This commit is contained in:
Ivan Blinkov 2020-01-29 23:27:36 +03:00
parent efedfcdfd5
commit 223704ee9c

View File

@ -196,19 +196,9 @@ def build_single_page_version(lang, args, cfg):
shutil.copytree(test_dir, args.save_raw_single_page) shutil.copytree(test_dir, args.save_raw_single_page)
def build_redirect_html(args, from_path, to_path): def write_redirect_html(out_path, to_url):
for lang in args.lang.split(','): with open(out_path, 'w') as f:
out_path = os.path.join(args.docs_output_dir, lang, from_path.replace('.md', '/index.html')) f.write('''<!DOCTYPE HTML>
out_dir = os.path.dirname(out_path)
try:
os.makedirs(out_dir)
except OSError:
pass
version_prefix = args.version_prefix + '/' if args.version_prefix else '/'
to_url = '/docs%s%s/%s' % (version_prefix, lang, to_path.replace('.md', '/'))
to_url = to_url.strip()
with open(out_path, 'w') as f:
f.write('''<!DOCTYPE HTML>
<html lang="en-US"> <html lang="en-US">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@ -224,6 +214,20 @@ def build_redirect_html(args, from_path, to_path):
</html>''' % (to_url, to_url, to_url)) </html>''' % (to_url, to_url, to_url))
def build_redirect_html(args, from_path, to_path):
for lang in args.lang.split(','):
out_path = os.path.join(args.docs_output_dir, lang, from_path.replace('.md', '/index.html'))
out_dir = os.path.dirname(out_path)
try:
os.makedirs(out_dir)
except OSError:
pass
version_prefix = args.version_prefix + '/' if args.version_prefix else '/'
to_url = '/docs%s%s/%s' % (version_prefix, lang, to_path.replace('.md', '/'))
to_url = to_url.strip()
write_redirect_html(out_path, to_url)
def build_redirects(args): def build_redirects(args):
lang_re_fragment = args.lang.replace(',', '|') lang_re_fragment = args.lang.replace(',', '|')
rewrites = [] rewrites = []
@ -263,6 +267,11 @@ def build(args):
if not args.skip_website: if not args.skip_website:
minify_website(args) minify_website(args)
write_redirect_html(
os.path.join(args.output_dir, 'tutorial.html'),
'/docs/en/getting_started/tutorial/'
)
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.join(os.path.dirname(__file__), '..')) os.chdir(os.path.join(os.path.dirname(__file__), '..'))