state.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crate::errors::{ Result };
use crate::git::{ Git };
use regex::{ Regex, RegexBuilder };
use tera::{ Tera };
pub(crate) struct Gitten {
pub(crate) git: Git,
pub(crate) shared_regexes: SharedRegexes,
pub(crate) site_link: String,
pub(crate) site_name: String,
pub(crate) tera: Tera,
}
pub(crate) struct SharedRegexes {
pub(crate) markdown_heading_regex: Regex,
pub(crate) html_h1_regex: Regex,
pub(crate) too_long_heading_regex: Regex,
}
impl SharedRegexes {
pub(crate) fn new() -> Result<SharedRegexes> {
let shared_regexes = SharedRegexes {
// For all headings
markdown_heading_regex: RegexBuilder::new(r"^(?<heading>##*)")
.crlf(true)
.multi_line(true)
.build()?,
// For html headings
html_h1_regex: RegexBuilder::new(r"<h1>(?<content>.*)</h1>")
.crlf(true)
.multi_line(true)
.build()?,
// For headings with 7 or more #'s
too_long_heading_regex: RegexBuilder::new(r"^########*")
.crlf(true)
.multi_line(true)
.build()?,
};
Ok(shared_regexes)
}
}