浏览代码

Clean up warnings

master
Dylan Baker 2 年前
父节点
当前提交
af9a781fde
共有 5 个文件被更改,包括 76 次插入93 次删除
  1. 19
    19
      src/entry.rs
  2. 38
    56
      src/lib.rs
  3. 1
    1
      src/main.rs
  4. 6
    5
      src/rss.rs
  5. 12
    12
      tests/integration_test.rs

+ 19
- 19
src/entry.rs 查看文件

7
 
7
 
8
 use config::Config;
8
 use config::Config;
9
 
9
 
10
-#[derive(Debug, PartialEq)]
10
+#[derive(Debug, PartialEq, Eq)]
11
 pub enum EntryKind {
11
 pub enum EntryKind {
12
     Page,
12
     Page,
13
     Post,
13
     Post,
46
 pub fn read_entry_dir(cwd: &path::Path) -> Vec<fs::DirEntry> {
46
 pub fn read_entry_dir(cwd: &path::Path) -> Vec<fs::DirEntry> {
47
     match fs::read_dir(cwd) {
47
     match fs::read_dir(cwd) {
48
         Ok(entries) => entries.into_iter().map(|entry| entry.unwrap()).collect(),
48
         Ok(entries) => entries.into_iter().map(|entry| entry.unwrap()).collect(),
49
-        Err(err) => panic!(err),
49
+        Err(err) => std::panic::panic_any(err),
50
     }
50
     }
51
 }
51
 }
52
 
52
 
68
 
68
 
69
     if kind == EntryKind::Post {
69
     if kind == EntryKind::Post {
70
         let captures = &RE_WITH_DATE
70
         let captures = &RE_WITH_DATE
71
-            .captures(&contents)
71
+            .captures(contents)
72
             .expect("Couldn't parse post");
72
             .expect("Couldn't parse post");
73
         let title = captures["title"].to_string();
73
         let title = captures["title"].to_string();
74
         let body = captures["body"].to_string();
74
         let body = captures["body"].to_string();
84
         }
84
         }
85
     } else {
85
     } else {
86
         let captures = &RE_WITHOUT_DATE
86
         let captures = &RE_WITHOUT_DATE
87
-            .captures(&contents)
87
+            .captures(contents)
88
             .expect("Couldn't parse page");
88
             .expect("Couldn't parse page");
89
         let title = captures["title"].to_string();
89
         let title = captures["title"].to_string();
90
         let body = captures["body"].to_string();
90
         let body = captures["body"].to_string();
114
         Ok(_) => {}
114
         Ok(_) => {}
115
         Err(err) => match err.kind() {
115
         Err(err) => match err.kind() {
116
             std::io::ErrorKind::AlreadyExists => {}
116
             std::io::ErrorKind::AlreadyExists => {}
117
-            _ => panic!(err),
117
+            _ => std::panic::panic_any(err),
118
         },
118
         },
119
     }
119
     }
120
 
120
 
121
-    let template = layout.replace("{{ contents }}", &post_template);
121
+    let template = layout.replace("{{ contents }}", post_template);
122
 
122
 
123
     fs::write(
123
     fs::write(
124
         &root_path.join("index.html"),
124
         &root_path.join("index.html"),
125
-        entry.render(&template, &config),
125
+        entry.render(&template, config),
126
     )
126
     )
127
     .expect("Unable to write file");
127
     .expect("Unable to write file");
128
 }
128
 }
132
     layout: &str,
132
     layout: &str,
133
     post_listing_template: &str,
133
     post_listing_template: &str,
134
     post_item_template: &str,
134
     post_item_template: &str,
135
-    posts: &Vec<Entry>,
135
+    posts: &[Entry],
136
     config: &Config,
136
     config: &Config,
