Skip to content

Need a "concat chapters for nostarch" script #183

@carols10cents

Description

@carols10cents

Problem

We have multiple files for each chapter and subchapter, but would like to deliver one file per chapter to nostarch.

I did this by hand recently, but it was a little tedious and not quite what I wanted, so it'd be nice to have exactly what I wanted in a script.

Solution

This script should be written in Rust and should:

  • Take a directory as an argument (this might be a temporary directory and I'm not sure of its name yet, I'd like to hook this into the script for Need a link remover script #182, but you should be able to test this without the other script by passing this script the src directory)
  • Group all the *.md files in that directory by their chapter prefix
  • Concatenate the subchapters in order, and with one newline in between
  • Write the output to a file in the nostarch directory named for that chapter.

For example, this is what should happen for chapter 1 if we pass this script the src directory:

  • Take these three files because they start with ch01-:
    • src/ch01-00-introduction.md
    • src/ch01-01-installation.md
    • src/ch01-02-hello-world.md
  • Concatenate so that the result looks like this (I'm showing the beginning and end of each subchapter here:
# Introduction

Welcome to “The Rust Programming Language”, an introductory book about Rust.

...

## Contributing to the book

This book is open source. If you find an error, please don’t hesitate to file an
issue or send a pull request [on GitHub].

[on GitHub]: https://github.com/rust-lang/book

## Installation

The first step to using Rust is to install it. You’ll need an internet

...

### Local documentation

The installer also includes a copy of the documentation locally, so you can
read it offline. On Linux or Mac, run `rustup doc` to open the local
documentation in your browser. On Windows, the documentation is in a
`share/doc` directory inside the directory where Rust was installed.

## Hello, World!

Now that you have Rust installed, let’s write your first Rust program. It's

...

> Note: If you want to look at Cargo in more detail, check out the official
[Cargo guide], which covers all of its features.

[Cargo guide]: http://doc.crates.io/guide.html
  • Store the result in nostarch/chapter01.md.

This should happen for all the chNN-NN-whatever.md files, and also for the appendix-NN.md files. There might be more filename patterns someday (glossary?), so make a place where it's easy to add new ones.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions