Пример #1
0
def build_for_lang(lang, args):
    logging.info(f"Building {lang} docs")

    try:
        theme_cfg = {
            "name":
            None,
            "custom_dir":
            os.path.join(os.path.dirname(__file__), "..", args.theme_dir),
            "language":
            lang,
            "direction":
            "rtl" if lang == "fa" else "ltr",
            "static_templates": ["404.html"],
            "extra": {
                "now": int(time.mktime(datetime.datetime.now().timetuple())
                           )  # TODO better way to avoid caching
            },
        }

        # the following list of languages is sorted according to
        # https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers
        languages = {"en": "English", "zh": "中文", "ru": "Русский", "ja": "日本語"}

        site_names = {
            "en": "ClickHouse %s Documentation",
            "zh": "ClickHouse文档 %s",
            "ru": "Документация ClickHouse %s",
            "ja": "ClickHouseドキュメント %s",
        }

        assert len(site_names) == len(languages)

        site_dir = os.path.join(args.docs_output_dir, lang)

        plugins = ["macros"]
        if args.htmlproofer:
            plugins.append("htmlproofer")

        website_url = "https://clickhouse.com"
        site_name = site_names.get(lang, site_names["en"]) % ""
        site_name = site_name.replace("  ", " ")

        raw_config = dict(
            site_name=site_name,
            site_url=f"{website_url}/docs/{lang}/",
            docs_dir=os.path.join(args.docs_dir, lang),
            site_dir=site_dir,
            strict=True,
            theme=theme_cfg,
            copyright="©2016–2022 ClickHouse, Inc.",
            use_directory_urls=True,
            repo_name="ClickHouse/ClickHouse",
            repo_url="https://github.com/ClickHouse/ClickHouse/",
            edit_uri=f"edit/master/docs/{lang}",
            markdown_extensions=mdx_clickhouse.MARKDOWN_EXTENSIONS,
            plugins=plugins,
            extra=dict(
                now=datetime.datetime.now().isoformat(),
                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"),
                is_blog=False,
            ),
        )

        raw_config["nav"] = nav.build_docs_nav(lang, args)

        cfg = config.load_config(**raw_config)

        if not args.skip_multi_page:
            mkdocs.commands.build.build(cfg)

        mdx_clickhouse.PatchedMacrosPlugin.disabled = False

        logging.info(f"Finished building {lang} docs")

    except exceptions.ConfigurationError as e:
        raise SystemExit("\n" + str(e))
Пример #2
0
def build_for_lang(lang, args):
    logging.info(f'Building {lang} docs')
    os.environ['SINGLE_PAGE'] = '0'

    config_path = os.path.join(args.docs_dir, f'toc_{lang}.yml')
    if args.is_stable_release and not os.path.exists(config_path):
        logging.warning(
            f'Skipping {lang} docs, because {config} does not exist')
        return

    try:
        theme_cfg = {
            'name':
            None,
            'custom_dir':
            os.path.join(os.path.dirname(__file__), '..', args.theme_dir),
            'language':
            lang,
            'direction':
            'rtl' if lang == 'fa' else 'ltr',
            'static_templates': ['404.html'],
            'extra': {
                'now': int(time.mktime(datetime.datetime.now().timetuple())
                           )  # TODO better way to avoid caching
            }
        }

        # the following list of languages is sorted according to
        # https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers
        languages = {
            'en': 'English',
            'zh': '中文',
            'es': 'Español',
            'fr': 'Français',
            'ru': 'Русский',
            'ja': '日本語',
            'tr': 'Türkçe',
            'fa': 'فارسی'
        }

        site_names = {
            'en': 'ClickHouse %s Documentation',
            'zh': 'ClickHouse文档 %s',
            'es': 'Documentación de ClickHouse %s',
            'fr': 'Documentation ClickHouse %s',
            'ru': 'Документация ClickHouse %s',
            'ja': 'ClickHouseドキュメント %s',
            'tr': 'ClickHouse Belgeleri %s',
            'fa': 'مستندات %sClickHouse'
        }

        assert len(site_names) == len(languages)

        if args.version_prefix:
            site_dir = os.path.join(args.docs_output_dir, args.version_prefix,
                                    lang)
        else:
            site_dir = os.path.join(args.docs_output_dir, lang)

        plugins = ['macros']
        if args.htmlproofer:
            plugins.append('htmlproofer')

        website_url = 'https://clickhouse.tech'
        site_name = site_names.get(lang,
                                   site_names['en']) % args.version_prefix
        site_name = site_name.replace('  ', ' ')
        raw_config = dict(
            site_name=site_name,
            site_url=f'{website_url}/docs/{lang}/',
            docs_dir=os.path.join(args.docs_dir, lang),
            site_dir=site_dir,
            strict=not args.version_prefix,
            theme=theme_cfg,
            copyright='©2016–2020 Yandex LLC',
            use_directory_urls=True,
            repo_name='ClickHouse/ClickHouse',
            repo_url='https://github.com/ClickHouse/ClickHouse/',
            edit_uri=f'edit/master/docs/{lang}',
            markdown_extensions=mdx_clickhouse.MARKDOWN_EXTENSIONS,
            plugins=plugins,
            extra=dict(now=datetime.datetime.now().isoformat(),
                       stable_releases=args.stable_releases,
                       version_prefix=args.version_prefix,
                       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'),
                       is_amp=False,
                       is_blog=False))

        if os.path.exists(config_path):
            raw_config['config_file'] = config_path
        else:
            raw_config['nav'] = nav.build_docs_nav(lang, args)

        cfg = config.load_config(**raw_config)

        if not args.skip_multi_page:
            try:
                mkdocs.commands.build.build(cfg)
            except jinja2.exceptions.TemplateError:
                if not args.version_prefix:
                    raise
                mdx_clickhouse.PatchedMacrosPlugin.disabled = True
                mkdocs.commands.build.build(cfg)

        if not (args.skip_amp or args.version_prefix):
            amp.build_amp(lang, args, cfg)

        if not args.skip_single_page:
            single_page.build_single_page_version(lang, args,
                                                  raw_config.get('nav'), cfg)

        mdx_clickhouse.PatchedMacrosPlugin.disabled = False

        logging.info(f'Finished building {lang} docs')

    except exceptions.ConfigurationError as e:
        raise SystemExit('\n' + str(e))