137
 ) {
137
 ) {
138
     fs::write(
138
     fs::write(
152
     layout: &str,
152
     layout: &str,
153
     post_listing_template: &str,
153
     post_listing_template: &str,
154
     post_item_template: &str,
154
     post_item_template: &str,
155
-    posts: &Vec<Entry>,
155
+    posts: &[Entry],
156
     config: &Config,
156
     config: &Config,
157
 ) -> String {
157
 ) -> String {
158
     layout
158
     layout
159
-        .replace("{{ page_title }}", &format!("{}", config.site_name))
159
+        .replace("{{ page_title }}", &config.site_name.to_string())
160
         .replace(
160
         .replace(
161
             "{{ contents }}",
161
             "{{ contents }}",
162
             &post_listing_template.replace(
162
             &post_listing_template.replace(
163
                 "{{ post_listing }}",
163
                 "{{ post_listing }}",
164
                 &posts
164
                 &posts
165
                     .iter()
165
                     .iter()
166
-                    .map(|post| post.render(&post_item_template, &config))
166
+                    .map(|post| post.render(post_item_template, config))
167
                     .collect::<Vec<String>>()
167
                     .collect::<Vec<String>>()
168
                     .join("\n"),
168
                     .join("\n"),
169
             ),
169
             ),
198
         let output = post.render(
198
         let output = post.render(
199
             "<html><head><title>{{ page_title }}</title></head><body><article><h1>{{ title }}</h1><div>{{ body }}</div></article></body></html>", &config
199
             "<html><head><title>{{ page_title }}</title></head><body><article><h1>{{ title }}</h1><div>{{ body }}</div></article></body></html>", &config
200
         )
200
         )
201
-        .replace("\n", "");
201
+        .replace('\n', "");
202
 
202
 
203
         assert_eq!(
203
         assert_eq!(
204
             "<html><head><title>hello world | Test Site</title></head><body><article><h1>hello world</h1><div><p>lorem ipsum dolor sit amet</p></div></article></body></html>",
204
             "<html><head><title>hello world | Test Site</title></head><body><article><h1>hello world</h1><div><p>lorem ipsum dolor sit amet</p></div></article></body></html>",
245
             &posts,
245
             &posts,
246
             &config,
246
             &config,
247
         )
247
         )
248
-        .replace("\n", "");
248
+        .replace('\n', "");
249
 
249
 
250
         assert_eq!(
250
         assert_eq!(
251
             "<html><head><title>Test Site</title></head><body><ul><li><a href=\"/first-post\">First post</a></li><li><a href=\"/second-post\">Second post</a></li><li><a href=\"/third-post\">Third post</a></li></ul></body></html>",
251
             "<html><head><title>Test Site</title></head><body><ul><li><a href=\"/first-post\">First post</a></li><li><a href=\"/second-post\">Second post</a></li><li><a href=\"/third-post\">Third post</a></li></ul></body></html>",
278
             description: String::from("recent posts from testsite.com"),
278
             description: String::from("recent posts from testsite.com"),
279
         };
279
         };
280
 
280
 
281
-        write_entry(&project_dir, &layout, &post_template, &post, &config);
281
+        write_entry(&project_dir, layout, post_template, &post, &config);
282
 
282
 
283
         let content = fs::read_to_string(
283
         let content = fs::read_to_string(
284
             project_dir
284
             project_dir
291
 
291
 
292
         assert_eq!(
292
         assert_eq!(
293
             "<html><head><title>Hello world | Test Site</title></head><body><article><h1>Hello world</h1><div><p>Lorem ipsum dolor sit amet</p></div></article></body></html>",
293
             "<html><head><title>Hello world | Test Site</title></head><body><article><h1>Hello world</h1><div><p>Lorem ipsum dolor sit amet</p></div></article></body></html>",
294
-	    content.replace("\n", "")
294
+	    content.replace('\n', "")
295
 	);
295
 	);
296
 
296
 
297
         fs::remove_dir_all(temp_dir.join(&project_dir)).unwrap();
297
         fs::remove_dir_all(temp_dir.join(&project_dir)).unwrap();
341
         };
341
         };
342
         write_entry_listing(
342
         write_entry_listing(
343
             &cwd,
343
             &cwd,
344
-            &layout,
345
-            &post_listing_template,
346
-            &post_item_template,
344
+            layout,
345
+            post_listing_template,
346
+            post_item_template,
347
             &posts,
347
             &posts,
348
             &config,
348
             &config,
349
         );
349
         );
355
              ></ul></body></html>",
355
              ></ul></body></html>",
356
             fs::read_to_string(&cwd.join("public").join("index.html"))
356
             fs::read_to_string(&cwd.join("public").join("index.html"))
357
                 .unwrap()
357
                 .unwrap()
358
-                .replace("\n", ""),
358
+                .replace('\n', ""),
359
         );
359
         );
360
 
360
 
361
         fs::remove_dir_all(temp_dir.join(&project_dir)).unwrap();
361
         fs::remove_dir_all(temp_dir.join(&project_dir)).unwrap();

+ 38
- 56
src/lib.rs 查看文件

40
         }
40
         }
41
     };
