Browse Source

Clean up

master
Dylan Baker 5 years ago
parent
commit
1198c31dc5
1 changed files with 15 additions and 15 deletions
  1. 15
    15
      src/main.rs

+ 15
- 15
src/main.rs View File

@@ -126,22 +126,22 @@ fn build() {
126 126
 fn new(name: &str) {
127 127
     let cwd = env::current_dir().expect("Couldn't read current directory");
128 128
     let project_path = cwd.join(name);
129
+
129 130
     fs::create_dir(&project_path).expect(&format!("Couldn't create directory '{}'", &name));
130
-    fs::create_dir(&project_path.join("posts")).expect("Couldn't create posts directory");
131
-    fs::create_dir(&project_path.join("public")).expect("Couldn't create public directory");
132
-    fs::create_dir(&project_path.join("templates")).expect("Couldn't create templates directory");
133
-    fs::write(&project_path.join("templates").join("layout.html"), "")
134
-        .expect("Couldn't write templates/layout.html");
135
-    fs::write(&project_path.join("templates").join("index.html"), "")
136
-        .expect("Couldn't write templates/index.html");
137
-    fs::write(&project_path.join("templates").join("post.html"), "")
138
-        .expect("Couldn't write templates/post.html");
139
-    fs::write(
140
-        &project_path
141
-            .join("templates")
142
-            .join("post_listing_item.html"),
143
-        "",
144
-    ).expect("Couldn't write templates/post_listing_item.html");
131
+
132
+    for dir in &["posts", "public", "templates"] {
133
+        fs::create_dir(&project_path.join(&dir))
134
+            .expect(&format!("Couldn't create {} directory", &dir));
135
+    }
136
+
137
+    for file in &["layout", "index", "post", "post_listing_item"] {
138
+        fs::write(
139
+            &project_path
140
+                .join("templates")
141
+                .join(format!("{}.html", file)),
142
+            "",
143
+        ).expect(&format!("Couldn't write templates/{}.html", file));
144
+    }
145 145
 }
146 146
 
147 147
 fn main() {

Loading…
Cancel
Save