Skip to content

Commit cd1bead

Browse files
authored
Merge pull request #978 from pre-commit/featured-hooks
replace all-repos.yaml with a curated list of tools
2 parents 338b021 + 53aacc6 commit cd1bead

File tree

10 files changed

+182
-220
lines changed

10 files changed

+182
-220
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
*.html
22
*.pyc
3-
*.swp
4-
/all-hooks.json
53
/build
64
/node_modules

.pre-commit-config.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,3 @@ repos:
4242
hooks:
4343
- id: biome-check
4444
additional_dependencies: ["@biomejs/[email protected]"]
45-
- repo: local
46-
hooks:
47-
- id: no-github-dot-git
48-
name: No need for .git for github/gitlab urls
49-
entry: '(github|gitlab).*\.git'
50-
files: all-repos.yaml
51-
language: pygrep
52-
- id: no-github-trailing-slash
53-
name: No need for trailing / for urls
54-
entry: '.*/$'
55-
files: all-repos.yaml
56-
language: pygrep

Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all: install-hooks build/main_bs5.css all-hooks.json index.html hooks.html
1+
all: install-hooks build/main_bs5.css index.html hooks.html
22

33
.PHONY: install-hooks
44
install-hooks: venv
@@ -7,10 +7,7 @@ install-hooks: venv
77
build/main_bs5.css: node_modules build scss/main_bs5.scss scss/_variables.scss
88
node_modules/.bin/sass --style=compressed --load-path=. scss/main_bs5.scss build/main_bs5.css
99

10-
all-hooks.json: venv make_all_hooks.py all-repos.yaml
11-
venv/bin/python make_all_hooks.py
12-
13-
index.html hooks.html: venv all-hooks.json base.mako index.mako hooks.mako make_templates.py template_lib.py sections/*.md
10+
index.html hooks.html: venv base.mako index.mako hooks.mako make_templates.py template_lib.py sections/*.md
1411
venv/bin/python make_templates.py
1512

1613
venv: requirements-dev.txt Makefile
@@ -28,11 +25,10 @@ node_modules: package.json
2825
push: venv
2926
venv/bin/markdown-to-presentation push \
3027
.nojekyll README.md CNAME \
31-
build assets *.html *.png *.svg favicon.ico \
32-
all-hooks.json
28+
build assets *.html *.png *.svg favicon.ico
3329

3430
clean:
35-
rm -rf venv build node_modules *.html all-hooks.json
31+
rm -rf venv build node_modules *.html
3632

3733
build:
3834
mkdir -p build

assets/filter_repos.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

hooks.mako

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,4 @@
33

44
<div class="page-header"><h1>Supported hooks</h1></div>
55

6-
<div class="row mb-4">
7-
<div class="col">
8-
<label for="search-hook-id" class="mb-2">Filter hook id:</label>
9-
<input id="search-hook-id" type="text" placeholder="filter hook id" class="form-control form-control-sm"></input>
10-
</div>
11-
<div class="col">
12-
<label for="search-hook-id" class="mb-2">Filter hook type:</label>
13-
<select id="select-hook-type" class="form-select form-select-sm">
14-
<option value="">--</option>
15-
% for hook_type in sorted(all_types, key=str.lower):
16-
<option value="${hook_type}">${hook_type}</option>
17-
% endfor
18-
</select>
19-
</div>
20-
</div>
21-
22-
<p>
23-
To add to this list, fork <a href="https://github.com/pre-commit/pre-commit.com">this repository</a>.
24-
</p>
25-
26-
<p>
27-
Also available in <a href="/all-hooks.json">json</a>.
28-
</p>
29-
30-
<div id="hooks">
31-
% for repository, hooks in all_hooks.items():
32-
<h3 data-repo="${repository}">
33-
<a href="${repository}" target="_blank">
34-
${repository.replace('https://', '')}
35-
</a>
36-
</h3>
37-
<ul data-repo="${repository}">
38-
% for hook_dict in hooks:
39-
<li data-id="${hook_dict['id']}" data-types="${', '.join(hook_dict.get('types', []) + hook_dict.get('types_or', []))}">
40-
<code>${hook_dict['id']}</code>
41-
% if hook_dict.get('description'):
42-
- ${hook_dict['description']}
43-
% elif hook_dict['name'].lower() != hook_dict['id'].lower():
44-
- ${hook_dict['name']}
45-
% endif
46-
</li>
47-
% endfor
48-
</ul>
49-
% endfor
50-
</div>
51-
52-
<script src="assets/filter_repos.js"></script>
6+
${body}

make_all_hooks.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

make_templates.py

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
from __future__ import annotations
22

3-
import collections
4-
import json
53
import os.path
6-
from typing import Any
74

85
import mako.lookup
96
import markupsafe
@@ -29,13 +26,7 @@
2926
)
3027

3128

32-
ALL_TEMPLATES = [
33-
filename for filename in os.listdir('.')
34-
if filename.endswith('.mako') and filename != 'base.mako'
35-
]
36-
37-
38-
def get_env() -> dict[str, Any]:
29+
def index_body() -> markupsafe.Markup:
3930
body_parts = []
4031
for title, filename in SECTIONS:
4132
div_id, _ = os.path.splitext(os.path.basename(filename))
@@ -50,30 +41,22 @@ def get_env() -> dict[str, Any]:
5041
f'</div>\n',
5142
),
5243
)
53-
body = markupsafe.Markup().join(body_parts)
44+
return markupsafe.Markup().join(body_parts)
5445

55-
all_hooks = json.loads(
56-
open('all-hooks.json').read(),
57-
object_pairs_hook=collections.OrderedDict,
58-
)
59-
all_types = {
60-
hook_type
61-
for properties in all_hooks.values()
62-
for hook_type in (
63-
properties[0].get('types', []) + properties[0].get('types_or', [])
64-
)
65-
}
66-
return {'all_hooks': all_hooks, 'all_types': all_types, 'body': body}
46+
47+
def hooks_body() -> markupsafe.Markup:
48+
with open('sections/hooks.md') as f:
49+
return md(f.read())
6750

6851

6952
def main() -> int:
70-
env = get_env()
71-
for template in ALL_TEMPLATES:
72-
template_name, _ = os.path.splitext(template)
73-
env['template_name'] = template_name
74-
with open(f'{template_name}.html', 'w') as html_file:
75-
template_obj = template_lookup.get_template(template)
76-
html_file.write(template_obj.render(**env))
53+
with open('index.html', 'w') as f:
54+
tmpl = template_lookup.get_template('index.mako')
55+
f.write(tmpl.render(body=index_body(), template_name='index'))
56+
57+
with open('hooks.html', 'w') as f:
58+
tmpl = template_lookup.get_template('hooks.mako')
59+
f.write(tmpl.render(body=hooks_body(), template_name='hooks'))
7760
return 0
7861

7962

0 commit comments

Comments
 (0)