41
     };
42
 
42
 
43
-    match fs::read_dir(cwd.join("public")) {
44
-        Ok(_) => {
45
-            fs::remove_dir_all(cwd.join("public")).unwrap();
46
-        }
47
-        Err(_) => {}
43
+    if fs::read_dir(cwd.join("public")).is_ok() {
44
+        fs::remove_dir_all(cwd.join("public")).unwrap();
48
     }
45
     }
49
 
46
 
50
     fs::create_dir(cwd.join("public")).expect("Couldn't create public directory");
47
     fs::create_dir(cwd.join("public")).expect("Couldn't create public directory");
85
     posts.sort_by(|a, b| b.date.cmp(&a.date));
82
     posts.sort_by(|a, b| b.date.cmp(&a.date));
86
 
83
 
87
     for post in &posts {
84
     for post in &posts {
88
-        write_entry(&cwd, &layout_template, &post_template, &post, &config);
85
+        write_entry(cwd, &layout_template, &post_template, post, &config);
89
     }
86
     }
90
 
87
 
91
     for entry in page_paths.into_iter() {
88
     for entry in page_paths.into_iter() {
92
         let path = entry.path();
89
         let path = entry.path();
93
         let contents = fs::read_to_string(&path).expect("Couldn't read page file");
90
         let contents = fs::read_to_string(&path).expect("Couldn't read page file");
94
         let page = parse_entry(EntryKind::Page, &contents, &path);
91
         let page = parse_entry(EntryKind::Page, &contents, &path);
95
-        write_entry(&cwd, &layout_template, &page_template, &page, &config);
92
+        write_entry(cwd, &layout_template, &page_template, &page, &config);
96
     }
93
     }
97
 
94
 
98
     write_entry_listing(
95
     write_entry_listing(
99
-        &cwd,
96
+        cwd,
100
         &layout_template,
97
         &layout_template,
101
         &post_listing_template,
98
         &post_listing_template,
102
         &post_item_template,
99
         &post_item_template,
111
     )
108
     )
112
     .expect("Couldn't copy assets directory");
109
     .expect("Couldn't copy assets directory");
113
 
110
 
114
-    let rss = generate_rss(&config, &posts);
111
+    let rss = generate_rss(&config, posts);
115
     fs::write(cwd.join("public").join("rss.xml"), rss).expect("Couldn't write rss file");
112
     fs::write(cwd.join("public").join("rss.xml"), rss).expect("Couldn't write rss file");
116
 }
113
 }
117
 
114
 
