2020-06-16 06:31:00 +00:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
import datetime
|
|
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
import nav # monkey patches mkdocs
|
|
|
|
|
|
|
|
|
|
import mkdocs.commands
|
|
|
|
|
from mkdocs import config
|
|
|
|
|
from mkdocs import exceptions
|
|
|
|
|
|
|
|
|
|
import mdx_clickhouse
|
|
|
|
|
import redirects
|
|
|
|
|
|
|
|
|
|
import util
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_for_lang(lang, args):
|
2022-03-22 16:39:58 +00:00
|
|
|
|
logging.info(f"Building {lang} blog")
|
2020-06-16 06:31:00 +00:00
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
theme_cfg = {
|
2022-03-22 16:39:58 +00:00
|
|
|
|
"name": None,
|
|
|
|
|
"custom_dir": os.path.join(os.path.dirname(__file__), "..", args.theme_dir),
|
|
|
|
|
"language": lang,
|
|
|
|
|
"direction": "ltr",
|
|
|
|
|
"static_templates": ["404.html"],
|
|
|
|
|
"extra": {
|
|
|
|
|
"now": int(
|
|
|
|
|
time.mktime(datetime.datetime.now().timetuple())
|
|
|
|
|
) # TODO better way to avoid caching
|
|
|
|
|
},
|
2020-06-16 06:31:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# the following list of languages is sorted according to
|
|
|
|
|
# https://en.wikipedia.org/wiki/List_of_languages_by_total_number_of_speakers
|
2022-03-22 16:39:58 +00:00
|
|
|
|
languages = {"en": "English"}
|
2020-06-16 06:31:00 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
site_names = {"en": "ClickHouse Blog"}
|
2020-06-16 06:31:00 +00:00
|
|
|
|
|
|
|
|
|
assert len(site_names) == len(languages)
|
|
|
|
|
|
|
|
|
|
site_dir = os.path.join(args.blog_output_dir, lang)
|
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
plugins = ["macros"]
|
2020-06-16 06:31:00 +00:00
|
|
|
|
if args.htmlproofer:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
plugins.append("htmlproofer")
|
2020-06-16 06:31:00 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
website_url = "https://clickhouse.com"
|
|
|
|
|
site_name = site_names.get(lang, site_names["en"])
|
2020-06-16 06:31:00 +00:00
|
|
|
|
blog_nav, post_meta = nav.build_blog_nav(lang, args)
|
|
|
|
|
raw_config = dict(
|
|
|
|
|
site_name=site_name,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
site_url=f"{website_url}/blog/{lang}/",
|
2020-06-16 06:31:00 +00:00
|
|
|
|
docs_dir=os.path.join(args.blog_dir, lang),
|
|
|
|
|
site_dir=site_dir,
|
|
|
|
|
strict=True,
|
|
|
|
|
theme=theme_cfg,
|
|
|
|
|
nav=blog_nav,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
copyright="©2016–2022 ClickHouse, Inc.",
|
2020-06-16 06:31:00 +00:00
|
|
|
|
use_directory_urls=True,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
repo_name="ClickHouse/ClickHouse",
|
|
|
|
|
repo_url="https://github.com/ClickHouse/ClickHouse/",
|
|
|
|
|
edit_uri=f"edit/master/website/blog/{lang}",
|
2020-06-16 06:31:00 +00:00
|
|
|
|
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,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
includes_dir=os.path.join(os.path.dirname(__file__), "..", "_includes"),
|
2020-06-16 06:31:00 +00:00
|
|
|
|
is_amp=False,
|
|
|
|
|
is_blog=True,
|
2020-06-30 18:22:07 +00:00
|
|
|
|
post_meta=post_meta,
|
2022-03-22 16:39:58 +00:00
|
|
|
|
today=datetime.date.today().isoformat(),
|
|
|
|
|
),
|
2020-06-16 06:31:00 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cfg = config.load_config(**raw_config)
|
|
|
|
|
mkdocs.commands.build.build(cfg)
|
|
|
|
|
|
|
|
|
|
redirects.build_blog_redirects(args)
|
|
|
|
|
|
2020-06-30 18:22:07 +00:00
|
|
|
|
env = util.init_jinja2_env(args)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
with open(
|
|
|
|
|
os.path.join(args.website_dir, "templates", "blog", "rss.xml"), "rb"
|
|
|
|
|
) as f:
|
|
|
|
|
rss_template_string = f.read().decode("utf-8").strip()
|
2020-06-30 18:22:07 +00:00
|
|
|
|
rss_template = env.from_string(rss_template_string)
|
2022-03-22 16:39:58 +00:00
|
|
|
|
with open(os.path.join(args.blog_output_dir, lang, "rss.xml"), "w") as f:
|
|
|
|
|
f.write(rss_template.render({"config": raw_config}))
|
2020-06-30 18:22:07 +00:00
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
logging.info(f"Finished building {lang} blog")
|
2020-06-16 06:31:00 +00:00
|
|
|
|
|
|
|
|
|
except exceptions.ConfigurationError as e:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
raise SystemExit("\n" + str(e))
|
2020-06-16 06:31:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build_blog(args):
|
|
|
|
|
tasks = []
|
2022-03-22 16:39:58 +00:00
|
|
|
|
for lang in args.blog_lang.split(","):
|
2020-06-16 06:31:00 +00:00
|
|
|
|
if lang:
|
2022-03-22 16:39:58 +00:00
|
|
|
|
tasks.append(
|
|
|
|
|
(
|
|
|
|
|
lang,
|
|
|
|
|
args,
|
|
|
|
|
)
|
|
|
|
|
)
|
2020-06-16 06:31:00 +00:00
|
|
|
|
util.run_function_in_parallel(build_for_lang, tasks, threads=False)
|