Skip to content

Commit c0a2cef

Browse files
authored
Merge pull request #3388 from ehuss/generate-subpages
Add support for rfc subchapters
2 parents 5c8d632 + 0eb7dfb commit c0a2cef

File tree

5 files changed

+63
-25
lines changed

5 files changed

+63
-25
lines changed

.github/workflows/deploy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
- name: Install mdbook
1515
run: |
1616
mkdir mdbook
17-
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.21/mdbook-v0.4.21-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
17+
curl -Lf https://github.com/rust-lang/mdBook/releases/download/v0.4.26/mdbook-v0.4.26-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
1818
echo `pwd`/mdbook >> $GITHUB_PATH
1919
- name: Generate Book
2020
run: |
21-
./generate-book.sh
21+
./generate-book.py
2222
- name: Deploy GitHub Pages
2323
run: |
2424
git worktree add gh-pages gh-pages

generate-book.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
This auto-generates the mdBook SUMMARY.md file based on the layout on the filesystem.
5+
6+
This generates the `src` directory based on the contents of the `text` directory.
7+
8+
Most RFCs should be kept to a single chapter. However, in some rare cases it
9+
may be necessary to spread across multiple pages. In that case, place them in
10+
a subdirectory with the same name as the RFC. For example:
11+
12+
0123-my-awesome-feature.md
13+
0123-my-awesome-feature/extra-material.md
14+
15+
It is recommended that if you have static content like images that you use a similar layout:
16+
17+
0123-my-awesome-feature.md
18+
0123-my-awesome-feature/diagram.svg
19+
20+
The chapters are presented in sorted-order.
21+
"""
22+
23+
import os
24+
import shutil
25+
import subprocess
26+
27+
def main():
28+
if os.path.exists('src'):
29+
# Clear out src to remove stale links in case you switch branches.
30+
shutil.rmtree('src')
31+
os.mkdir('src')
32+
33+
for path in os.listdir('text'):
34+
symlink(f'../text/{path}', f'src/{path}')
35+
symlink('../README.md', 'src/introduction.md')
36+
37+
with open('src/SUMMARY.md', 'w') as summary:
38+
summary.write('[Introduction](introduction.md)\n\n')
39+
collect(summary, 'text', 0)
40+
41+
subprocess.call(['mdbook', 'build'])
42+
43+
def collect(summary, path, depth):
44+
entries = [e for e in os.scandir(path) if e.name.endswith('.md')]
45+
entries.sort(key=lambda e: e.name)
46+
for entry in entries:
47+
indent = ' '*depth
48+
name = entry.name[:-3]
49+
link_path = entry.path[5:]
50+
summary.write(f'{indent}- [{name}]({link_path})\n')
51+
maybe_subdir = os.path.join(path, name)
52+
if os.path.isdir(maybe_subdir):
53+
collect(summary, maybe_subdir, depth+1)
54+
55+
def symlink(src, dst):
56+
if not os.path.exists(dst):
57+
os.symlink(src, dst)
58+
59+
if __name__ == '__main__':
60+
main()

generate-book.sh

-22
This file was deleted.

text/2856-project-groups.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ explicitly re-proposed through the project group process detailed in this RFC.
5353
This is a high level overview of the complete process of a project group.
5454

5555
<p align="center">
56-
<img src="../resources/project-group-workflow.svg"
56+
<img src="2856-project-groups/project-group-workflow.svg"
5757
alt="A flow diagram showing each step of a project group"
5858
height="800px">
5959
<p align="center">Figure 1. Project Group Lifecycle</p>

0 commit comments

Comments
 (0)