118
 pub fn new(name: &str, cwd: &path::Path) {
115
 pub fn new(name: &str, cwd: &path::Path) {
119
     let project_path = cwd.join(name);
116
     let project_path = cwd.join(name);
120
 
117
 
121
-    fs::create_dir(&project_path).expect(&format!("Couldn't create directory '{}'", &name));
118
+    fs::create_dir(&project_path)
119
+        .unwrap_or_else(|_| panic!("Couldn't create directory '{}'", &name));
122
     fs::write(
120
     fs::write(
123
         project_path.join("casaubon.toml"),
121
         project_path.join("casaubon.toml"),
124
         format!(
122
         format!(
138
         "js",
136
         "js",
139
     ] {
137
     ] {
140
         fs::create_dir(&project_path.join(&dir))
138
         fs::create_dir(&project_path.join(&dir))
141
-            .expect(&format!("Couldn't create {} directory", &dir));
139
+            .unwrap_or_else(|_| panic!("Couldn't create {} directory", &dir));
142
     }
140
     }
143
 
141
 
144
     let default_layout_template = format!(
142
     let default_layout_template = format!(
153
 </html>\n",
151
 </html>\n",
154
         name, name
152
         name, name
155
     );
153
     );
156
-    let default_post_listing_template = format!(
157
-        "<div>
154
+    let default_post_listing_template = "<div>
158
   <h3>Posts</h3>
155
   <h3>Posts</h3>
159
-  <ul>{{{{ post_listing }}}}</ul>
156
+  <ul>{{ post_listing }}</ul>
160
 </div>\n"
157
 </div>\n"
161
-    );
162
-    let default_post_template = format!(
163
-        "<article>
164
-  <h1>{{{{ title }}}}</h1>
165
-  <div>{{{{ body }}}}</div>
158
+        .to_string();
159
+    let default_post_template = "<article>
160
+  <h1>{{ title }}</h1>
161
+  <div>{{ body }}</div>
166
 </article>\n"
162
 </article>\n"
167
-    );
168
-    let default_page_template = format!(
169
-        "<article>
170
-  <h1>{{{{ title }}}}</h1>
171
-  <div>{{{{ body }}}}</div>
163
+        .to_string();
164
+    let default_page_template = "<article>
165
+  <h1>{{ title }}</h1>
166
+  <div>{{ body }}</div>
172
 </article>\n"
167
 </article>\n"
173
-    );
174
-    let default_post_listing_item_template = format!(
175
-        "<li>
176
-  {{ date }} <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a>
168
+        .to_string();
169
+    let default_post_listing_item_template = "<li>
170
+  { date } <a href=\"/posts/{{ slug }}/\">{{ title }}</a>
177
 </li>\n"
171
 </li>\n"
178
-    );
172
+        .to_string();
179
 
173
 
180
     for (filename, contents) in &[
174
     for (filename, contents) in &[
181
         ("layout", &default_layout_template),
175
         ("layout", &default_layout_template),
190
                 .join(format!("{}.html", filename)),
184
                 .join(format!("{}.html", filename)),
191
             &contents,
185
             &contents,
192
         )
186
         )
193
-        .expect(&format!("Couldn't write templates/{}.html", filename));
187
+        .unwrap_or_else(|_| panic!("Couldn't write templates/{}.html", filename));
194
     }
188
     }
195
 }
189
 }
196
 
190
 
