Skip to content

Commit

Permalink
Allow static folder to be missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Prouillet committed Oct 25, 2017
1 parent 57b9095 commit 1d8df57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fix generated index section not found in `get_section` global function
- Fix permalink generation for index page
- Add Nim syntax highlighting
- Allow static folder to be missing


## 0.2.1 (2017-10-17)
Expand Down
5 changes: 4 additions & 1 deletion components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ impl Site {
&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(())
}
Expand Down
19 changes: 14 additions & 5 deletions src/cmd/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,22 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {
console::warn_about_ignored_pages(&site);
site.build()?;
console::report_elapsed_time(start);
let mut watching_static = false;

// Setup watchers
let (tx, rx) = channel();
let mut watcher = watcher(tx, Duration::from_secs(2)).unwrap();
watcher.watch("content/", RecursiveMode::Recursive)
.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)
.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
let _ = watcher.watch("sass/", RecursiveMode::Recursive);

Expand Down Expand Up @@ -142,11 +147,15 @@ pub fn serve(interface: &str, port: &str, config_file: &str) -> Result<()> {

let pwd = format!("{}", env::current_dir().unwrap().display());

let mut watchers = vec!["content", "templates"];
if watching_static {
watchers.push("static");
}
if site.config.compile_sass.unwrap() {
println!("Listening for changes in {}/{{content, static, templates, sass}}", pwd);
} else {
println!("Listening for changes in {}/{{content, static, templates}}", pwd);
watchers.push("sass");
}

println!("Listening for changes in {}/{{{}}}", pwd, watchers.join(", "));
println!("Web server is available at http://{}", address);
println!("Press Ctrl+C to stop\n");

Expand Down

0 comments on commit 1d8df57

Please sign in to comment.