Пример #3
0
def build_for_lang(lang, args):
    logging.info(f'Building {lang} docs')
    os.environ['SINGLE_PAGE'] = '0'

    try:
        theme_cfg = {
            'name': None,
            'custom_dir': os.path.join(os.path.dirname(__file__), '..', args.theme_dir),
            'language': lang,
            'direction': 'rtl' if lang == 'fa' else 'ltr',
            'static_templates': ['404.html'],
            'extra': {
                'now': int(time.mktime(datetime.datetime.now().timetuple()))  # TODO better way to avoid caching
            }
        }

        # the following list of languages is sorted according to
        # https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers
        languages = {
            'en': 'English',
            'zh': '中文',
            'ru': 'Русский',
            'ja': '日本語'
        }

        site_names = {
            'en': 'ClickHouse %s Documentation',
            'zh': 'ClickHouse文档 %s',
            'ru': 'Документация ClickHouse %s',
            'ja': 'ClickHouseドキュメント %s'
        }

        assert len(site_names) == len(languages)

        site_dir = os.path.join(args.docs_output_dir, lang)

        plugins = ['macros']
        if args.htmlproofer:
            plugins.append('htmlproofer')

        website_url = 'https://clickhouse.com'
        site_name = site_names.get(lang, site_names['en']) % ''
        site_name = site_name.replace('  ', ' ')

        raw_config = dict(
            site_name=site_name,
            site_url=f'{website_url}/docs/{lang}/',
            docs_dir=os.path.join(args.docs_dir, lang),
            site_dir=site_dir,
            strict=True,
            theme=theme_cfg,
            copyright='©2016–2022 ClickHouse, Inc.',
            use_directory_urls=True,
            repo_name='ClickHouse/ClickHouse',
            repo_url='https://github.com/ClickHouse/ClickHouse/',
            edit_uri=f'edit/master/docs/{lang}',
            markdown_extensions=mdx_clickhouse.MARKDOWN_EXTENSIONS,
            plugins=plugins,
            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'),
                is_amp=False,
                is_blog=False
            )
        )

        # Clean to be safe if last build finished abnormally
        single_page.remove_temporary_files(lang, args)

        raw_config['nav'] = nav.build_docs_nav(lang, args)

        cfg = config.load_config(**raw_config)

        if not args.skip_multi_page:
            mkdocs.commands.build.build(cfg)

        if not args.skip_amp:
            amp.build_amp(lang, args, cfg)

        if not args.skip_single_page:
            single_page.build_single_page_version(lang, args, raw_config.get('nav'), cfg)

        mdx_clickhouse.PatchedMacrosPlugin.disabled = False

        logging.info(f'Finished building {lang} docs')

    except exceptions.ConfigurationError as e:
        raise SystemExit('\n' + str(e))