197
-fn should_rebuild(cwd: &path::Path, path: &path::PathBuf) -> bool {
191
+fn should_rebuild(cwd: &path::Path, path: &path::Path) -> bool {
198
     let path_string = path.to_str().unwrap().to_string();
192
     let path_string = path.to_str().unwrap().to_string();
199
     let change_is_from_public = path_string.contains(cwd.join("public").to_str().unwrap());
193
     let change_is_from_public = path_string.contains(cwd.join("public").to_str().unwrap());
200
     let change_is_from_git = path_string.contains(cwd.join(".git").to_str().unwrap());
194
     let change_is_from_git = path_string.contains(cwd.join(".git").to_str().unwrap());
204
 
198
 
205
 pub fn watch(include_drafts: bool, cwd: &path::Path) -> notify::Result<()> {
199
 pub fn watch(include_drafts: bool, cwd: &path::Path) -> notify::Result<()> {
206
     let (tx, rx) = channel();
200
     let (tx, rx) = channel();
207
-    let mut watcher: RecommendedWatcher = try!(Watcher::new(tx, Duration::from_secs(2)));
208
-    try!(watcher.watch(&cwd, RecursiveMode::Recursive));
201
+    let mut watcher: RecommendedWatcher = Watcher::new(tx, Duration::from_secs(2))?;
202
+    watcher.watch(&cwd, RecursiveMode::Recursive)?;
209
     println!("Watching {}", cwd.to_str().unwrap());
203
     println!("Watching {}", cwd.to_str().unwrap());
210
 
204
 
211
     let handle_event = |path: &path::PathBuf| {
205
     let handle_event = |path: &path::PathBuf| {
212
-        if should_rebuild(&cwd, &path) {
206
+        if should_rebuild(cwd, path) {
213
             println!("Rebuilding");
207
             println!("Rebuilding");
214
-            build(include_drafts, &cwd);
208
+            build(include_drafts, cwd);
215
         }
209
         }
216
     };
210
     };
217
 
211
 
243
     #[test]
237
     #[test]
244
     fn test_should_rebuild() {
238
     fn test_should_rebuild() {
245
         let cwd = env::current_dir().unwrap();
239
         let cwd = env::current_dir().unwrap();
246
-        assert_eq!(
247
-            false,
248
-            should_rebuild(&cwd, &cwd.join("public").join("index.html"))
249
-        );
250
-        assert_eq!(
251
-            false,
252
-            should_rebuild(&cwd, &cwd.join(".git").join("index.html"))
253
-        );
254
-        assert_eq!(
255
-            true,
256
-            should_rebuild(&cwd, &cwd.join("posts").join("test.md"))
257
-        );
258
-        assert_eq!(
259
-            true,
260
-            should_rebuild(&cwd, &cwd.join("drafts").join("test.md"))
261
-        );
262
-        assert_eq!(
263
-            true,
264
-            should_rebuild(&cwd, &cwd.join("css").join("style.css"))
265
-        );
266
-        assert_eq!(true, should_rebuild(&cwd, &cwd.join("js").join("index.js")));
240
+        assert!(!should_rebuild(
241
+            &cwd,
242
+            &cwd.join("public").join("index.html")
243
+        ));
244
+        assert!(!should_rebuild(&cwd, &cwd.join(".git").join("index.html")));
245
+        assert!(should_rebuild(&cwd, &cwd.join("posts").join("test.md")));
246
+        assert!(should_rebuild(&cwd, &cwd.join("drafts").join("test.md")));
247
+        assert!(should_rebuild(&cwd, &cwd.join("css").join("style.css")));
248
+        assert!(should_rebuild(&cwd, &cwd.join("js").join("index.js")));
267
     }
249
     }
268
 }
250
 }

+ 1
- 1
src/main.rs 查看文件

37
         );
37
         );
38
     } else if command == "new" {
38
     } else if command == "new" {
39
         casaubon::new(
39
         casaubon::new(
40
-            &matches.value_of("name").unwrap(),
40
+            matches.value_of("name").unwrap(),
41
             &env::current_dir().expect("Can't read current directory"),
41
             &env::current_dir().expect("Can't read current directory"),
42
         );
42
         );
43
     } else if command == "watch" {
43
     } else if command == "watch" {

+ 6
- 5
src/rss.rs 查看文件

5
 use entry::{Entry, EntryKind};
5
 use entry::{Entry, EntryKind};
6
 
6
 
7
 pub fn generate_post_rss(config: &Config, post: &Entry) -> String {
7
 pub fn generate_post_rss(config: &Config, post: &Entry) -> String {
8
-    let date: DateTime<Utc> = DateTime::from_utc(post.date.unwrap().and_hms(0, 0, 0), Utc);
8
+    let raw_date = post.date.unwrap().and_hms_opt(0, 0, 0).unwrap();
9
+    let date: DateTime<Utc> = DateTime::from_utc(raw_date, Utc);
9
     let date_string = date.format("%a, %d %b %Y %H:%M:%S %z").to_string();
10
     let date_string = date.format("%a, %d %b %Y %H:%M:%S %z").to_string();
10
     let url = format!("{}/posts/{}/", config.url, post.slug);
11
     let url = format!("{}/posts/{}/", config.url, post.slug);
11
     format!(
12
     format!(
14
     )
15
     )
15
 }
16
 }
16
 
17
 
17
-pub fn generate_rss(config: &Config, posts: &Vec<Entry>) -> String {
18
+pub fn generate_rss(config: &Config, posts: Vec<Entry>) -> String {
18
     let items = posts
19
     let items = posts
19
-        .into_iter()
20
+        .iter()
20
         .filter(|post| post.kind == EntryKind::Post)
21
         .filter(|post| post.kind == EntryKind::Post)
21
-        .map(|post| generate_post_rss(&config, &post))
22
+        .map(|post| generate_post_rss(config, post))
22
         .collect::<Vec<String>>()
23
         .collect::<Vec<String>>()
23
         .join("");
24
         .join("");
24
 
25
 
51
             kind: EntryKind::Post,
52
             kind: EntryKind::Post,
52
         }];
53
         }];
