mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
Redesign website (#2628)
* Bump up Bootstrap to v5.3.1, Bootstrap Icon to v1.10.5. * Use autoComplete.js to drop dependency on jQuery and typeahead.js. * Support dark mode. * New svg logo and icon with responsive color mode support. * Normalize section ids to lower kebab-case for easiness of linking. * Use relative paths for links for local development (--root /output). * Various markup cleanups and accessibility improvements.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import glob
|
||||
import itertools
|
||||
from jinja2 import Environment, FileSystemLoader, select_autoescape, pass_context
|
||||
@@ -10,6 +11,10 @@ import re
|
||||
import shutil
|
||||
import yaml
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--root', default='/jq')
|
||||
args = parser.parse_args()
|
||||
|
||||
env = Environment(
|
||||
loader=FileSystemLoader('templates'),
|
||||
autoescape=select_autoescape(['html.j2']),
|
||||
@@ -21,40 +26,51 @@ def load_yml_file(fn):
|
||||
return yaml.safe_load(f)
|
||||
|
||||
|
||||
env.globals['url'] = 'https://jqlang.github.io/jq'
|
||||
env.globals['root'] = args.root
|
||||
|
||||
env.filters['search_id'] = lambda input: input.replace(r'`', '')
|
||||
env.filters['section_id'] = lambda input: re.sub(r"[^a-zA-Z0-9_]", '', input)
|
||||
env.filters['entry_id'] = lambda input: re.sub(r"[ `]", '', input)
|
||||
env.filters['section_id'] = lambda input: re.sub(
|
||||
r'[^-a-zA-Z0-9_]', '', input.replace(' ', '-')).lower()
|
||||
env.filters['entry_id'] = lambda input: re.sub(
|
||||
r'^(split|first-last-nth)$',
|
||||
r'\1' + ('-1' if ';' not in input else '-2'), # avoid id conflict
|
||||
re.sub(
|
||||
r'\b([^-]+)(?:-\1)+\b',
|
||||
r'\1', # e.g. range-range-range -> range
|
||||
re.sub(r' ?/ ?|,? ', '-',
|
||||
re.sub(r'[`;]|: .*|\(.*?\)| \[.+\]', '', input)))).lower()
|
||||
env.filters['markdownify'] = lambda input: Markup(markdown(input))
|
||||
env.filters['no_paragraph'] = lambda input: Markup(re.sub(r"</?p>", '', input))
|
||||
env.filters['no_paragraph'] = lambda input: Markup(re.sub(r'</?p>', '', input))
|
||||
|
||||
env.globals['unique_id'] = pass_context(
|
||||
lambda ctx: str(next(ctx['unique_ctr'])))
|
||||
|
||||
env.globals.update(load_yml_file('site.yml'))
|
||||
|
||||
env.globals['navigation'] = ['tutorial', 'download', 'manual']
|
||||
def raise_handler(message):
|
||||
raise Exception(message)
|
||||
|
||||
|
||||
def generate_file(env, fname='content/1.tutorial/default.yml'):
|
||||
env.globals['raise'] = raise_handler
|
||||
|
||||
|
||||
def generate_file(env, fname):
|
||||
path, base = os.path.split(fname)
|
||||
path = os.path.relpath(path, 'content')
|
||||
if path == '.':
|
||||
path = ''
|
||||
slug = 'index'
|
||||
permalink = ''
|
||||
else:
|
||||
slug = os.path.basename(path)
|
||||
permalink = path + '/'
|
||||
|
||||
output_dir = os.path.join('output', path)
|
||||
output_path = os.path.join(output_dir, 'index.html')
|
||||
|
||||
template_name = re.sub(r".yml$", '.html.j2', base)
|
||||
template_name = re.sub(r'.yml$', '.html.j2', base)
|
||||
|
||||
ctx = load_yml_file(fname)
|
||||
ctx.update(unique_ctr=itertools.count(1),
|
||||
permalink=permalink,
|
||||
slug=slug,
|
||||
navitem=path)
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
env.get_template(template_name).stream(ctx).dump(output_path,
|
||||
@@ -72,6 +88,7 @@ def copy_public_files(root=''):
|
||||
shutil.copyfile(f.path, dst)
|
||||
|
||||
|
||||
os.makedirs('output', exist_ok=True)
|
||||
copy_public_files()
|
||||
|
||||
for fn in glob.glob('content/**/*.yml', recursive=True):
|
||||
|
||||
Reference in New Issue
Block a user