* Add hard_link_static config option. * Copy or hardlink file depending on an argument. Modify the call sites for `copy_file` to account for the extra argument. * Plug the config setting through to copy_file. Don't apply the config option to theme's static directory. * Update documentation. * Backticks make no sense in this comment. * Addressing PR comments. * Be consistent with argument naming.index-subcmd
@@ -106,6 +106,8 @@ pub struct Config { | |||||
pub generate_rss: bool, | pub generate_rss: bool, | ||||
/// The number of articles to include in the RSS feed. Defaults to including all items. | /// The number of articles to include in the RSS feed. Defaults to including all items. | ||||
pub rss_limit: Option<usize>, | pub rss_limit: Option<usize>, | ||||
/// If set, files from static/ will be hardlinked instead of copied to the output dir. | |||||
pub hard_link_static: bool, | |||||
pub taxonomies: Vec<Taxonomy>, | pub taxonomies: Vec<Taxonomy>, | ||||
@@ -280,6 +282,7 @@ impl Default for Config { | |||||
languages: Vec::new(), | languages: Vec::new(), | ||||
generate_rss: false, | generate_rss: false, | ||||
rss_limit: None, | rss_limit: None, | ||||
hard_link_static: false, | |||||
taxonomies: Vec::new(), | taxonomies: Vec::new(), | ||||
compile_sass: false, | compile_sass: false, | ||||
check_external_links: false, | check_external_links: false, | ||||
@@ -597,11 +597,12 @@ impl Site { | |||||
copy_directory( | copy_directory( | ||||
&self.base_path.join("themes").join(theme).join("static"), | &self.base_path.join("themes").join(theme).join("static"), | ||||
&self.output_path, | &self.output_path, | ||||
false | |||||
)?; | )?; | ||||
} | } | ||||
// We're fine with missing static folders | // We're fine with missing static folders | ||||
if self.static_path.exists() { | if self.static_path.exists() { | ||||
copy_directory(&self.static_path, &self.output_path)?; | |||||
copy_directory(&self.static_path, &self.output_path, self.config.hard_link_static)?; | |||||
} | } | ||||
Ok(()) | Ok(()) | ||||
@@ -95,7 +95,7 @@ pub fn find_related_assets(path: &Path) -> Vec<PathBuf> { | |||||
/// Copy a file but takes into account where to start the copy as | /// Copy a file but takes into account where to start the copy as | ||||
/// there might be folders we need to create on the way | /// there might be folders we need to create on the way | ||||
pub fn copy_file(src: &Path, dest: &PathBuf, base_path: &PathBuf) -> Result<()> { | |||||
pub fn copy_file(src: &Path, dest: &PathBuf, base_path: &PathBuf, hard_link: bool) -> Result<()> { | |||||
let relative_path = src.strip_prefix(base_path).unwrap(); | let relative_path = src.strip_prefix(base_path).unwrap(); | ||||
let target_path = dest.join(relative_path); | let target_path = dest.join(relative_path); | ||||
@@ -103,11 +103,15 @@ pub fn copy_file(src: &Path, dest: &PathBuf, base_path: &PathBuf) -> Result<()> | |||||
create_dir_all(parent_directory)?; | create_dir_all(parent_directory)?; | ||||
} | } | ||||
copy(src, target_path)?; | |||||
if hard_link { | |||||
std::fs::hard_link(src, target_path)? | |||||
} else { | |||||
copy(src, target_path)?; | |||||
} | |||||
Ok(()) | Ok(()) | ||||
} | } | ||||
pub fn copy_directory(src: &PathBuf, dest: &PathBuf) -> Result<()> { | |||||
pub fn copy_directory(src: &PathBuf, dest: &PathBuf, hard_link: bool) -> Result<()> { | |||||
for entry in WalkDir::new(src).into_iter().filter_map(std::result::Result::ok) { | for entry in WalkDir::new(src).into_iter().filter_map(std::result::Result::ok) { | ||||
let relative_path = entry.path().strip_prefix(src).unwrap(); | let relative_path = entry.path().strip_prefix(src).unwrap(); | ||||
let target_path = dest.join(relative_path); | let target_path = dest.join(relative_path); | ||||
@@ -117,7 +121,7 @@ pub fn copy_directory(src: &PathBuf, dest: &PathBuf) -> Result<()> { | |||||
create_directory(&target_path)?; | create_directory(&target_path)?; | ||||
} | } | ||||
} else { | } else { | ||||
copy_file(entry.path(), dest, src)?; | |||||
copy_file(entry.path(), dest, src, hard_link)?; | |||||
} | } | ||||
} | } | ||||
Ok(()) | Ok(()) | ||||
@@ -41,6 +41,12 @@ generate_rss = false | |||||
# not set (the default). | # not set (the default). | ||||
# rss_limit = 20 | # rss_limit = 20 | ||||
# Whether to copy or hardlink files in static/ directory. Useful for sites | |||||
# whose static files are large. Note that for this to work, both static/ and | |||||
# output directory need to be on the same filesystem. Also, theme's static/ | |||||
# files are always copies, regardles of this setting. False by default. | |||||
# hard_link_static = false | |||||
# The taxonomies to be rendered for that site and their configuration | # The taxonomies to be rendered for that site and their configuration | ||||
# Example: | # Example: | ||||
# taxonomies = [ | # taxonomies = [ | ||||
@@ -38,6 +38,8 @@ The directory structure of the `sass` folder will be preserved when copying over | |||||
## `static` | ## `static` | ||||
Contains any kind of files. All the files/folders in the `static` folder will be copied as-is in the output directory. | Contains any kind of files. All the files/folders in the `static` folder will be copied as-is in the output directory. | ||||
If your static files are large you can configure Zola to [hard link](https://en.wikipedia.org/wiki/Hard_link) them | |||||
instead of copying by setting `hard_link_static = true` in the config file. | |||||
## `templates` | ## `templates` | ||||
Contains all the [Tera](https://tera.netlify.com) templates that will be used to render this site. | Contains all the [Tera](https://tera.netlify.com) templates that will be used to render this site. | ||||
@@ -325,7 +325,7 @@ pub fn serve( | |||||
} else { | } else { | ||||
rebuild_done_handling( | rebuild_done_handling( | ||||
&broadcaster, | &broadcaster, | ||||
copy_file(&path, &site.output_path, &site.static_path), | |||||
copy_file(&path, &site.output_path, &site.static_path, site.config.hard_link_static), | |||||
&partial_path.to_string_lossy(), | &partial_path.to_string_lossy(), | ||||
); | ); | ||||
} | } | ||||