53
         assert_eq!(
54
         assert_eq!(
54
-            generate_rss(&config, &posts),
55
+            generate_rss(&config, posts),
55
             "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel><atom:link href=\"https://www.loremipsum.com/rss.xml\" rel=\"self\" /><title>Lorem Ipsum</title><description>recent posts from loremipsum.com</description><link>https://www.loremipsum.com</link><item><title>Hello World</title><description>&lt;article&gt;&lt;p&gt;lorem ipsum dolor sit amet&lt;/p&gt;\n&lt;/article&gt;</description><guid>https://www.loremipsum.com/posts/hello-world/</guid><link>https://www.loremipsum.com/posts/hello-world/</link><pubDate>Tue, 01 Jan 2019 00:00:00 +0000</pubDate></item></channel></rss>"
56
             "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel><atom:link href=\"https://www.loremipsum.com/rss.xml\" rel=\"self\" /><title>Lorem Ipsum</title><description>recent posts from loremipsum.com</description><link>https://www.loremipsum.com</link><item><title>Hello World</title><description>&lt;article&gt;&lt;p&gt;lorem ipsum dolor sit amet&lt;/p&gt;\n&lt;/article&gt;</description><guid>https://www.loremipsum.com/posts/hello-world/</guid><link>https://www.loremipsum.com/posts/hello-world/</link><pubDate>Tue, 01 Jan 2019 00:00:00 +0000</pubDate></item></channel></rss>"
56
         );
57
         );
57
     }
58
     }

+ 12
- 12
tests/integration_test.rs 查看文件

87
                 .join("index.html")
87
                 .join("index.html")
88
         )
88
         )
89
         .unwrap()
89
         .unwrap()
90
-        .replace("\n", ""),
90
+        .replace('\n', ""),
91
     );
91
     );
92
 
92
 
93
     assert_eq!(
93
     assert_eq!(
101
                 .join("index.html")
101
                 .join("index.html")
102
         )
102
         )
103
         .unwrap()
103
         .unwrap()
104
-        .replace("\n", ""),
104
+        .replace('\n', ""),
105
     );
105
     );
106
 
106
 
107
     assert_eq!(
107
     assert_eq!(
182
 
182
 
183
     assert_eq!(
183
     assert_eq!(
184
         "<html><head><title>Test Site</title></head><body><ul><li><a href=\"/first-post\">First post</a></li><li><a href=\"/first-draft\">First draft</a></li></ul></body></html>",
184
         "<html><head><title>Test Site</title></head><body><ul><li><a href=\"/first-post\">First post</a></li><li><a href=\"/first-draft\">First draft</a></li></ul></body></html>",
185
-        fs::read_to_string(project_dir.join("public").join("index.html")).unwrap().replace("\n", ""),
185
+        fs::read_to_string(project_dir.join("public").join("index.html")).unwrap().replace('\n', ""),
186
     );
186
     );
187
 
187
 
188
     assert_eq!(
188
     assert_eq!(
194
                 .join("first-post")
194
                 .join("first-post")
195
                 .join("index.html")
195
                 .join("index.html")
196
         ).unwrap()
196
         ).unwrap()
197
-        .replace("\n", ""),
197
+        .replace('\n', ""),
198
     );
198
     );
199
 
199
 
200
     assert_eq!(
200
     assert_eq!(
205
                 .join("first-page")
205
                 .join("first-page")
206
                 .join("index.html")
206
                 .join("index.html")
207
         ).unwrap()
207
         ).unwrap()
208
-        .replace("\n", ""),
208
+        .replace('\n', ""),
209
     );
209
     );
210
 
210
 
