Skip to content

Commit 73af42a

Browse files
committed
Add TOC to README
1 parent 799b84f commit 73af42a

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,33 @@
99

1010
---
1111

12+
**Table of contents:**
13+
14+
<!-- toc -->
15+
16+
- [General API Stuff](#general-api-stuff)
17+
* [CORS](#cors)
18+
- [Authentication - JWT](#authentication---jwt)
19+
* [Settings](#settings)
20+
* [APIs](#apis)
21+
* [Requiring authentication](#requiring-authentication)
22+
- [Authentication - Sessions](#authentication---sessions)
23+
* [DRF & Overriding `SessionAuthentication`](#drf--overriding-sessionauthentication)
24+
* [Cross origin](#cross-origin)
25+
* [APIs](#apis-1)
26+
* [`HTTP Only` / `SameSite`](#http-only--samesite)
27+
* [Reading list](#reading-list)
28+
- [Example List API](#example-list-api)
29+
- [Helpful commands for local development without docker-compose](#helpful-commands-for-local-development-without-docker-compose)
30+
- [Helpful commands for local development with docker-compose](#helpful-commands-for-local-development-with-docker-compose)
31+
- [Deployment](#deployment)
32+
* [Heroku](#heroku)
33+
* [AWS ECS](#aws-ecs)
34+
35+
<!-- tocstop -->
36+
37+
---
38+
1239
This project serves as an [example of our styleguide](https://github.com/HackSoftware/Django-Styleguide)
1340

1441
The structure is inspired by [cookiecutter-django](https://github.com/pydanny/cookiecutter-django) and modified based on our experience with Django.

markdown_tools/toc.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import re
2+
from subprocess import check_output
3+
4+
5+
def get_new_toc():
6+
new_toc = check_output(
7+
'markdown-toc README.md',
8+
shell=True
9+
).decode('utf-8')
10+
11+
pattern = ['<!-- toc -->', '', new_toc, '', '<!-- tocstop -->']
12+
13+
return '\n'.join(pattern)
14+
15+
16+
def get_readme():
17+
with open('README.md', 'r') as f:
18+
return f.read()
19+
20+
21+
def save_readme(readme):
22+
with open('README.md', 'w') as f:
23+
return f.write(readme)
24+
25+
26+
def replace_toc():
27+
readme = get_readme()
28+
new_toc = get_new_toc()
29+
30+
regex = '<!-- toc -->(.|\n)+<!-- tocstop -->'
31+
32+
new_readme = re.sub(regex, new_toc, readme)
33+
34+
save_readme(new_readme)
35+
36+
print('TOC updated ...')
37+
38+
39+
def main():
40+
return replace_toc()
41+
42+
43+
if __name__ == '__main__':
44+
main()

0 commit comments

Comments
 (0)