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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
pub mod processing {
use std::{
fs,
io::{self},
path::Path,
path::PathBuf,
};
pub fn file_find_markdown(dir: &Path) -> io::Result<Vec<PathBuf>> {
let mut markdown_files: Vec<PathBuf> = vec![];
if dir.is_dir() {
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
let sub_files = self::file_find_markdown(&path)?;
markdown_files.extend(sub_files);
} else {
if let Some(extension) = path.extension() {
if extension == "md" {
markdown_files.push(path)
}
}
}
}
}
Ok(markdown_files)
}
pub fn copy_css(src: &Path, dest: &Path) -> io::Result<()> {
if src.is_dir() {
for entry in fs::read_dir(src)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
self::file_find_markdown(&path)?;
} else {
if let Some(extension) = path.extension() {
if extension == "css" {
let dest = if let Ok(stripped) = path.clone().strip_prefix(src) {
Path::new(dest).join(stripped)
} else {
path.clone()
};
if let Some(parent) = dest.parent() {
fs::create_dir_all(parent)?
}
fs::copy(&path, &dest)?;
}
}
}
}
}
Ok(())
}
pub fn uppercase_first_letter(s: &str) -> String {
let mut c = s.chars();
match c.next() {
None => String::new(),
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
}
}
}