2020-03-18 13:02:32 +00:00
|
|
|
|
#!/usr/bin/env python3
|
2020-03-30 08:25:29 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
import argparse
|
2018-08-10 14:44:49 +00:00
|
|
|
|
import datetime
|
2018-07-09 19:59:07 +00:00
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
2018-10-12 15:43:16 +00:00
|
|
|
|
import subprocess
|
2018-07-09 19:59:07 +00:00
|
|
|
|
import sys
|
2018-10-16 10:47:17 +00:00
|
|
|
|
import time
|
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
import jinja2
|
2020-03-13 19:35:03 +00:00
|
|
|
|
import livereload
|
2018-10-16 10:47:17 +00:00
|
|
|
|
import markdown.util
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import nav # monkey patches mkdocs
|
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
from mkdocs import config
|
|
|
|
|
from mkdocs import exceptions
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import mkdocs.commands.build
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import amp
|
2020-06-16 06:31:00 +00:00
|
|
|
|
import blog
|
2018-12-12 17:28:00 +00:00
|
|
|
|
import mdx_clickhouse
|
2020-05-08 08:04:09 +00:00
|
|
|
|
import redirects
|
|
|
|
|
import single_page
|
2018-12-18 11:32:08 +00:00
|
|
|
|
import test
|
2019-04-08 16:01:54 +00:00
|
|
|
|
import util
|
2020-03-30 11:39:26 +00:00
|
|
|
|
import website
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-09-19 16:42:36 +00:00
|
|
|
|
from cmake_in_clickhouse_generator import generate_cmake_flags_files
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2018-10-16 10:47:17 +00:00
|
|
|
|
class ClickHouseMarkdown(markdown.extensions.Extension):
|
|
|
|
|
class ClickHousePreprocessor(markdown.util.Processor):
|
|
|
|
|
def run(self, lines):
|
|
|
|
|
for line in lines:
|
|
|
|
|
if '<!--hide-->' not in line:
|
|
|
|
|
yield line
|
|
|
|
|
|
|
|
|
|
def extendMarkdown(self, md):
|
|
|
|
|
md.preprocessors.register(self.ClickHousePreprocessor(), 'clickhouse_preprocessor', 31)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2018-10-16 10:47:17 +00:00
|
|
|
|
markdown.extensions.ClickHouseMarkdown = ClickHouseMarkdown
|
2018-10-16 06:58:03 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
def build_for_lang(lang, args):
|
2020-03-22 12:12:53 +00:00
|
|
|
|
logging.info(f'Building {lang} docs')
|
2018-12-12 17:28:00 +00:00
|
|
|
|
os.environ['SINGLE_PAGE'] = '0'
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
theme_cfg = {
|
2020-03-22 12:12:53 +00:00
|
|
|
|
'name': None,
|
2020-03-30 08:25:29 +00:00
|
|
|
|
'custom_dir': os.path.join(os.path.dirname(__file__), '..', args.theme_dir),
|
2018-07-09 19:59:07 +00:00
|
|
|
|
'language': lang,
|
2018-09-06 10:22:06 +00:00
|
|
|
|
'direction': 'rtl' if lang == 'fa' else 'ltr',
|
2018-07-09 19:59:07 +00:00
|
|
|
|
'static_templates': ['404.html'],
|
|
|
|
|
'extra': {
|
2020-02-18 14:19:44 +00:00
|
|
|
|
'now': int(time.mktime(datetime.datetime.now().timetuple())) # TODO better way to avoid caching
|
2018-07-09 19:59:07 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-10 14:44:49 +00:00
|
|
|
|
|
2020-03-30 13:07:08 +00:00
|
|
|
|
# the following list of languages is sorted according to
|
|
|
|
|
# https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers
|
2020-03-30 08:25:29 +00:00
|
|
|
|
languages = {
|
|
|
|
|
'en': 'English',
|
|
|
|
|
'zh': '中文',
|
|
|
|
|
'ru': 'Русский',
|
2020-12-21 20:04:22 +00:00
|
|
|
|
'ja': '日本語'
|
2020-03-30 08:25:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 13:07:08 +00:00
|
|
|
|
site_names = {
|
|
|
|
|
'en': 'ClickHouse %s Documentation',
|
2020-04-08 09:09:59 +00:00
|
|
|
|
'zh': 'ClickHouse文档 %s',
|
2020-03-30 13:07:08 +00:00
|
|
|
|
'ru': 'Документация ClickHouse %s',
|
2020-12-21 20:04:22 +00:00
|
|
|
|
'ja': 'ClickHouseドキュメント %s'
|
2020-03-30 13:07:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
assert len(site_names) == len(languages)
|
|
|
|
|
|
2020-12-21 20:04:22 +00:00
|
|
|
|
site_dir = os.path.join(args.docs_output_dir, lang)
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
plugins = ['macros']
|
2020-03-18 13:02:32 +00:00
|
|
|
|
if args.htmlproofer:
|
|
|
|
|
plugins.append('htmlproofer')
|
|
|
|
|
|
2020-04-30 15:49:48 +00:00
|
|
|
|
website_url = 'https://clickhouse.tech'
|
2020-12-21 20:04:22 +00:00
|
|
|
|
site_name = site_names.get(lang, site_names['en']) % ''
|
2020-04-22 12:40:30 +00:00
|
|
|
|
site_name = site_name.replace(' ', ' ')
|
2021-06-24 13:52:08 +00:00
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
raw_config = dict(
|
2020-04-22 12:40:30 +00:00
|
|
|
|
site_name=site_name,
|
2020-04-30 15:49:48 +00:00
|
|
|
|
site_url=f'{website_url}/docs/{lang}/',
|
2018-07-09 19:59:07 +00:00
|
|
|
|
docs_dir=os.path.join(args.docs_dir, lang),
|
2019-04-08 16:01:54 +00:00
|
|
|
|
site_dir=site_dir,
|
2020-12-21 20:04:22 +00:00
|
|
|
|
strict=True,
|
2018-07-09 19:59:07 +00:00
|
|
|
|
theme=theme_cfg,
|
2021-05-21 06:49:54 +00:00
|
|
|
|
copyright='©2016–2021 Yandex LLC',
|
2018-07-09 19:59:07 +00:00
|
|
|
|
use_directory_urls=True,
|
2019-11-08 14:26:25 +00:00
|
|
|
|
repo_name='ClickHouse/ClickHouse',
|
|
|
|
|
repo_url='https://github.com/ClickHouse/ClickHouse/',
|
2020-03-22 12:12:53 +00:00
|
|
|
|
edit_uri=f'edit/master/docs/{lang}',
|
2020-06-16 06:31:00 +00:00
|
|
|
|
markdown_extensions=mdx_clickhouse.MARKDOWN_EXTENSIONS,
|
2020-03-18 13:02:32 +00:00
|
|
|
|
plugins=plugins,
|
2020-05-08 08:04:09 +00:00
|
|
|
|
extra=dict(
|
|
|
|
|
now=datetime.datetime.now().isoformat(),
|
|
|
|
|
single_page=False,
|
|
|
|
|
rev=args.rev,
|
|
|
|
|
rev_short=args.rev_short,
|
|
|
|
|
rev_url=args.rev_url,
|
|
|
|
|
website_url=website_url,
|
|
|
|
|
events=args.events,
|
|
|
|
|
languages=languages,
|
|
|
|
|
includes_dir=os.path.join(os.path.dirname(__file__), '..', '_includes'),
|
2020-06-16 06:31:00 +00:00
|
|
|
|
is_amp=False,
|
|
|
|
|
is_blog=False
|
2020-05-08 08:04:09 +00:00
|
|
|
|
)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
)
|
|
|
|
|
|
2020-12-21 20:04:22 +00:00
|
|
|
|
raw_config['nav'] = nav.build_docs_nav(lang, args)
|
2020-04-03 13:23:32 +00:00
|
|
|
|
|
2020-03-30 08:25:29 +00:00
|
|
|
|
cfg = config.load_config(**raw_config)
|
|
|
|
|
|
2020-05-06 12:54:33 +00:00
|
|
|
|
if not args.skip_multi_page:
|
2020-12-21 20:04:22 +00:00
|
|
|
|
mkdocs.commands.build.build(cfg)
|
|
|
|
|
|
|
|
|
|
if not args.skip_amp:
|
2020-05-08 08:04:09 +00:00
|
|
|
|
amp.build_amp(lang, args, cfg)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
|
|
|
|
if not args.skip_single_page:
|
2020-05-08 08:04:09 +00:00
|
|
|
|
single_page.build_single_page_version(lang, args, raw_config.get('nav'), cfg)
|
2020-03-30 08:25:29 +00:00
|
|
|
|
|
|
|
|
|
mdx_clickhouse.PatchedMacrosPlugin.disabled = False
|
|
|
|
|
|
2020-03-22 15:20:11 +00:00
|
|
|
|
logging.info(f'Finished building {lang} docs')
|
2020-03-22 14:48:36 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
except exceptions.ConfigurationError as e:
|
|
|
|
|
raise SystemExit('\n' + str(e))
|
|
|
|
|
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
def build_docs(args):
|
2020-01-29 13:34:12 +00:00
|
|
|
|
tasks = []
|
2019-04-08 16:01:54 +00:00
|
|
|
|
for lang in args.lang.split(','):
|
2020-02-18 14:19:44 +00:00
|
|
|
|
if lang:
|
|
|
|
|
tasks.append((lang, args,))
|
2020-02-03 08:58:13 +00:00
|
|
|
|
util.run_function_in_parallel(build_for_lang, tasks, threads=False)
|
2020-12-21 20:04:22 +00:00
|
|
|
|
redirects.build_docs_redirects(args)
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
def build(args):
|
2019-03-26 09:50:28 +00:00
|
|
|
|
if os.path.exists(args.output_dir):
|
|
|
|
|
shutil.rmtree(args.output_dir)
|
|
|
|
|
|
|
|
|
|
if not args.skip_website:
|
2020-03-30 11:39:26 +00:00
|
|
|
|
website.build_website(args)
|
2019-03-26 09:50:28 +00:00
|
|
|
|
|
2020-09-03 20:37:45 +00:00
|
|
|
|
if not args.skip_docs:
|
2020-09-28 12:47:10 +00:00
|
|
|
|
generate_cmake_flags_files()
|
2020-09-19 16:42:36 +00:00
|
|
|
|
|
2020-09-03 20:37:45 +00:00
|
|
|
|
build_docs(args)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-06-16 06:31:00 +00:00
|
|
|
|
if not args.skip_blog:
|
|
|
|
|
blog.build_blog(args)
|
|
|
|
|
|
2019-03-26 09:50:28 +00:00
|
|
|
|
if not args.skip_website:
|
2020-04-22 11:30:33 +00:00
|
|
|
|
website.process_benchmark_results(args)
|
2020-03-30 11:39:26 +00:00
|
|
|
|
website.minify_website(args)
|
2020-05-08 08:04:09 +00:00
|
|
|
|
redirects.build_static_redirects(args)
|
2020-01-29 20:27:36 +00:00
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
if __name__ == '__main__':
|
2019-04-08 16:01:54 +00:00
|
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
|
2020-11-28 06:20:06 +00:00
|
|
|
|
|
|
|
|
|
# A root path to ClickHouse source code.
|
|
|
|
|
src_dir = '..'
|
|
|
|
|
|
|
|
|
|
website_dir = os.path.join(src_dir, 'website')
|
2020-09-19 22:27:36 +00:00
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser = argparse.ArgumentParser()
|
2021-03-31 23:35:41 +00:00
|
|
|
|
arg_parser.add_argument('--lang', default='en,ru,zh,ja')
|
2020-06-16 06:31:00 +00:00
|
|
|
|
arg_parser.add_argument('--blog-lang', default='en,ru')
|
2018-08-10 14:44:49 +00:00
|
|
|
|
arg_parser.add_argument('--docs-dir', default='.')
|
2020-03-30 08:25:29 +00:00
|
|
|
|
arg_parser.add_argument('--theme-dir', default=website_dir)
|
|
|
|
|
arg_parser.add_argument('--website-dir', default=website_dir)
|
2020-11-28 06:20:06 +00:00
|
|
|
|
arg_parser.add_argument('--src-dir', default=src_dir)
|
2020-06-16 06:31:00 +00:00
|
|
|
|
arg_parser.add_argument('--blog-dir', default=os.path.join(website_dir, 'blog'))
|
2018-08-10 14:44:49 +00:00
|
|
|
|
arg_parser.add_argument('--output-dir', default='build')
|
2020-05-08 08:04:09 +00:00
|
|
|
|
arg_parser.add_argument('--nav-limit', type=int, default='0')
|
2020-05-06 12:54:33 +00:00
|
|
|
|
arg_parser.add_argument('--skip-multi-page', action='store_true')
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser.add_argument('--skip-single-page', action='store_true')
|
2020-05-08 08:04:09 +00:00
|
|
|
|
arg_parser.add_argument('--skip-amp', action='store_true')
|
2018-12-21 19:40:49 +00:00
|
|
|
|
arg_parser.add_argument('--skip-pdf', action='store_true')
|
2019-03-26 09:50:28 +00:00
|
|
|
|
arg_parser.add_argument('--skip-website', action='store_true')
|
2020-06-16 06:31:00 +00:00
|
|
|
|
arg_parser.add_argument('--skip-blog', action='store_true')
|
2020-05-12 14:09:36 +00:00
|
|
|
|
arg_parser.add_argument('--skip-git-log', action='store_true')
|
2020-09-03 20:37:45 +00:00
|
|
|
|
arg_parser.add_argument('--skip-docs', action='store_true')
|
2020-05-06 12:54:33 +00:00
|
|
|
|
arg_parser.add_argument('--test-only', action='store_true')
|
2020-02-14 09:34:57 +00:00
|
|
|
|
arg_parser.add_argument('--minify', action='store_true')
|
2020-03-18 13:02:32 +00:00
|
|
|
|
arg_parser.add_argument('--htmlproofer', action='store_true')
|
2020-03-19 08:31:06 +00:00
|
|
|
|
arg_parser.add_argument('--no-docs-macros', action='store_true')
|
2018-12-18 11:32:08 +00:00
|
|
|
|
arg_parser.add_argument('--save-raw-single-page', type=str)
|
2020-03-13 19:35:03 +00:00
|
|
|
|
arg_parser.add_argument('--livereload', type=int, default='0')
|
2018-07-09 19:59:07 +00:00
|
|
|
|
arg_parser.add_argument('--verbose', action='store_true')
|
|
|
|
|
|
|
|
|
|
args = arg_parser.parse_args()
|
2020-03-19 06:28:58 +00:00
|
|
|
|
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.DEBUG if args.verbose else logging.INFO,
|
|
|
|
|
stream=sys.stderr
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
logging.getLogger('MARKDOWN').setLevel(logging.INFO)
|
|
|
|
|
|
2019-04-08 16:01:54 +00:00
|
|
|
|
args.docs_output_dir = os.path.join(os.path.abspath(args.output_dir), 'docs')
|
2020-06-16 06:31:00 +00:00
|
|
|
|
args.blog_output_dir = os.path.join(os.path.abspath(args.output_dir), 'blog')
|
2020-02-18 14:19:44 +00:00
|
|
|
|
|
2020-12-21 20:04:22 +00:00
|
|
|
|
from github import get_events
|
2020-03-18 13:02:32 +00:00
|
|
|
|
args.rev = subprocess.check_output('git rev-parse HEAD', shell=True).decode('utf-8').strip()
|
|
|
|
|
args.rev_short = subprocess.check_output('git rev-parse --short HEAD', shell=True).decode('utf-8').strip()
|
2020-03-22 12:12:53 +00:00
|
|
|
|
args.rev_url = f'https://github.com/ClickHouse/ClickHouse/commit/{args.rev}'
|
2020-03-13 19:35:03 +00:00
|
|
|
|
args.events = get_events(args)
|
2018-07-09 19:59:07 +00:00
|
|
|
|
|
2020-05-06 12:54:33 +00:00
|
|
|
|
if args.test_only:
|
|
|
|
|
args.skip_multi_page = True
|
2020-06-16 06:31:00 +00:00
|
|
|
|
args.skip_blog = True
|
2020-05-06 12:54:33 +00:00
|
|
|
|
args.skip_website = True
|
|
|
|
|
args.skip_pdf = True
|
2020-05-08 08:04:09 +00:00
|
|
|
|
args.skip_amp = True
|
2020-05-06 12:54:33 +00:00
|
|
|
|
|
2020-05-12 14:09:36 +00:00
|
|
|
|
if args.skip_git_log or args.skip_amp:
|
|
|
|
|
mdx_clickhouse.PatchedMacrosPlugin.skip_git_log = True
|
|
|
|
|
|
2018-07-09 19:59:07 +00:00
|
|
|
|
from build import build
|
|
|
|
|
build(args)
|
2020-04-09 20:50:39 +00:00
|
|
|
|
|
2020-03-13 19:35:03 +00:00
|
|
|
|
if args.livereload:
|
|
|
|
|
new_args = [arg for arg in sys.argv if not arg.startswith('--livereload')]
|
|
|
|
|
new_args = sys.executable + ' ' + ' '.join(new_args)
|
|
|
|
|
|
|
|
|
|
server = livereload.Server()
|
|
|
|
|
server.watch(args.docs_dir + '**/*', livereload.shell(new_args, cwd='tools', shell=True))
|
2020-03-30 08:25:29 +00:00
|
|
|
|
server.watch(args.website_dir + '**/*', livereload.shell(new_args, cwd='tools', shell=True))
|
2020-03-13 19:35:03 +00:00
|
|
|
|
server.serve(
|
|
|
|
|
root=args.output_dir,
|
2020-03-30 08:25:29 +00:00
|
|
|
|
host='0.0.0.0',
|
2020-03-13 19:35:03 +00:00
|
|
|
|
port=args.livereload
|
|
|
|
|
)
|
|
|
|
|
sys.exit(0)
|