|
@@ -8,7 +8,7 @@ use toml::Value;
|
8
|
8
|
|
9
|
9
|
use config::Config;
|
10
|
10
|
use post::{parse_post, read_posts_dir};
|
11
|
|
-use write::{write_post, write_post_listing};
|
|
11
|
+use write::{write_page, write_post, write_post_listing};
|
12
|
12
|
|
13
|
13
|
pub fn build(include_drafts: bool) {
|
14
|
14
|
let cwd = env::current_dir().expect("Couldn't read current directory");
|
|
@@ -32,6 +32,7 @@ pub fn build(include_drafts: bool) {
|
32
|
32
|
}
|
33
|
33
|
|
34
|
34
|
fs::create_dir(cwd.join("public")).expect("Couldn't create public directory");
|
|
35
|
+ fs::create_dir(cwd.join("public").join("posts")).expect("Couldn't create posts directory");
|
35
|
36
|
|
36
|
37
|
let layout_template = fs::read_to_string(&cwd.join("templates").join("layout.html"))
|
37
|
38
|
.expect("Couldn't find layout template");
|
|
@@ -52,6 +53,8 @@ pub fn build(include_drafts: bool) {
|
52
|
53
|
false => read_posts_dir(&cwd.join("posts")),
|
53
|
54
|
};
|
54
|
55
|
|
|
56
|
+ let page_paths = read_posts_dir(&cwd.join("pages"));
|
|
57
|
+
|
55
|
58
|
let posts = post_paths
|
56
|
59
|
.into_iter()
|
57
|
60
|
.map(|entry| {
|
|
@@ -61,6 +64,11 @@ pub fn build(include_drafts: bool) {
|
61
|
64
|
})
|
62
|
65
|
.collect();
|
63
|
66
|
|
|
67
|
+ for entry in page_paths.into_iter() {
|
|
68
|
+ let post = parse_post(entry.path());
|
|
69
|
+ write_page(&cwd, &layout_template, &post_template, &post, &config);
|
|
70
|
+ }
|
|
71
|
+
|
64
|
72
|
write_post_listing(
|
65
|
73
|
&cwd,
|
66
|
74
|
&layout_template,
|
|
@@ -89,7 +97,15 @@ pub fn new(name: &str) {
|
89
|
97
|
)
|
90
|
98
|
.expect("Could not create casaubon.toml");
|
91
|
99
|
|
92
|
|
- for dir in &["drafts", "posts", "public", "templates", "css", "js"] {
|
|
100
|
+ for dir in &[
|
|
101
|
+ "drafts",
|
|
102
|
+ "posts",
|
|
103
|
+ "pages",
|
|
104
|
+ "public",
|
|
105
|
+ "templates",
|
|
106
|
+ "css",
|
|
107
|
+ "js",
|
|
108
|
+ ] {
|
93
|
109
|
fs::create_dir(&project_path.join(&dir))
|
94
|
110
|
.expect(&format!("Couldn't create {} directory", &dir));
|
95
|
111
|
}
|
|
@@ -209,7 +225,9 @@ mod tests {
|
209
|
225
|
env::set_current_dir(&project_dir).unwrap();
|
210
|
226
|
|
211
|
227
|
fs::create_dir(project_dir.join("posts")).unwrap();
|
|
228
|
+ fs::create_dir(project_dir.join("pages")).unwrap();
|
212
|
229
|
fs::create_dir(project_dir.join("public")).unwrap();
|
|
230
|
+ fs::create_dir(project_dir.join("public").join("posts")).unwrap();
|
213
|
231
|
fs::create_dir(project_dir.join("templates")).unwrap();
|
214
|
232
|
fs::create_dir(project_dir.join("css")).unwrap();
|
215
|
233
|
fs::create_dir(project_dir.join("js")).unwrap();
|
|
@@ -249,7 +267,11 @@ mod tests {
|
249
|
267
|
"# First post\n\nThis is the first post\n\nIt has multiple paragraphs",
|
250
|
268
|
)
|
251
|
269
|
.unwrap();
|
252
|
|
- fs::write(project_dir.join("casaubon.toml"), "site_name = \"Test Site\"").unwrap();
|
|
270
|
+ fs::write(
|
|
271
|
+ project_dir.join("casaubon.toml"),
|
|
272
|
+ "site_name = \"Test Site\"",
|
|
273
|
+ )
|
|
274
|
+ .unwrap();
|
253
|
275
|
|
254
|
276
|
build(false);
|
255
|
277
|
|
|
@@ -266,6 +288,7 @@ mod tests {
|
266
|
288
|
fs::read_to_string(
|
267
|
289
|
project_dir
|
268
|
290
|
.join("public")
|
|
291
|
+ .join("posts")
|
269
|
292
|
.join("first-post")
|
270
|
293
|
.join("index.html")
|
271
|
294
|
)
|
|
@@ -296,7 +319,9 @@ mod tests {
|
296
|
319
|
|
297
|
320
|
fs::create_dir(project_dir.join("drafts")).unwrap();
|
298
|
321
|
fs::create_dir(project_dir.join("posts")).unwrap();
|
|
322
|
+ fs::create_dir(project_dir.join("pages")).unwrap();
|
299
|
323
|
fs::create_dir(project_dir.join("public")).unwrap();
|
|
324
|
+ fs::create_dir(project_dir.join("public").join("posts")).unwrap();
|
300
|
325
|
fs::create_dir(project_dir.join("templates")).unwrap();
|
301
|
326
|
fs::create_dir(project_dir.join("css")).unwrap();
|
302
|
327
|
fs::create_dir(project_dir.join("js")).unwrap();
|
|
@@ -341,7 +366,11 @@ mod tests {
|
341
|
366
|
"# First draft\n\nThis is the first draft",
|
342
|
367
|
)
|
343
|
368
|
.unwrap();
|
344
|
|
- fs::write(project_dir.join("casaubon.toml"), "site_name = \"Test Site\"").unwrap();
|
|
369
|
+ fs::write(
|
|
370
|
+ project_dir.join("casaubon.toml"),
|
|
371
|
+ "site_name = \"Test Site\"",
|
|
372
|
+ )
|
|
373
|
+ .unwrap();
|
345
|
374
|
|
346
|
375
|
build(true);
|
347
|
376
|
|
|
@@ -355,6 +384,7 @@ mod tests {
|
355
|
384
|
fs::read_to_string(
|
356
|
385
|
project_dir
|
357
|
386
|
.join("public")
|
|
387
|
+ .join("posts")
|
358
|
388
|
.join("first-post")
|
359
|
389
|
.join("index.html")
|
360
|
390
|
).unwrap()
|
|
@@ -366,6 +396,7 @@ mod tests {
|
366
|
396
|
fs::read_to_string(
|
367
|
397
|
project_dir
|
368
|
398
|
.join("public")
|
|
399
|
+ .join("posts")
|
369
|
400
|
.join("first-draft")
|
370
|
401
|
.join("index.html")
|
371
|
402
|
).unwrap()
|