211
     assert_eq!(
211
     assert_eq!(
217
                 .join("first-draft")
217
                 .join("first-draft")
218
                 .join("index.html")
218
                 .join("index.html")
219
         ).unwrap()
219
         ).unwrap()
220
-        .replace("\n", ""),
220
+        .replace('\n', ""),
221
     );
221
     );
222
 }
222
 }
223
 
223
 
227
     let temp_dir = tempfile::tempdir().unwrap();
227
     let temp_dir = tempfile::tempdir().unwrap();
228
     let project_dir = temp_dir.path().join(&uuid);
228
     let project_dir = temp_dir.path().join(&uuid);
229
 
229
 
230
-    casaubon::new(&uuid, &temp_dir.path());
230
+    casaubon::new(&uuid, temp_dir.path());
231
 
231
 
232
     for dir in &["public", "pages", "posts", "templates"] {
232
     for dir in &["public", "pages", "posts", "templates"] {
233
         fs::read_dir(&project_dir.join(dir)).unwrap();
233
         fs::read_dir(&project_dir.join(dir)).unwrap();
240
         ),
240
         ),
241
         fs::read_to_string(&project_dir.join("templates").join("layout.html"))
241
         fs::read_to_string(&project_dir.join("templates").join("layout.html"))
242
             .unwrap()
242
             .unwrap()
243
-            .replace("\n", "")
243
+            .replace('\n', "")
244
             .replace("  ", "")
244
             .replace("  ", "")
245
     );
245
     );
246
     assert_eq!(
246
     assert_eq!(
247
         format!("<div><h3>Posts</h3><ul>{{{{ post_listing }}}}</ul></div>"),
247
         format!("<div><h3>Posts</h3><ul>{{{{ post_listing }}}}</ul></div>"),
248
         fs::read_to_string(&project_dir.join("templates").join("post_listing.html"))
248
         fs::read_to_string(&project_dir.join("templates").join("post_listing.html"))
249
             .unwrap()
249
             .unwrap()
250
-            .replace("\n", "")
250
+            .replace('\n', "")
251
             .replace("  ", "")
251
             .replace("  ", "")
252
     );
252
     );
253
     assert_eq!(
253
     assert_eq!(
254
         format!("<li>{{ date }} <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a></li>"),
254
         format!("<li>{{ date }} <a href=\"/posts/{{{{ slug }}}}/\">{{{{ title }}}}</a></li>"),
255
         fs::read_to_string(&project_dir.join("templates").join("post_listing_item.html"))
255
         fs::read_to_string(&project_dir.join("templates").join("post_listing_item.html"))
256
             .unwrap()
256
             .unwrap()
257
-            .replace("\n", "")
257
+            .replace('\n', "")
258
             .replace("  ", "")
258
             .replace("  ", "")
259
     );
259
     );
260
     assert_eq!(
260
     assert_eq!(
261
         format!("<article><h1>{{{{ title }}}}</h1><div>{{{{ body }}}}</div></article>"),
261
         format!("<article><h1>{{{{ title }}}}</h1><div>{{{{ body }}}}</div></article>"),
262
         fs::read_to_string(&project_dir.join("templates").join("post.html"))
262
         fs::read_to_string(&project_dir.join("templates").join("post.html"))
263
             .unwrap()
263
             .unwrap()
264
-            .replace("\n", "")
264
+            .replace('\n', "")
265
             .replace("  ", "")
265
             .replace("  ", "")
266
     );
266
     );
267
     assert_eq!(
267
     assert_eq!(
268
         format!("<article><h1>{{{{ title }}}}</h1><div>{{{{ body }}}}</div></article>"),
268
         format!("<article><h1>{{{{ title }}}}</h1><div>{{{{ body }}}}</div></article>"),
269
         fs::read_to_string(&project_dir.join("templates").join("page.html"))
269
         fs::read_to_string(&project_dir.join("templates").join("page.html"))
270
             .unwrap()
270
             .unwrap()
271
-            .replace("\n", "")
271
+            .replace('\n', "")
272
             .replace("  ", "")
272
             .replace("  ", "")
273
     );
273
     );
274
     assert_eq!(
274
     assert_eq!(

正在加载...
取消
保存