9098d36840
- Mention various chat channels - Add `intermodal-bin` package to package table - Document `bin/gen` - Add contributing section - Link to book type: documentation |
||
---|---|---|
.. | ||
bin.rs | ||
changelog.rs | ||
cmd.rs | ||
command_ext.rs | ||
common.rs | ||
config.rs | ||
entry.rs | ||
example.rs | ||
exit_status_ext.rs | ||
introduction.rs | ||
kind.rs | ||
main.rs | ||
metadata.rs | ||
opt.rs | ||
package.rs | ||
project.rs | ||
readme.rs | ||
release.rs | ||
row.rs | ||
subcommand.rs | ||
summary.rs | ||
table.rs |
use crate::common::*; #[derive(Template)] #[template(path = "README.md")] pub(crate) struct Readme { pub(crate) table_of_contents: String, pub(crate) packages: Table<Package>, } const HEADING_PATTERN: &str = "(?m)^(?P<MARKER>#+) (?P<TEXT>.*)$"; impl Readme { #[throws] pub(crate) fn load(config: &Config, template: &Path) -> Readme { let text = fs::read_to_string(template)?; let header_re = Regex::new(HEADING_PATTERN)?; let mut lines = Vec::new(); for captures in header_re.captures_iter(&text).skip(2) { let marker = captures.name("MARKER").unwrap().as_str(); let text = captures.name("TEXT").unwrap().as_str(); let level = marker.len(); let indentation = " ".repeat((level - 2) * 2); let slug = text .to_lowercase() .replace(' ', "-") .replace('.', "") .replace('&', ""); lines.push(format!("{}- [{}](#{})", indentation, text, slug)); } Readme { table_of_contents: lines.join("\n"), packages: Table::new(config.packages.clone()), } } }