Skip to content

Commit 8194e74

Browse files
authored
Merge pull request #22 from williln/fix-internal-readmes
Fix internal readmes
2 parents 8126c34 + 401da51 commit 8194e74

File tree

12 files changed

+86
-35
lines changed

12 files changed

+86
-35
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
python3 scripts/build_subdir_toc.py github
4747
python3 scripts/build_subdir_toc.py google
4848
python3 scripts/build_subdir_toc.py home-office
49+
python3 scripts/build_subdir_toc.py html
4950
python3 scripts/build_subdir_toc.py htmx
5051
python3 scripts/build_subdir_toc.py javascript
5152
python3 scripts/build_subdir_toc.py kubernetes
@@ -54,15 +55,23 @@ jobs:
5455
python3 scripts/build_subdir_toc.py meilisearch
5556
python3 scripts/build_subdir_toc.py microsoft-dynamics
5657
python3 scripts/build_subdir_toc.py misc
58+
python3 scripts/build_subdir_toc.py mkdocs
59+
python3 scripts/build_subdir_toc.py plata
60+
python3 scripts/build_subdir_toc.py postgres
61+
python3 scripts/build_subdir_toc.py pre-commit
5762
python3 scripts/build_subdir_toc.py pytest
5863
python3 scripts/build_subdir_toc.py python
5964
python3 scripts/build_subdir_toc.py r
65+
python3 scripts/build_subdir_toc.py seo
6066
python3 scripts/build_subdir_toc.py slack
67+
python3 scripts/build_subdir_toc.py sphinx
68+
python3 scripts/build_subdir_toc.py stripe
69+
python3 scripts/build_subdir_toc.py terraform
6170
python3 scripts/build_subdir_toc.py wagtail
6271
- name: Commit and push if anything changed
6372
run: |-
6473
git diff
6574
git config --global user.email "[email protected]"
6675
git config --global user.name "README-bot"
67-
git diff --quiet || (git add README.md && git commit -m "Updated READMEs")
76+
git diff --quiet || (git add README.md */README.md && git commit -m "Updated READMEs")
6877
git push

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/til.db
2+
.aider*

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
# til
22

