Show documentation revision in footer

This commit is contained in:
Ivan Blinkov 2020-02-18 17:19:44 +03:00
parent de0e81b7b4
commit 8db2f90f78
5 changed files with 66 additions and 39 deletions

View File

@ -68,7 +68,7 @@ def build_for_lang(lang, args):
'search_index_only': False, 'search_index_only': False,
'static_templates': ['404.html'], 'static_templates': ['404.html'],
'extra': { '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) site_dir = os.path.join(args.docs_output_dir, args.version_prefix, lang)
else: else:
site_dir = os.path.join(args.docs_output_dir, lang) site_dir = os.path.join(args.docs_output_dir, lang)
cfg = config.load_config( cfg = config.load_config(
config_file=config_path, config_file=config_path,
site_name=site_names.get(lang, site_names['en']) % args.version_prefix, 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_name='ClickHouse/ClickHouse',
repo_url='https://github.com/ClickHouse/ClickHouse/', repo_url='https://github.com/ClickHouse/ClickHouse/',
edit_uri='edit/master/docs/%s' % lang, 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=[ markdown_extensions=[
'clickhouse', 'clickhouse',
'admonition', 'admonition',
@ -115,7 +115,10 @@ def build_for_lang(lang, args):
plugins=[], plugins=[],
extra={ extra={
'stable_releases': args.stable_releases, '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): def build_docs(args):
tasks = [] tasks = []
for lang in args.lang.split(','): 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) util.run_function_in_parallel(build_for_lang, tasks, threads=False)
build_redirects(args) build_redirects(args)
@ -260,7 +264,7 @@ def build(args):
build_website(args) build_website(args)
build_docs(args) build_docs(args)
from github import build_releases from github import build_releases
build_releases(args, build_docs) build_releases(args, build_docs)
@ -281,7 +285,7 @@ def build(args):
if __name__ == '__main__': if __name__ == '__main__':
os.chdir(os.path.join(os.path.dirname(__file__), '..')) os.chdir(os.path.join(os.path.dirname(__file__), '..'))
arg_parser = argparse.ArgumentParser() arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('--lang', default='en,ru,zh,ja,fa') arg_parser.add_argument('--lang', default='en,ru,zh,ja,fa')
arg_parser.add_argument('--docs-dir', default='.') arg_parser.add_argument('--docs-dir', default='.')
@ -300,9 +304,12 @@ if __name__ == '__main__':
args = arg_parser.parse_args() args = arg_parser.parse_args()
args.docs_output_dir = os.path.join(os.path.abspath(args.output_dir), 'docs') args.docs_output_dir = os.path.join(os.path.abspath(args.output_dir), 'docs')
from github import choose_latest_releases from github import choose_latest_releases
args.stable_releases = choose_latest_releases() if args.enable_stable_releases else [] 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( logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.INFO, level=logging.DEBUG if args.verbose else logging.INFO,

View File

@ -1,9 +1,3 @@
{% if config.extra.social %} <div class="md-footer-social">
<div class="md-footer-social"> <span class="md-footer-copyright__highlight">Built from <a href="{{ config.extra.rev_url }}" rel="external nofollow">{{ config.extra.rev_short }}</a></span>
{% set path = "ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" %} </div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/{{ path }}">
{% for social in config.extra.social %}
<a href="{{ social.link }}" class="md-footer-social__link fa fa-{{ social.type }}"></a>
{% endfor %}
</div>
{% endif %}

View File

@ -4,10 +4,16 @@ import shutil
import cssmin import cssmin
import htmlmin import htmlmin
import jinja2
import jsmin import jsmin
def build_website(args): def build_website(args):
logging.info('Building website') logging.info('Building website')
env = jinja2.Environment(
loader=args.output_dir
)
shutil.copytree( shutil.copytree(
args.website_dir, args.website_dir,
args.output_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): def minify_website(args):
if args.minify: if args.minify:
logging.info('Minifying website')
for root, _, filenames in os.walk(args.output_dir): for root, _, filenames in os.walk(args.output_dir):
for filename in filenames: for filename in filenames:
path = os.path.join(root, filename) path = os.path.join(root, filename)
@ -33,15 +55,15 @@ def minify_website(args):
filename.endswith('.js') filename.endswith('.js')
): ):
continue continue
logging.info('Minifying %s', path) logging.info('Minifying %s', path)
with open(path, 'rb') as f: with open(path, 'rb') as f:
content = f.read().decode('utf-8') content = f.read().decode('utf-8')
if filename.endswith('.html'): if filename.endswith('.html'):
content = htmlmin.minify(content, remove_empty_space=False) content = htmlmin.minify(content, remove_empty_space=False)
elif filename.endswith('.css'): elif filename.endswith('.css'):
content = cssmin.cssmin(content) content = cssmin.cssmin(content)
elif filename.endswith('.js'): elif filename.endswith('.js'):
content = jsmin.jsmin(content) content = jsmin.jsmin(content)
with open(path, 'wb') as f: with open(path, 'wb') as f:
f.write(content.encode('utf-8')) f.write(content.encode('utf-8'))

View File

@ -23,7 +23,7 @@
<meta name="keywords" <meta name="keywords"
content="ClickHouse, DBMS, OLAP, relational, analytics, analytical, big data, open-source, SQL, web-analytics" /> content="ClickHouse, DBMS, OLAP, relational, analytics, analytical, big data, open-source, SQL, web-analytics" />
<link href="index.css" media="all" rel="stylesheet" /> <link href="index.css?{{ rev_short }}" media="all" rel="stylesheet" />
</head> </head>
<body> <body>
<div id="navbar"> <div id="navbar">
@ -47,7 +47,7 @@
<path class="orange" d="M8,3.25 h1 v1.5 h-1 z"></path> <path class="orange" d="M8,3.25 h1 v1.5 h-1 z"></path>
</svg> </svg>
<img id="logo-text" src="images/clickhouse-black.svg" alt="ClickHouse" /> <img id="logo-text" src="images/clickhouse-black.svg?{{ rev_short }}" alt="ClickHouse" />
</h1> </h1>
</a> </a>
</div> </div>

View File

@ -1,23 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://clickhouse.tech/</loc> <loc>https://clickhouse.tech/</loc>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://clickhouse.tech/benchmark.html</loc> <loc>https://clickhouse.tech/benchmark.html</loc>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://clickhouse.tech/tutorial.html</loc> <loc>https://clickhouse.tech/benchmark_hardware.html</loc>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://clickhouse.tech/blog/en</loc> <loc>https://clickhouse.tech/tutorial.html</loc>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://clickhouse.tech/blog/ru</loc> <loc>https://clickhouse.tech/blog/en</loc>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
</urlset> <url>
<loc>https://clickhouse.tech/blog/ru</loc>
<changefreq>daily</changefreq>
</url>
</urlset>