diff --git a/docs/tools/build.py b/docs/tools/build.py index b12f738a6e3..b0b78daa4d9 100755 --- a/docs/tools/build.py +++ b/docs/tools/build.py @@ -68,7 +68,7 @@ def build_for_lang(lang, args): 'search_index_only': False, 'static_templates': ['404.html'], 'extra': { - 'now': int(time.mktime(datetime.datetime.now().timetuple())) # TODO better way to avoid caching + 'now': int(time.mktime(datetime.datetime.now().timetuple())) # TODO better way to avoid caching } } @@ -84,7 +84,7 @@ def build_for_lang(lang, args): site_dir = os.path.join(args.docs_output_dir, args.version_prefix, lang) else: site_dir = os.path.join(args.docs_output_dir, lang) - + cfg = config.load_config( config_file=config_path, site_name=site_names.get(lang, site_names['en']) % args.version_prefix, @@ -98,7 +98,7 @@ def build_for_lang(lang, args): repo_name='ClickHouse/ClickHouse', repo_url='https://github.com/ClickHouse/ClickHouse/', edit_uri='edit/master/docs/%s' % lang, - extra_css=['assets/stylesheets/custom.css'], + extra_css=['assets/stylesheets/custom.css?%s' % args.rev_short], markdown_extensions=[ 'clickhouse', 'admonition', @@ -115,7 +115,10 @@ def build_for_lang(lang, args): plugins=[], extra={ 'stable_releases': args.stable_releases, - 'version_prefix': args.version_prefix + 'version_prefix': args.version_prefix, + 'rev': args.rev, + 'rev_short': args.rev_short, + 'rev_url': args.rev_url } ) @@ -247,7 +250,8 @@ def build_redirects(args): def build_docs(args): tasks = [] for lang in args.lang.split(','): - tasks.append((lang, args,)) + if lang: + tasks.append((lang, args,)) util.run_function_in_parallel(build_for_lang, tasks, threads=False) build_redirects(args) @@ -260,7 +264,7 @@ def build(args): build_website(args) build_docs(args) - + from github import build_releases build_releases(args, build_docs) @@ -281,7 +285,7 @@ def build(args): if __name__ == '__main__': os.chdir(os.path.join(os.path.dirname(__file__), '..')) - + arg_parser = argparse.ArgumentParser() arg_parser.add_argument('--lang', default='en,ru,zh,ja,fa') arg_parser.add_argument('--docs-dir', default='.') @@ -300,9 +304,12 @@ if __name__ == '__main__': args = arg_parser.parse_args() args.docs_output_dir = os.path.join(os.path.abspath(args.output_dir), 'docs') - + from github import choose_latest_releases args.stable_releases = choose_latest_releases() if args.enable_stable_releases else [] + args.rev = subprocess.check_output('git rev-parse HEAD', shell=True).strip() + args.rev_short = subprocess.check_output('git rev-parse --short HEAD', shell=True).strip() + args.rev_url = 'https://github.com/ClickHouse/ClickHouse/commit/%s' % args.rev logging.basicConfig( level=logging.DEBUG if args.verbose else logging.INFO, diff --git a/docs/tools/mkdocs-material-theme/partials/social.html b/docs/tools/mkdocs-material-theme/partials/social.html index cb68735adf2..86fc636584c 100644 --- a/docs/tools/mkdocs-material-theme/partials/social.html +++ b/docs/tools/mkdocs-material-theme/partials/social.html @@ -1,9 +1,3 @@ -{% if config.extra.social %} -
-{% endif %} + diff --git a/docs/tools/website.py b/docs/tools/website.py index de971662a5a..b6fb2880bbb 100644 --- a/docs/tools/website.py +++ b/docs/tools/website.py @@ -4,10 +4,16 @@ import shutil import cssmin import htmlmin +import jinja2 import jsmin + def build_website(args): logging.info('Building website') + env = jinja2.Environment( + loader=args.output_dir + ) + shutil.copytree( args.website_dir, args.output_dir, @@ -21,9 +27,25 @@ def build_website(args): ) ) + for root, _, filenames in os.walk(args.output_dir): + for filename in filenames: + path = os.path.join(root, filename) + if not filename.endswith('.html'): + continue + logging.info('Processing %s', path) + with open(path, 'rb') as f: + content = f.read().decode('utf-8') + + template = env.from_string(content) + content = template.render(args.__dict__) + + with open(path, 'wb') as f: + f.write(content.encode('utf-8')) + def minify_website(args): if args.minify: + logging.info('Minifying website') for root, _, filenames in os.walk(args.output_dir): for filename in filenames: path = os.path.join(root, filename) @@ -33,15 +55,15 @@ def minify_website(args): filename.endswith('.js') ): continue - + logging.info('Minifying %s', path) with open(path, 'rb') as f: content = f.read().decode('utf-8') - if filename.endswith('.html'): - content = htmlmin.minify(content, remove_empty_space=False) - elif filename.endswith('.css'): - content = cssmin.cssmin(content) - elif filename.endswith('.js'): - content = jsmin.jsmin(content) + if filename.endswith('.html'): + content = htmlmin.minify(content, remove_empty_space=False) + elif filename.endswith('.css'): + content = cssmin.cssmin(content) + elif filename.endswith('.js'): + content = jsmin.jsmin(content) with open(path, 'wb') as f: f.write(content.encode('utf-8')) diff --git a/website/index.html b/website/index.html index e4f4cd5196a..d06a1a632f9 100644 --- a/website/index.html +++ b/website/index.html @@ -23,7 +23,7 @@ - + diff --git a/website/sitemap_static.xml b/website/sitemap_static.xml index cfeaf1b8b79..1eb6dd3fee2 100644 --- a/website/sitemap_static.xml +++ b/website/sitemap_static.xml @@ -1,23 +1,27 @@ - -