|
1 | | -# Welcome to Better Code |
| 1 | +# Better Code |
2 | 2 |
|
3 | | -This is the development home of the STLab Better Code course. |
| 3 | +Development repository for the STLab Better Code course. |
4 | 4 |
|
5 | | -## Working with the Book |
| 5 | +**Read the book:** https://stlab.github.io/better-code/ |
6 | 6 |
|
7 | | -We're migrating from using Jekyll to using |
8 | | -[mdBook](https://github.com/rust-lang/mdBook). The mdBook version is located in |
9 | | -the `./better-code` directory and includes automated CI/CD deployment to GitHub Pages. |
| 7 | +## Quick Start |
10 | 8 |
|
11 | | -## Installing and updating mdBook |
| 9 | +### 1. Install Prerequisites |
12 | 10 |
|
13 | | -Install [Rust and |
14 | | -Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html): |
| 11 | +Install [Rust and Cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html). |
15 | 12 |
|
16 | | -Linux and macOS: |
17 | 13 |
|
18 | | -``` |
19 | | -curl https://sh.rustup.rs -sSf | sh |
20 | | -``` |
21 | | - |
22 | | -On Windows, you can download the installer from |
23 | | -[here](https://win.rustup.rs/). |
24 | | - |
25 | | -Once you have Rust and Cargo installed, you can install or upgrade mdBook by running: |
| 14 | +### 2. Install mdBook and Plugins |
26 | 15 |
|
| 16 | +**Linux/macOS:** |
| 17 | +```bash |
| 18 | +./scripts/install-tools.sh |
27 | 19 | ``` |
28 | | -cargo install mdbook |
| 20 | + |
| 21 | +**Windows (PowerShell):** |
| 22 | +```powershell |
| 23 | +.\scripts\install-tools.ps1 |
29 | 24 | ``` |
30 | 25 |
|
31 | | -## Building the book |
| 26 | +These scripts install mdBook and all required plugins using versions from `versions.txt`. |
32 | 27 |
|
33 | | -To build the book, run: |
| 28 | +### 3. Build and Serve |
34 | 29 |
|
35 | | -``` |
| 30 | +```bash |
36 | 31 | mdbook serve ./better-code |
37 | 32 | ``` |
38 | 33 |
|
39 | | -Open the browser to http://localhost:3000 to see the book. You can use the |
40 | | -Simple Browser in VSCode/Cursor to view the book while editing. |
| 34 | +Open http://localhost:3000 in your browser. |
41 | 35 |
|
42 | | -## Automated Deployment |
| 36 | +## Contributing |
43 | 37 |
|
44 | | -The mdBook is automatically built and deployed to GitHub Pages using GitHub Actions. |
45 | | -When you push changes to the main branch: |
| 38 | +### Editing Content |
46 | 39 |
|
47 | | -1. GitHub Actions will build the book using mdBook |
48 | | -2. The built book will be deployed to GitHub Pages |
49 | | -3. The book will be available at https://stlab.github.io/better-code/ |
| 40 | +1. Edit markdown files in `better-code/src/` |
| 41 | +2. Add new chapters by creating `.md` files and updating `better-code/src/SUMMARY.md` |
| 42 | +3. Changes automatically rebuild when you push to the main branch |
50 | 43 |
|
51 | | -No manual deployment steps are required! |
| 44 | +### Content Conventions |
52 | 45 |
|
53 | | -### Conventions and Guidelines |
| 46 | +* Use Markdown formatting; avoid unnecessary HTML |
| 47 | +* Wrap lines at 80 columns for diff-friendly change tracking |
| 48 | +* Start each chapter with a level-2 heading (`## Chapter Name`) |
| 49 | +* Use level-3+ headings within chapters |
| 50 | +* Keep file names and heading titles stable for linkability |
54 | 51 |
|
55 | | -* Avoid unnecessary HTML tags; use Markdown formatting to the degree possible. |
56 | | -* Wrap lines at 80 columns to support diff-friendly change tracking. |
57 | | -* Chapters are represented as individual Markdown files in the chapters/ |
58 | | - subdirectory. |
59 | | -* Each chapter begins with a 2nd-level heading, e.g. `## Chapter Name`. All |
60 | | - other headings in a chapter are 3rd-level and below. |
61 | | -* Each file's name starts with a 4-digit number that determines its order in the |
62 | | - overall document. Initial numbering is spaced by 100s. |
63 | | -* Maintain stable file names and heading titles for linkability until another |
64 | | - solution is in place. |
| 52 | +## Deployment |
65 | 53 |
|
66 | | -### Older draft |
| 54 | +### CI/CD Pipeline |
67 | 55 |
|
68 | | -Please see the [latest published draft](https://stlab.github.io/better-code/) |
69 | | -for information about the motivation for this project. |
| 56 | +**Pull Requests:** |
| 57 | +- Validates build on Ubuntu and Windows |
| 58 | +- No deployment; PR check shows build status |
70 | 59 |
|
71 | | -### Infrastructure |
| 60 | +**Main Branch:** |
| 61 | +- Builds book using mdBook with versions from `versions.txt` |
| 62 | +- Deploys to GitHub Pages |
| 63 | +- Available at https://stlab.github.io/better-code/ |
72 | 64 |
|
73 | | -The book is being migrated from [Jekyll](https://jekyllrb.com) to [mdBook](https://github.com/rust-lang/mdBook). |
74 | | -The new mdBook version is automatically built and deployed to [GitHub Pages](https://pages.github.com) using GitHub Actions. |
| 65 | +### Managing Dependencies |
75 | 66 |
|
76 | | -The legacy Jekyll files remain in the root directory for reference during the transition. |
| 67 | +All tool versions are centrally managed in `versions.txt`. To update: |
77 | 68 |
|
78 | | -### Running a local server |
| 69 | +1. Edit version number in `versions.txt` |
| 70 | +2. Run the appropriate install script locally |
| 71 | +3. Test with `mdbook serve ./better-code` |
| 72 | +4. Commit - CI automatically uses the new version |
79 | 73 |
|
80 | | -If you are able to install the necessary parts for jekyll, |
| 74 | +## Project Structure |
81 | 75 |
|
82 | 76 | ``` |
83 | | -bundle exec jekyll serve -l |
| 77 | +better-code/ # mdBook source and configuration |
| 78 | +├── src/ # Markdown chapter files |
| 79 | +├── book.toml # mdBook configuration |
| 80 | +└── book/ # Generated HTML (gitignored) |
| 81 | +
|
| 82 | +scripts/ # Installation scripts |
| 83 | +├── install-tools.sh # Linux/macOS |
| 84 | +└── install-tools.ps1 # Windows |
| 85 | +
|
| 86 | +versions.txt # Single source of truth for tool versions |
| 87 | +archive/ # Legacy Jekyll site (for reference only) |
84 | 88 | ``` |
85 | 89 |
|
86 | | -will start a server for the site at http://localhost:4000. |
| 90 | +## Advanced Usage |
87 | 91 |
|
88 | | -Creating a complete installation of jekyll and all the parts needed for github |
89 | | -pages development can be fraught. If you install |
90 | | -[docker-compose](https://docs.docker.com/compose/), you can start the server |
91 | | -by invoking |
92 | 92 |
|
| 93 | +### Building Without Serving |
| 94 | + |
| 95 | +```bash |
| 96 | +mdbook build ./better-code |
93 | 97 | ``` |
94 | | -docker-compose up |
| 98 | + |
| 99 | +Output will be in `./better-code/book/`. |
| 100 | + |
| 101 | + |
| 102 | +## Legacy Content |
| 103 | + |
| 104 | +The `archive/` directory contains the legacy Jekyll site for reference during migration. |
| 105 | +You can safely ignore it unless working on migration tasks. |
| 106 | + |
| 107 | +To run the Jekyll version (not recommended for regular development): |
| 108 | + |
| 109 | +```bash |
| 110 | +bundle exec jekyll serve -l # Starts server at http://localhost:4000 |
95 | 111 | ``` |
96 | 112 |
|
97 | | -in the root directory of your working copy. |
| 113 | +Or with Docker: |
| 114 | + |
| 115 | +```bash |
| 116 | +docker-compose up |
| 117 | +``` |
0 commit comments