Skip to content

Commit 37b9858

Browse files
authored
Merge pull request #35 from haplo/pre-commit
pre-commit hooks
2 parents 97708d2 + 0700429 commit 37b9858

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+798
-778
lines changed

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: check-json
7+
exclude: ^package-lock\.json$
8+
- id: check-yaml
9+
- id: check-case-conflict
10+
- id: check-merge-conflict
11+
12+
- repo: https://github.com/djlint/djLint
13+
rev: v1.36.4
14+
hooks:
15+
- id: djlint-reformat
16+
files: \.html$
17+
types: [file]
18+
- id: djlint
19+
files: \.html$
20+
types: [file]
21+
22+
- repo: local
23+
hooks:
24+
- id: npm-build-check
25+
name: Check compiled assets
26+
entry: bash -c 'npm run build && git diff --exit-code static/stylesheet/*.min.css static/dark-theme/*.min.js static/pygments/*.min.css'
27+
language: system
28+
files: ^(gulpfile\.js|static/stylesheet/.*\.less|static/dark-theme/.*\.js|static/pygments/.*\.css)$
29+
pass_filenames: false

AGENTS.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ make publish
121121
└── package.json # Node.js dependencies
122122
```
123123

124+
## Pre-commit Hooks
125+
126+
Pre-commit hooks run automatically on `git commit` to ensure code quality:
127+
128+
```bash
129+
# Install pre-commit (one-time setup)
130+
pip install pre-commit
131+
pre-commit install
132+
133+
# Run manually on all files
134+
pre-commit run --all-files
135+
```
136+
137+
Hooks configured:
138+
- **trailing-whitespace** - File hygiene
139+
- **check-json / check-yaml** - Validate config files
140+
- **djlint** - Format and lint Jinja2 templates
141+
- **npm-build-check** - Verify compiled assets are up to date (runs only when source files change)
142+
124143
## Testing
125144

126145
- Tests build the example/ site as a smoke test
@@ -181,9 +200,8 @@ PyPI publishing is automated via the `pypi-publish.yml` workflow when a `v*` tag
181200

182201
## Notes
183202

184-
- Always rebuild assets (`npm run build`) before committing
203+
- Pre-commit hooks enforce code style and verify compiled assets
185204
- A PR check (`check-npm-build.yml`) verifies that built assets are up to date; PRs with stale assets cannot be merged
186205
- The theme supports both light and dark modes
187206
- Font Awesome is copied from node_modules to static/
188207
- Pygments styles are minified but kept as separate files
189-
- No linting tools are configured - follow existing code style

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2020
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
SOFTWARE.
23-

docs/developing.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Reflex uses gulp to compile LESS files into CSS and optimize the final build.
44

55
## Setup
66

7-
`npm install`
7+
```bash
8+
npm install
9+
pip install pre-commit # or install system-wide
10+
pre-commit install
11+
```
812

913
## Compilation
1014

@@ -32,3 +36,18 @@ To deploy to Github Pages:
3236
```shell
3337
make github
3438
```
39+
40+
## Pre-commit Hooks
41+
42+
[Pre-commit](https://pre-commit.com/) hooks run automatically on each commit to enforce code style and verify compiled assets:
43+
44+
```bash
45+
# Run manually on all files
46+
pre-commit run --all-files
47+
```
48+
49+
Hooks include:
50+
- File hygiene (trailing whitespace, EOF fixes)
51+
- JSON/YAML validation
52+
- Template formatting and linting with [djlint](https://djlint.com/)
53+
- Asset build verification (when LESS source files change)

example/content/articles/reflex-pelican-theme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Slug: reflex-pelican-theme
66
Cover: images/reflex-screenshot.png
77

88
When I started [my blog](https://blog.fidelramos.net) I looked all the options in the [Pelican theme
9-
gallery](http://www.pelicanthemes.com/), and decided on the [Flex theme by Alexandre
9+
gallery](https://pelicanthemes.com/), and decided on the [Flex theme by Alexandre
1010
Vizenzi](https://github.com/alexandrevicenzi/Flex) as the best one for my needs:
1111

1212
- Minimalistic and beautiful.
@@ -44,7 +44,7 @@ Mem: 5866 4674 1192 386 0 2404
4444
Swap: 20480 1267 19213
4545
</samp>
4646

47-
If you like to share code snippets, you can take advantage of [Pygments](http://pygments.org/) syntax highlighting:
47+
If you like to share code snippets, you can take advantage of [Pygments](https://pygments.org/) syntax highlighting:
4848

4949
```js
5050
// Javascript

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ excludes = [
4141
"**/.DS_Store",
4242
"**/__pycache__/**",
4343
]
44+
45+
[tool.djlint]
46+
indent = 2
47+
profile = "jinja"
48+
ignore = "H006,H013,H019,H021,H022,H023,H031,T002,T028,T032"

templates/archives.html

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
{% extends "base.html" %}
2-
3-
{% block title %} &ndash; {{ _('Archives') }}{% endblock %}
4-
2+
{% block title %}
3+
&ndash; {{ _("Archives") }}
4+
{% endblock title %}
55
{% block content %}
6-
<article class="single">
7-
<header>
8-
<h1 id="archives">{{ _('Archives') }}</h1>
9-
</header>
10-
<div>
11-
<dl>
12-
{% set previous_date = False %}
13-
14-
{% for article in dates %}
15-
{% if article.locale_date != previous_date %}
16-
{% set previous_date = article.locale_date %}
17-
<dt>{{ article.locale_date }}</dt>
18-
{% endif %}
19-
20-
<dd>
21-
<a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a>
22-
</dd>
23-
{% endfor %}
24-
</dl>
25-
</div>
26-
</article>
27-
{% endblock %}
6+
<article class="single">
7+
<header>
8+
<h1 id="archives">{{ _("Archives") }}</h1>
9+
</header>
10+
<div>
11+
<dl>
12+
{% set previous_date = False %}
13+
{% for article in dates %}
14+
{% if article.locale_date != previous_date %}
15+
{% set previous_date = article.locale_date %}
16+
<dt>{{ article.locale_date }}</dt>
17+
{% endif %}
18+
<dd>
19+
<a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a>
20+
</dd>
21+
{% endfor %}
22+
</dl>
23+
</div>
24+
</article>
25+
{% endblock content %}

0 commit comments

Comments
 (0)