Allow static folder to be missing

This commit is contained in:
Vincent Prouillet 2017-10-25 14:49:54 +02:00
parent 57b9095aa3
commit 1d8df5774f
3 changed files with 20 additions and 7 deletions

View file

@ -8,6 +8,7 @@
- Fix generated index section not found in `get_section` global function - Fix generated index section not found in `get_section` global function
- Fix permalink generation for index page - Fix permalink generation for index page
- Add Nim syntax highlighting - Add Nim syntax highlighting
- Allow static folder to be missing
## 0.2.1 (2017-10-17) ## 0.2.1 (2017-10-17)

View file

@ -431,7 +431,10 @@ impl Site {
&self.base_path.join("themes").join(theme).join("static") &self.base_path.join("themes").join(theme).join("static")
)?; )?;
} }
self.copy_static_directory(&self.static_path)?; // We're fine with missing static folders
if self.static_path.exists() {
self.copy_static_directory(&self.static_path)?;
}
Ok(()) Ok(())
} }

View file

@ -95,17 +95,22 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
console::warn_about_ignored_pages(&site); console::warn_about_ignored_pages(&site);
site.build()?; site.build()?;
console::report_elapsed_time(start); console::report_elapsed_time(start);
let mut watching_static = false;
// Setup watchers // Setup watchers
let (tx, rx) = channel(); let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(2)).unwrap(); let mut watcher = watcher(tx, Duration::from_secs(2)).unwrap();
watcher.watch("content/", RecursiveMode::Recursive) watcher.watch("content/", RecursiveMode::Recursive)
.chain_err(|| "Can't watch the `content` folder. Does it exist?")?; .chain_err(|| "Can't watch the `content` folder. Does it exist?")?;
watcher.watch("static/", RecursiveMode::Recursive)
.chain_err(|| "Can't watch the `static` folder. Does it exist?")?;
watcher.watch("templates/", RecursiveMode::Recursive) watcher.watch("templates/", RecursiveMode::Recursive)
.chain_err(|| "Can't watch the `templates` folder. Does it exist?")?; .chain_err(|| "Can't watch the `templates` folder. Does it exist?")?;
if Path::new("static").exists() {
watching_static = true;
watcher.watch("static/", RecursiveMode::Recursive)
.chain_err(|| "Can't watch the `static` folder. Does it exist?")?;
}
// Sass support is optional so don't make it an error to no have a sass folder // Sass support is optional so don't make it an error to no have a sass folder
let _ = watcher.watch("sass/", RecursiveMode::Recursive); let _ = watcher.watch("sass/", RecursiveMode::Recursive);
@ -142,11 +147,15 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
let pwd = format!("{}", env::current_dir().unwrap().display()); let pwd = format!("{}", env::current_dir().unwrap().display());
if site.config.compile_sass.unwrap() { let mut watchers = vec!["content", "templates"];
println!("Listening for changes in {}/{{content, static, templates, sass}}", pwd); if watching_static {
} else { watchers.push("static");
println!("Listening for changes in {}/{{content, static, templates}}", pwd);
} }
if site.config.compile_sass.unwrap() {
watchers.push("sass");
}
println!("Listening for changes in {}/{{{}}}", pwd, watchers.join(", "));
println!("Web server is available at http://{}", address); println!("Web server is available at http://{}", address);
println!("Press Ctrl+C to stop\n"); println!("Press Ctrl+C to stop\n");