Skip to content

Commit c8e28da

Browse files
authored
Redesign website (jqlang#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.
1 parent 4af3f99 commit c8e28da

26 files changed

+401
-655
lines changed

Diff for: .github/workflows/website.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Python
2121
uses: actions/setup-python@v4
2222
with:
23-
python-version: '3.10'
23+
python-version: '3.11'
2424
cache: pipenv
2525
- name: Install pipenv
2626
run: pip install pipenv

Diff for: Makefile.am

+1-5
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,10 @@ endif
197197

198198
### Packaging
199199

200-
docs/site.yml: configure.ac
201-
sed 's/^jq_version: .*/jq_version: "$(VERSION)"/' $@ > $@.new
202-
mv $@.new $@
203-
204200
install-binaries: $(BUILT_SOURCES)
205201
$(MAKE) $(AM_MAKEFLAGS) install-exec
206202

207-
DOC_FILES = docs/content docs/public docs/templates docs/site.yml \
203+
DOC_FILES = docs/content docs/public docs/templates \
208204
docs/Pipfile docs/Pipfile.lock docs/build_manpage.py \
209205
docs/build_mantests.py docs/build_website.py docs/README.md \
210206
docs/validate_manual_schema.py docs/manual_schema.yml

Diff for: docs/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ need `python3` and `pipenv`. You can install `pipenv` like so:
1111

1212
Though, you may need to say `pip3` instead, depending on your system. Once
1313
you have `pipenv` installed, you can install the dependencies by running
14-
`pipenv sync` from the `docs` directory.
14+
`pipenv sync` from the `docs/` directory.
1515

1616
Also, you may need to run `virtualenv -p /usr/bin/python3 venv/` and
1717
then `source venv/bin/activate`, and only then `pipenv sync`.
1818

1919
Once this is done, rerun `./configure` in the jq root directory and then
20-
the Makefile will be able to generate the jq manpage. You can also just
21-
run `pipenv run build_manpage.py` in the `docs` directory to build the
22-
`jq.1` page manually, and `pipenv run build_mantests.py` to build the
23-
contents of `tests/man.test` and `tests/manonig.test`.
20+
the `Makefile` will be able to generate the jq manpage. You can just run
21+
`make jq.1` to build the manpage manually, and `make tests/man.test` to
22+
update the manual tests.
2423

25-
To build the website, run `pipenv run ./build_website.py` from inside
26-
the `docs` directory.
24+
To build the website, run `pipenv run python3 build_website.py --root /output`
25+
in the `docs/` directory. To serve them locally, you can run
26+
`python3 -m http.server`.

Diff for: docs/build_website.py

+27-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
import argparse
23
import glob
34
import itertools
45
from jinja2 import Environment, FileSystemLoader, select_autoescape, pass_context
@@ -10,6 +11,10 @@
1011
import shutil
1112
import yaml
1213

14+
parser = argparse.ArgumentParser()
15+
parser.add_argument('--root', default='/jq')
16+
args = parser.parse_args()
17+
1318
env = Environment(
1419
loader=FileSystemLoader('templates'),
1520
autoescape=select_autoescape(['html.j2']),
@@ -21,40 +26,51 @@ def load_yml_file(fn):
2126
return yaml.safe_load(f)
2227

2328

29+
env.globals['url'] = 'https://jqlang.github.io/jq'
30+
env.globals['root'] = args.root
31+
2432
env.filters['search_id'] = lambda input: input.replace(r'`', '')
25-
env.filters['section_id'] = lambda input: re.sub(r"[^a-zA-Z0-9_]", '', input)
26-
env.filters['entry_id'] = lambda input: re.sub(r"[ `]", '', input)
33+
env.filters['section_id'] = lambda input: re.sub(
34+
r'[^-a-zA-Z0-9_]', '', input.replace(' ', '-')).lower()
35+
env.filters['entry_id'] = lambda input: re.sub(
36+
r'^(split|first-last-nth)$',
37+
r'\1' + ('-1' if ';' not in input else '-2'), # avoid id conflict
38+
re.sub(
39+
r'\b([^-]+)(?:-\1)+\b',
40+
r'\1', # e.g. range-range-range -> range
41+
re.sub(r' ?/ ?|,? ', '-',
42+
re.sub(r'[`;]|: .*|\(.*?\)| \[.+\]', '', input)))).lower()
2743
env.filters['markdownify'] = lambda input: Markup(markdown(input))
28-
env.filters['no_paragraph'] = lambda input: Markup(re.sub(r"</?p>", '', input))
44+
env.filters['no_paragraph'] = lambda input: Markup(re.sub(r'</?p>', '', input))
2945

3046
env.globals['unique_id'] = pass_context(
3147
lambda ctx: str(next(ctx['unique_ctr'])))
3248

33-
env.globals.update(load_yml_file('site.yml'))
3449

35-
env.globals['navigation'] = ['tutorial', 'download', 'manual']
50+
def raise_handler(message):
51+
raise Exception(message)
52+
53+
54+
env.globals['raise'] = raise_handler
3655

3756

38-
def generate_file(env, fname='content/1.tutorial/default.yml'):
57+
def generate_file(env, fname):
3958
path, base = os.path.split(fname)
4059
path = os.path.relpath(path, 'content')
4160
if path == '.':
4261
path = ''
43-
slug = 'index'
4462
permalink = ''
4563
else:
46-
slug = os.path.basename(path)
4764
permalink = path + '/'
4865

4966
output_dir = os.path.join('output', path)
5067
output_path = os.path.join(output_dir, 'index.html')
5168

52-
template_name = re.sub(r".yml$", '.html.j2', base)
69+
template_name = re.sub(r'.yml$', '.html.j2', base)
5370

5471
ctx = load_yml_file(fname)
5572
ctx.update(unique_ctr=itertools.count(1),
5673
permalink=permalink,
57-
slug=slug,
5874
navitem=path)
5975
os.makedirs(output_dir, exist_ok=True)
6076
env.get_template(template_name).stream(ctx).dump(output_path,
@@ -72,6 +88,7 @@ def copy_public_files(root=''):
7288
shutil.copyfile(f.path, dst)
7389

7490

91+
os.makedirs('output', exist_ok=True)
7592
copy_public_files()
7693

7794
for fn in glob.glob('content/**/*.yml', recursive=True):

Diff for: docs/content/download/default.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ body:
196196
#### Building the documentation
197197
198198
jq's documentation is compiled into static HTML using Python.
199-
To build the docs, run `pipenv run python3 build_website.py` from
200-
the docs/ subdirectory. To serve them locally, you can run
201-
`python3 -m SimpleHTTPServer`. You'll need a few Python dependencies,
199+
To build the docs, run `pipenv run python3 build_website.py --root /output`
200+
in the `docs/` directory. To serve them locally, you can run
201+
`python3 -m http.server`. You'll need a few Python dependencies,
202202
which can be installed by following the instructions in `docs/README.md`.
203203
204204
The man page is built by `make jq.1`, or just `make`, also from

Diff for: docs/content/index.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ body3: |
2424
2525
tail: |
2626
27-
Go read the [tutorial](/jq/tutorial/) for more, or the [manual](/jq/manual/)
27+
Go read the [tutorial](./tutorial/) for more, or the [manual](./manual/)
2828
for *way* more.
2929
3030
Have a question related to jq? You can seek answers on [Stack Overflow](https://stackoverflow.com/)
@@ -34,7 +34,7 @@ tail: |
3434
news:
3535
- date: 1 November 2018
3636
body: |
37-
jq 1.6 released. See installation options on the [download](/jq/download/)
37+
jq 1.6 released. See installation options on the [download](./download/)
3838
page, and the [release notes](https://github.com/jqlang/jq/releases/tag/jq-1.6)
3939
for details.
4040
@@ -44,7 +44,7 @@ news:
4444
jq 1.5 released, including new datetime, math, and regexp functions,
4545
try/catch syntax, array and object destructuring, a streaming parser,
4646
and a module system. See installation options on the
47-
[download](/jq/download/) page, and the
47+
[download](./download/) page, and the
4848
[release notes](https://github.com/jqlang/jq/releases/tag/jq-1.5)
4949
for details.
5050
@@ -63,7 +63,7 @@ news:
6363
- date: 09 June 2014
6464
body: |
6565
66-
jq 1.4 (finally) released! Get it on the [download](/jq/download/) page.
66+
jq 1.4 (finally) released! Get it on the [download](./download/) page.
6767
6868
- date: 19 May 2013
6969
body: |

Diff for: docs/content/manual/manual.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ headline: jq Manual (development version)
33

44
history: |
55
6-
*For released versions, see [jq 1.6](/jq/manual/v1.6),
7-
[jq 1.5](/jq/manual/v1.5), [jq 1.4](/jq/manual/v1.4)
8-
or [jq 1.3](/jq/manual/v1.3).*
6+
*For released versions, see [jq 1.6](./v1.6/), [jq 1.5](./v1.5/),
7+
[jq 1.4](./v1.4/) or [jq 1.3](./v1.3/).*
98
109
body: |
1110

Diff for: docs/content/manual/v1.3/manual.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ headline: jq 1.3 Manual
44
history: |
55
66
*The manual for the development version of jq can be found
7-
[here](/jq/manual).*
7+
[here](../).*
88
99
body: |
1010

Diff for: docs/content/manual/v1.4/manual.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ headline: jq 1.4 Manual
44
history: |
55
66
*The manual for the development version of jq can be found
7-
[here](/jq/manual).*
7+
[here](../).*
88
99
body: |
1010

Diff for: docs/content/manual/v1.5/manual.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ headline: jq 1.5 Manual
44
history: |
55
66
*The manual for the development version of jq can be found
7-
[here](/jq/manual).*
7+
[here](../).*
88
99
body: |
1010

Diff for: docs/content/manual/v1.6/manual.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ headline: jq 1.6 Manual
44
history: |
55
66
*The manual for the development version of jq can be found
7-
[here](/jq/manual).*
7+
[here](../).*
88
99
body: |
1010

0 commit comments

Comments
 (0)