3-
My repo of Today I Learned posts. Inspired by [simonw/til](https://github.com/simonw/til).
3+
My repo of Today I Learned posts. Inspired by [simonw/til](https://github.com/simonw/til).
44

5-
**Now**: July 2024: At some point this month, I set a goal to write a TIL every work day. I haven't stuck to that, but I am averaging several per week, and I'm pleased with the cadence. But even trying to post every day, I am still not capturing everything I've learned.
5+
**Now**: April 2025: I have really fallen out of the habit of writing these TILs. But I am still learning so much, so I'm going to start trying to get back into the practice. I still believe in the power of the TIL!
66

7-
## My TIL Philosophy
7+
## My TIL Philosophy
88

9-
Since this repo has a few stars ⭐ (hi everyone), I want to take a moment to set expectations.
9+
Since this repo has a few stars ⭐ (hi everyone), I want to take a moment to set expectations.
1010

1111
- I write TILs quickly, usually in under 10 minutes.
1212
- Usually, there isn't any editing other than light proofreading.
1313
- I really enjoy it! Highly recommend a public TIL repo as a personal practice.
1414
- Sometimes I share them on Mastodon, but not always.
1515

16-
## Benefits of my TIL repo
16+
## Benefits of my TIL repo for myself
1717

18-
- It's good, low-stakes writing practice.
19-
- It helps remind me that beginnerhood is perpetual.
20-
- I have a few of my own TILs that I consult really regularly. Nothing beats copying and pasting your own stuff forever.
21-
- Sometimes, the TILs get picked up by [Django News](https://django-news.com/issues/243?#start), and that's neat!
18+
- It's good, low-stakes writing practice.
19+
- It helps remind me that beginnerhood is perpetual.
20+
- I have a few of my own TILs that I consult really regularly. Nothing beats copying and pasting your own stuff forever.
21+
- Sometimes, the TILs get picked up by [Django News](https://django-news.com/issues/243?#start), and that's neat!
2222
- Other people are aware of what I am working on, and then ask for help related to those things. Feels great to help people.
2323
- It provides a neat fossil record of the kinds of things I've worked on over the course of my career.
24-
- I have a repo full of markdown that's easy to clone and run parsing experiments on.
24+
- I have a repo full of markdown that's easy to clone and run parsing experiments on, which has come in handy a few times for client work.
25+
- I break down a lot of concepts into small pieces for myself, which makes writing longer-form pieces easier.
2526

2627
---
2728

@@ -264,3 +265,19 @@ Since this repo has a few stars ⭐ (hi everyone), I want to take a moment to se
264265
* [Seeding my Wagtail site](https://github.com/williln/til/blob/main/wagtail/seeding_wagtail_site.md) - 2024-03-27
265266
* [What to do if you delete the default Wagtail homepage](https://github.com/williln/til/blob/main/wagtail/fix_deleted_root_page.md) - 2024-03-25
266267
<!-- index ends -->
268+
269+
<!-- docs-section starts -->
270+
271+
## Automatic README Generation
272+
273+
This repository uses GitHub Actions to automatically generate and update README files:
274+
275+
1. The main README.md (this file) is updated with:
276+
- A table of contents listing all topics
277+
- An index of all TIL posts organized by topic
278+
279+
2. Each subdirectory also gets its own README.md with links to all files in that directory.
280+
281+
These updates happen automatically whenever changes are pushed to the main branch.
282+
283+
<!-- docs-section ends -->

django/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- [How to confirm that login is required in your Django view](how_to_test_view_auth.md)
1616
- [How to log in a test user in a `pytest` unit test](test_protected_page.md)
1717
- [How to test a file upload with `pytest` and `SimpleUploadedFile`](testing_file_upload_pytest.md)
18+
- [Neapolitan: Everything I've Learned](neapolitan.md)
1819
- [Run SQL statements as part of your migrations with `migrations.RunSQL`](run_sql.md)
1920
- [Testing Django signals, and disabling signals in tests (Django 2.2)](testing_django_signals.md)
2021
- [Using Django Aggregation](aggregation.md)

git/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# git
22

3-
- [Moving from an old repo to a new repo in another organization](moving_to_a_new_repo.md)
3+
- [Checking out someone else's branch](check_out_remote_branch.md)
4+
- [Moving from an old repo to a new repo in another organization](moving_to_a_new_repo.md)
5+
- [Naming a `git stash` and re-applying it later](name_a_stash_and_apply_it.md)
6+
- [`git reset`, with `soft`: Undo your last commit but keep your changes](undo_commit_but_preserve_changes.md)

justfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ build-internal-readmes:
2323
python3 scripts/build_subdir_toc.py microsoft-dynamics
2424
python3 scripts/build_subdir_toc.py misc
2525
python3 scripts/build_subdir_toc.py mkdocs
26+
python3 scripts/build_subdir_toc.py plata
2627
python3 scripts/build_subdir_toc.py postgres
2728
python3 scripts/build_subdir_toc.py pre-commit
2829
python3 scripts/build_subdir_toc.py pytest
2930
python3 scripts/build_subdir_toc.py python
3031
python3 scripts/build_subdir_toc.py r
32+
python3 scripts/build_subdir_toc.py seo
3133
python3 scripts/build_subdir_toc.py slack
34+
python3 scripts/build_subdir_toc.py sphinx
3235
python3 scripts/build_subdir_toc.py stripe
3336
python3 scripts/build_subdir_toc.py terraform
34-
python3 scripts/build_subdir_toc.py wagtail
37+
python3 scripts/build_subdir_toc.py wagtail

kubernetes/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# kubernetes
22

33
- [Accessing a Kubernetes cluster for the first time](accessing_cluster.md)
4-
- [Setting up Kubernetes access on MacOS with a config file](setting_up_new_access_mac.md)
4+
- [Setting up Kubernetes access on MacOS with a config file](setting_up_new_access_mac.md)
5+
- [Viewing logs for your pod](viewing_logs.md)

plata/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# plata
2+
3+
- [[`plata`](https://github.com/matthiask/plata/) order processors](processors.md)

python/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
- [How to sort a Python dictionary by key or value](sort_dictionary.md)
88
- [How to sort a Python dictionary by multiple values](sort_dict_multiple_keys.md)
99
- [Using `Decimal.quantize`](decimal_quantize.md)
10-
- [Using `pip-tools` and `pip-compile` for Python dependency management](pip_tools.md)
10+
- [Using `pip-tools` and `pip-compile` for Python dependency management](pip_tools.md)
11+
- [`typing.final`](typing-final.md)

scripts/build_subdir_toc.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,51 @@
44

55

66
@click.command()
7-
@click.argument("directory", type=click.Path(exists=True))
7+
@click.argument("directory", type=click.Path())
88
def generate_readme_links(directory):
99
"""
1010
Generate a README file with clickable links to all files in the specified directory.
1111
1212
DIRECTORY: The path to the directory containing files.
1313
"""
14+
1415
readme_file = os.path.join(directory, "README.md")
1516

1617
with open(readme_file, "w") as f:
1718
# Use first h1 as the header
1819
header = os.path.basename(directory)
1920
f.write(f"# {header}\n\n")
2021

21-
for root, dirs, files in os.walk(directory):
22-
contents = []
23-
for file in files:
24-
title = None
25-
# Read the file so I can get the header, which contains the title.
26-
with open(os.path.join(root, file), "r") as file_obj:
27-
title = file_obj.readline().replace("#", "").strip()
22+
# Only process files if the directory exists and has files
23+
if os.path.exists(directory):
24+
for root, dirs, files in os.walk(directory):
25+
contents = []
26+
for file in files:
27+
# Skip the README file
28+
if file == "README.md":
29+
continue
30+
31+
file_path = os.path.join(root, file)
2832

29-
# Skip files that don't have a title.
30-
if not title:
31-
continue
33+
try:
34+
# Read the file so I can get the header, which contains the title
35+
with open(os.path.join(root, file), "r") as file_obj:
36+
title = file_obj.readline().replace("#", "").strip()
3237

33-
# Skip the README file.
34-
if file == "README.md":
35-
continue
38+
# Skip files that don't have a title
39+
if not title:
40+
continue
3641

37-
file_path = os.path.join(root, file)
38-
relative_path = os.path.relpath(file_path, directory)
39-
contents.append(f"- [{title}]({relative_path})")
42+
relative_path = os.path.relpath(file_path, directory)
43+
contents.append(f"- [{title}]({relative_path})")
44+
except Exception as e:
45+
click.echo(f"Warning: Could not process file {file}: {e}")
4046

41-
sorted_contents = sorted(contents)
42-
f.write("\n".join(sorted_contents))
47+
sorted_contents = sorted(contents)
48+
f.write("\n".join(sorted_contents))
4349

4450
click.echo(f"README file generated at {readme_file}")
4551

4652

4753
if __name__ == "__main__":
48-
generate_readme_links()
54+
generate_readme_links()

0 commit comments

Comments
 (0)