Skip to content

Commit 3ff7820

Browse files
authored
Merge pull request #275 from myoshi2891/dev-from-macmini
Add index.html and maintenance scripts
2 parents ba81102 + 04851be commit 3ff7820

177 files changed

Lines changed: 200393 additions & 94 deletions

File tree

Some content is hidden

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

INDEX_MAINTENANCE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Index Maintenance Guide
2+
3+
This project includes tools to automatically generate and update the `index.html` file, which serves as a categorized table of contents for all HTML documentation in the repository.
4+
5+
## How It Works
6+
7+
The index maintenance system consists of two main scripts:
8+
9+
1. **`generate_index.py`**: A Python script that:
10+
- Scans the directory structure.
11+
- Extracts titles from HTML files.
12+
- Copies HTML files to a clean `public/` directory.
13+
- **Vendors Dependencies**: Copies required libraries (React, Babel, PrismJS, etc.) from `node_modules` to `public/vendor`.
14+
- **Rewrites Links**: Updates HTML files to point to local `/vendor/...` assets instead of CDNs.
15+
- Generates a categorised `index.html` with a tabbed interface.
16+
17+
## Dependency Management
18+
19+
This project uses `bun` to manage dependencies.
20+
21+
- **Install Dependencies**: `bun install`
22+
- **Add New Library**: `bun add <library>`
23+
- **Vendor Logic**: If you add a new library, update `generate_index.py` to copy it to `public/vendor` and add a rewrite rule.
24+
25+
## Manual Update
26+
27+
To manually update the index (for example, after adding new problems), run the following command in the root directory:
28+
29+
```bash
30+
./update_index.sh
31+
```
32+
33+
This will populate the `public/` directory with the latest file structure and `index.html`.
34+
35+
## Automatic Update (Git Hook)
36+
37+
You can set up a Git **pre-commit hook** to automatically update the index every time you commit. This ensures `index.html` is always in sync with your changes.
38+
39+
### Setup Instructions
40+
41+
1. Make the wrapper script executable:
42+
43+
```bash
44+
chmod +x update_index.sh
45+
```
46+
47+
2. Create the hook file:
48+
49+
```bash
50+
touch .git/hooks/pre-commit
51+
```
52+
53+
3. Open `.git/hooks/pre-commit` in a text editor and add the following content:
54+
55+
```bash
56+
#!/bin/bash
57+
58+
# Generate index and populate public/ directory. Fail if scripts fail.
59+
echo "Updating public index..."
60+
./update_index.sh || exit 1
61+
62+
# Add public directory to the commit if modified
63+
if ! git diff --quiet public; then
64+
echo "Staging updated public directory..."
65+
git add public
66+
fi
67+
```
68+
69+
4. Make the hook executable:
70+
71+
```bash
72+
chmod +x .git/hooks/pre-commit
73+
```
74+
75+
### How it Works
76+
77+
Now, whenever you run `git commit`:
78+
79+
1. The hook runs `update_index.sh`. If it fails, the commit is aborted.
80+
2. The `public/` directory (including `index.html` and copied content) is updated.
81+
3. If `public/` has changed, it is automatically staged (`git add`).
82+
4. The commit proceeds with the updated public artifacts.

README.md

Lines changed: 107 additions & 94 deletions
Large diffs are not rendered by default.

bun.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)