Skip to content

Commit

Permalink
Redesign website
Browse files Browse the repository at this point in the history
* Bump up Bootstrap to v5.3.0, Bootstrap Icon to v1.10.5.
* Use autoComplete.js to drop dependency on jQuery, typeahead.js.
* Support dark mode.
* New svg logo and icon with responsive color mode support.
* Improve section ids to make them easy to link in Markdown.
* Various markup cleanups and accessibility improvements.
  • Loading branch information
itchyny committed Jun 24, 2023
1 parent 6864aa8 commit 6dfa101
Show file tree
Hide file tree
Showing 22 changed files with 517 additions and 791 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: '3.11'
cache: pipenv
- name: Install pipenv
run: pip install pipenv
Expand Down
6 changes: 1 addition & 5 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,10 @@ AM_CFLAGS += $(onig_CFLAGS)

### Packaging

docs/site.yml: configure.ac
sed 's/^jq_version: .*/jq_version: "$(VERSION)"/' $@ > $@.new
mv $@.new $@

install-binaries: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) install-exec

DOC_FILES = docs/content docs/public docs/templates docs/site.yml \
DOC_FILES = docs/content docs/public docs/templates \
docs/Pipfile docs/Pipfile.lock docs/build_manpage.py \
docs/build_manpage.py docs/README.md jq.1.prebuilt

Expand Down
2 changes: 1 addition & 1 deletion docs/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ verify_ssl = true
jinja2 = "*"
pyyaml = "*"
markdown = "*"
lxml = "*"
lxml = "*"
292 changes: 143 additions & 149 deletions docs/Pipfile.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/build_manpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# Prevent our markdown parser from trying to help by interpreting things in angle brackets as HTML tags.
class EscapeHtml(Extension):

def extendMarkdown(self, md, md_globals):
del md.preprocessors['html_block']
del md.inlinePatterns['html']
def extendMarkdown(self, md):
md.preprocessors.deregister('html_block')
md.inlinePatterns.deregister('html')


class RoffWalker(object):
Expand Down
33 changes: 19 additions & 14 deletions docs/build_website.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
import glob
import itertools
from jinja2 import Environment, FileSystemLoader, Markup, select_autoescape, contextfunction
from jinja2 import Environment, FileSystemLoader, select_autoescape, pass_context
from markdown import markdown
from markupsafe import Markup
import os
import os.path
import re
Expand All @@ -20,40 +21,44 @@ def load_yml_file(fn):
return yaml.safe_load(f)


env.globals['url'] = 'https://jqlang.github.io/jq'
env.globals['root'] = '/jq'

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'] = contextfunction(
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 generate_file(env, fname='content/1.tutorial/default.yml'):
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,
Expand Down
2 changes: 1 addition & 1 deletion docs/content/download/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ body:
jq's documentation is compiled into static HTML using Python.
To build the docs, run `pipenv run python3 build_website.py` from
the docs/ subdirectory. To serve them locally, you can run
`python3 -m SimpleHTTPServer`. You'll need a few Python dependencies,
`python3 -m http.server`. You'll need a few Python dependencies,
which can be installed by following the instructions in `docs/README.md`.
The man page is built by `make jq.1`, or just `make`, also from
Expand Down
173 changes: 0 additions & 173 deletions docs/public/css/base.css

This file was deleted.

Loading

0 comments on commit 6dfa101

Please sign in to comment.