|
@@ -43,6 +43,8 @@ pub fn build(include_drafts: bool) {
|
43
|
43
|
let post_item_template =
|
44
|
44
|
fs::read_to_string(cwd.join("templates").join("post_listing_item.html"))
|
45
|
45
|
.expect("Couldn't find post listing item template");
|
|
46
|
+ let page_template = fs::read_to_string(cwd.join("templates").join("page.html"))
|
|
47
|
+ .expect("Couldn't find page template");
|
46
|
48
|
|
47
|
49
|
let post_paths = match include_drafts {
|
48
|
50
|
true => {
|
|
@@ -65,8 +67,8 @@ pub fn build(include_drafts: bool) {
|
65
|
67
|
.collect();
|
66
|
68
|
|
67
|
69
|
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
|
+ let page = parse_post(entry.path());
|
|
71
|
+ write_page(&cwd, &layout_template, &page_template, &page, &config);
|
70
|
72
|
}
|
71
|
73
|
|
72
|
74
|
write_post_listing(
|
|
@@ -114,7 +116,13 @@ pub fn new(name: &str) {
|
114
|
116
|
.expect("Couldn't create css/style.css");
|
115
|
117
|
fs::write(project_path.join("js").join("index.js"), "").expect("Couldn't create js/index.js");
|
116
|
118
|
|
117
|
|
- for file in &["layout", "post_listing", "post", "post_listing_item"] {
|
|
119
|
+ for file in &[
|
|
120
|
+ "layout",
|
|
121
|
+ "post_listing",
|
|
122
|
+ "post",
|
|
123
|
+ "page",
|
|
124
|
+ "post_listing_item",
|
|
125
|
+ ] {
|
118
|
126
|
fs::write(
|
119
|
127
|
&project_path
|
120
|
128
|
.join("templates")
|
|
@@ -179,7 +187,7 @@ mod tests {
|
179
|
187
|
let project_dir = temp_dir.join(&uuid);
|
180
|
188
|
new(&uuid);
|
181
|
189
|
|
182
|
|
- for dir in &["public", "posts", "templates"] {
|
|
190
|
+ for dir in &["public", "pages", "posts", "templates"] {
|
183
|
191
|
fs::read_dir(&project_dir.join(dir)).unwrap();
|
184
|
192
|
}
|
185
|
193
|
|
|
@@ -200,6 +208,10 @@ mod tests {
|
200
|
208
|
"",
|
201
|
209
|
fs::read_to_string(&project_dir.join("templates").join("post.html")).unwrap()
|
202
|
210
|
);
|
|
211
|
+ assert_eq!(
|
|
212
|
+ "",
|
|
213
|
+ fs::read_to_string(&project_dir.join("templates").join("page.html")).unwrap()
|
|
214
|
+ );
|
203
|
215
|
assert_eq!(
|
204
|
216
|
"",
|
205
|
217
|
fs::read_to_string(&project_dir.join("css").join("style.css")).unwrap()
|
|
@@ -252,6 +264,11 @@ mod tests {
|
252
|
264
|
"<article><h1>{{ title }}</h1><div>{{ body }}</div></article>",
|
253
|
265
|
)
|
254
|
266
|
.unwrap();
|
|
267
|
+ fs::write(
|
|
268
|
+ project_dir.join("templates").join("page.html"),
|
|
269
|
+ "<article class=\"page\"><h1>{{ title }}</h1><div>{{ body }}</div></article>",
|
|
270
|
+ )
|
|
271
|
+ .unwrap();
|
255
|
272
|
fs::write(
|
256
|
273
|
project_dir.join("templates").join("post_listing.html"),
|
257
|
274
|
"<ul>{{ post_listing }}</ul>",
|
|
@@ -267,6 +284,11 @@ mod tests {
|
267
|
284
|
"# First post\n\nThis is the first post\n\nIt has multiple paragraphs",
|
268
|
285
|
)
|
269
|
286
|
.unwrap();
|
|
287
|
+ fs::write(
|
|
288
|
+ project_dir.join("pages").join("first-page.md"),
|
|
289
|
+ "# First page\n\nThis is the first page\n\nIt has multiple paragraphs",
|
|
290
|
+ )
|
|
291
|
+ .unwrap();
|
270
|
292
|
fs::write(
|
271
|
293
|
project_dir.join("casaubon.toml"),
|
272
|
294
|
"site_name = \"Test Site\"",
|
|
@@ -296,6 +318,20 @@ mod tests {
|
296
|
318
|
.replace("\n", ""),
|
297
|
319
|
);
|
298
|
320
|
|
|
321
|
+ assert_eq!(
|
|
322
|
+ "<html><head><title>First page | Test Site</title></head><body><article class=\"page\"><h1>First pag\
|
|
323
|
+ e</h1><div><p>This is the first page</p><p>It has multiple paragra\
|
|
324
|
+ phs</p></div></article></body></html>",
|
|
325
|
+ fs::read_to_string(
|
|
326
|
+ project_dir
|
|
327
|
+ .join("public")
|
|
328
|
+ .join("first-page")
|
|
329
|
+ .join("index.html")
|
|
330
|
+ )
|
|
331
|
+ .unwrap()
|
|
332
|
+ .replace("\n", ""),
|
|
333
|
+ );
|
|
334
|
+
|
299
|
335
|
assert_eq!(
|
300
|
336
|
"body { background: blue; }",
|
301
|
337
|
fs::read_to_string(project_dir.join("public").join("css").join("style.css")).unwrap()
|
|
@@ -346,6 +382,11 @@ mod tests {
|
346
|
382
|
"<article><h1>{{ title }}</h1><div>{{ body }}</div></article>",
|
347
|
383
|
)
|
348
|
384
|
.unwrap();
|
|
385
|
+ fs::write(
|
|
386
|
+ project_dir.join("templates").join("page.html"),
|
|
387
|
+ "<article class=\"page\"><h1>{{ title }}</h1><div>{{ body }}</div></article>",
|
|
388
|
+ )
|
|
389
|
+ .unwrap();
|
349
|
390
|
fs::write(
|
350
|
391
|
project_dir.join("templates").join("post_listing.html"),
|
351
|
392
|
"<ul>{{ post_listing }}</ul>",
|
|
@@ -361,6 +402,11 @@ mod tests {
|
361
|
402
|
"# First post\n\nThis is the first post",
|
362
|
403
|
)
|
363
|
404
|
.unwrap();
|
|
405
|
+ fs::write(
|
|
406
|
+ project_dir.join("pages").join("first-page.md"),
|
|
407
|
+ "# First page\n\nThis is the first page",
|
|
408
|
+ )
|
|
409
|
+ .unwrap();
|
364
|
410
|
fs::write(
|
365
|
411
|
project_dir.join("drafts").join("first-draft.md"),
|
366
|
412
|
"# First draft\n\nThis is the first draft",
|
|
@@ -391,6 +437,17 @@ mod tests {
|
391
|
437
|
.replace("\n", ""),
|
392
|
438
|
);
|
393
|
439
|
|
|
440
|
+ assert_eq!(
|
|
441
|
+ "<html><head><title>First page | Test Site</title></head><body><article class=\"page\"><h1>First page</h1><div><p>This is the first page</p></div></article></body></html>",
|
|
442
|
+ fs::read_to_string(
|
|
443
|
+ project_dir
|
|
444
|
+ .join("public")
|
|
445
|
+ .join("first-page")
|
|
446
|
+ .join("index.html")
|
|
447
|
+ ).unwrap()
|
|
448
|
+ .replace("\n", ""),
|
|
449
|
+ );
|
|
450
|
+
|
394
|
451
|
assert_eq!(
|
395
|
452
|
"<html><head><title>First draft | Test Site</title></head><body><article><h1>First draft</h1><div><p>This is the first draft</p></div></article></body></html>",
|
396
|
453
|
fs::read_to_string(
|