Skip to content

Commit a5a5030

Browse files
committed
1 parent 1fa336f commit a5a5030

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

.github/workflows/deploy.yaml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
name: Deploy
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out source code
11+
uses: actions/checkout@v3
12+
with:
13+
fetch-depth: 0
14+
- name: Install mdbook
15+
run: |
16+
mkdir 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
18+
echo `pwd`/mdbook >> $GITHUB_PATH
19+
- name: Generate book
20+
run: |
21+
./generate-book.py
22+
- name: Publish book
23+
uses: JamesIves/github-pages-deploy-action@v4
24+
with:
25+
repository-name: amaranth-lang/amaranth-lang.github.io
26+
ssh-key: ${{ secrets.PAGES_DEPLOY_KEY }}
27+
branch: main
28+
folder: book/
29+
target-folder: rfcs/

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/src/
2+
/book/

book.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[book]
2+
title = "The Amaranth RFC Book"
3+
4+
[output.html]
5+
no-section-label = true
6+
git-repository-url = "https://github.com/amaranth-lang/rfcs"
7+
8+
[output.html.search]
9+
heading-split-level = 0
10+
11+
[output.html.playground]
12+
runnable = false

generate-book.py

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

0 commit comments

Comments
 (0)