2020-03-18 13:02:32 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-03-30 08:25:29 +00:00
|
|
|
|
2023-01-11 14:43:57 +00:00
|
|
|
from pathlib import Path
|
2018-07-09 19:59:07 +00:00
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import shutil
|
|
|
|
import sys
|
2018-10-16 10:47:17 +00:00
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
import livereload
|
2018-07-09 19:59:07 +00:00
|
|
|
|
2023-01-11 14:43:57 +00:00
|
|
|
|
|
|
|
def write_redirect_html(output_path: Path, to_url: str) -> None:
|
|
|
|
output_dir = output_path.parent
|
|
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
output_path.write_text(
|
|
|
|
f"""<!--[if IE 6]> Redirect: {to_url} <![endif]-->
|
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html lang="en-US">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<meta http-equiv="refresh" content="0; url={to_url}">
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.location.href = "{to_url}";
|
|
|
|
</script>
|
|
|
|
<title>Page Redirection</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
If you are not redirected automatically, follow this <a href="{to_url}">link</a>.
|
|
|
|
</body>
|
|
|
|
</html>"""
|
|
|
|
)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
2023-01-11 14:43:57 +00:00
|
|
|
def build_static_redirects(output_dir: Path):
|
|
|
|
for static_redirect in [
|
|
|
|
("benchmark.html", "/benchmark/dbms/"),
|
|
|
|
("benchmark_hardware.html", "/benchmark/hardware/"),
|
|
|
|
(
|
|
|
|
"tutorial.html",
|
|
|
|
"/docs/en/getting_started/tutorial/",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"reference_en.html",
|
|
|
|
"/docs/en/single/",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"reference_ru.html",
|
|
|
|
"/docs/ru/single/",
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"docs/index.html",
|
|
|
|
"/docs/en/",
|
|
|
|
),
|
|
|
|
]:
|
|
|
|
write_redirect_html(output_dir / static_redirect[0], static_redirect[1])
|
|
|
|
|
|
|
|
|
|
|
|
def build(root_dir: Path, output_dir: Path):
|
|
|
|
if output_dir.exists():
|
2019-03-26 09:50:28 +00:00
|
|
|
shutil.rmtree(args.output_dir)
|
|
|
|
|
2023-01-11 14:43:57 +00:00
|
|
|
(output_dir / "data").mkdir(parents=True)
|
|
|
|
|
|
|
|
logging.info("Building website")
|
|
|
|
|
|
|
|
# This file can be requested to check for available ClickHouse releases.
|
|
|
|
shutil.copy2(
|
|
|
|
root_dir / "utils" / "list-versions" / "version_date.tsv",
|
|
|
|
output_dir / "data" / "version_date.tsv",
|
|
|
|
)
|
|
|
|
|
|
|
|
# This file can be requested to install ClickHouse.
|
|
|
|
shutil.copy2(
|
|
|
|
root_dir / "docs" / "_includes" / "install" / "universal.sh",
|
|
|
|
output_dir / "data" / "install.sh",
|
|
|
|
)
|
|
|
|
|
|
|
|
build_static_redirects(output_dir)
|
2020-01-29 20:27:36 +00:00
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
if __name__ == "__main__":
|
2023-01-11 14:43:57 +00:00
|
|
|
root_dir = Path(__file__).parent.parent.parent
|
|
|
|
docs_dir = root_dir / "docs"
|
|
|
|
|
|
|
|
arg_parser = argparse.ArgumentParser(
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
|
|
)
|
|
|
|
arg_parser.add_argument(
|
|
|
|
"--output-dir",
|
|
|
|
type=Path,
|
|
|
|
default=docs_dir / "build",
|
|
|
|
help="path to the output dir",
|
|
|
|
)
|
2022-03-22 16:39:58 +00:00
|
|
|
arg_parser.add_argument("--livereload", type=int, default="0")
|
|
|
|
arg_parser.add_argument("--verbose", action="store_true")
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
args = arg_parser.parse_args()
|
2020-03-19 06:28:58 +00:00
|
|
|
|
|
|
|
logging.basicConfig(
|
2022-03-22 16:39:58 +00:00
|
|
|
level=logging.DEBUG if args.verbose else logging.INFO, stream=sys.stderr
|
2020-03-19 06:28:58 +00:00
|
|
|
)
|
|
|
|
|
2023-01-11 14:43:57 +00:00
|
|
|
build(root_dir, args.output_dir)
|
2020-04-09 20:50:39 +00:00
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
if args.livereload:
|
|
|
|
server = livereload.Server()
|
2022-03-22 16:39:58 +00:00
|
|
|
server.serve(root=args.output_dir, host="0.0.0.0", port=args.livereload)
|
2020-03-13 19:35:03 +00:00
|
|
|
sys.exit(0)
|