# Dewey's Rustbook Build

All redundant assets (CSS files, JS bundles, custom fonts, themes, and favicons) have been removed. The HTML pages have been cleaned up in place to keep only the structural content, organized into folders, and their relative links updated.

## Setup and Cleanup Script

The cleanup and folder organization are powered by [clean_book.py](file:///home/sortedcord/Projects/docs-rust/clean_book.py).

### What the script does:
1. **HTML Clean-up**: For each HTML file, it extracts only the main content inside the `<main>...</main>` tag (or fallback to `<body>`), and strips out the header scripts, navigation sidebar wrappers, theme toggles, templates, search panels, and footer navigation.
2. **Title Optimization**: It extracts the page title and cleans up the redundant suffix (` - The Rust Programming Language`) for a shorter context title.
3. **Asset Deletion**: It recursively deletes redundant stylesheets (`.css`), javascript scripts (`.js`), favicons, web fonts, theme subdirectories, and decorative icons (such as Ferris badges inside `img/ferris/`).
4. **Folder Organization**: It moves pages into organized subdirectories:
   - Chapters (`ch00-xx`, `ch01-xx`, ..., `ch21-xx`) are grouped into folders like [ch01/](file:///home/sortedcord/Projects/docs-rust/ch01/), [ch02/](file:///home/sortedcord/Projects/docs-rust/ch02/), etc.
   - Appendices are moved to the [appendix/](file:///home/sortedcord/Projects/docs-rust/appendix/) folder.
   - Conceptual illustrations/diagrams are preserved and moved to [img/](file:///home/sortedcord/Projects/docs-rust/img/).
5. **Relative Link Rewriting**: It parses all link (`href="..."`) and image (`src="..."`) tags, and updates their paths relative to their new nested folder depth (e.g. replacing a link with `../ch02/ch02-00-guessing-game-tutorial.html` or an image path with `../img/trpl15-01.svg` as necessary).
6. **Build Directory Cleanup**: Deletes the raw `build/` folder completely once processing is finished.

## Repository Layout

- [toc.html](file:///home/sortedcord/Projects/docs-rust/toc.html): The Table of Contents list page (root of the repo).
- [print.html](file:///home/sortedcord/Projects/docs-rust/print.html): The single-page version of the **entire** book, containing all chapters in one clean, continuous document (1.8MB). This is highly recommended for single-file ingestion.
- [index.html](file:///home/sortedcord/Projects/docs-rust/index.html): The landing page of the book.
- [foreword.html](file:///home/sortedcord/Projects/docs-rust/foreword.html): The foreword of the book.
- [title-page.html](file:///home/sortedcord/Projects/docs-rust/title-page.html): The title page.
- [ch01/](file:///home/sortedcord/Projects/docs-rust/ch01/) to [ch21/](file:///home/sortedcord/Projects/docs-rust/ch21/): Respective chapter subdirectories containing the topics (e.g., [ch01/ch01-01-installation.html](file:///home/sortedcord/Projects/docs-rust/ch01/ch01-01-installation.html)).
- [appendix/](file:///home/sortedcord/Projects/docs-rust/appendix/): Subdirectory containing all appendix pages.
- [img/](file:///home/sortedcord/Projects/docs-rust/img/): Conceptual illustrations referenced by the text.

## How to Run Again

If the book is rebuilt (which regenerates the raw `build/` output folder), you can run the script to re-clean and re-organize everything back to the repository layout in one step:

```bash
python3 clean_book.py
```
