summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 2920917..25d1528 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,7 @@ use markdown::*;
use vagabond::*;
use std::collections::HashSet;
+use std::time::SystemTime;
const NORMAL: &str = "\x1b[0m";
@@ -95,7 +96,7 @@ fn main() {
// Convert document to different formats.
if args.html {
let html = generate_html(&page.document, page, &website);
- write_file(&html, &destination, "html");
+ write_file(&html, &destination, "html", page.last_modified);
}
// Copy original markdown file.
destination.add_extension("md");
@@ -115,15 +116,7 @@ fn main() {
static_file.source_path, destination));
}
- for static_dir in &website.static_dirs {
- let mut destination = destination.clone();
- destination.push(&static_dir.full_url);
- verbose!("Copying static directory to {destination:?}");
- make_parent_directory(&destination).unwrap();
- copy(&static_dir.source_path, &destination).unwrap_or_else(|_|
- error!("Failed to copy static directory {:?} to {:?}",
- static_dir.source_path, destination));
- }
+ // NOTE: Static dir contents are copied as part of all static files.
for redirect in &website.redirects {
let mut destination = destination.clone();
@@ -132,12 +125,12 @@ fn main() {
if args.html {
if !path.contains("://") {
if let Some(path) = website.has_page(redirect, &path, "html") {
- write_file(&generate_html_redirect(&path), &destination, "html");
+ write_file(&generate_html_redirect(&path), &destination, "html", redirect.last_modified);
} else {
warn!("Redirect {:?} links to nonexistent page {path:?}", redirect.name);
}
} else {
- write_file(&generate_html_redirect(&path), &destination, "html");
+ write_file(&generate_html_redirect(&path), &destination, "html", redirect.last_modified);
}
}
}
@@ -145,7 +138,7 @@ fn main() {
-pub fn write_file(text: &str, destination: &PathBuf, ext: &str) {
+pub fn write_file(text: &str, destination: &PathBuf, ext: &str, last_modified: Option<SystemTime>) {
let mut destination = destination.clone();
destination.add_extension(ext);
verbose!("Generating {destination:?}");
@@ -153,6 +146,12 @@ pub fn write_file(text: &str, destination: &PathBuf, ext: &str) {
error!("Failed to create parent directories for {destination:?}"));
write_to_file(&destination, text).unwrap_or_else(|_|
error!("Failed to write generated {ext} file to {destination:?}"));
+ // Set the last-modified time of the new file to the time provided.
+ if let Some(time) = last_modified {
+ if let Ok(dest) = std::fs::File::open(&destination) {
+ let _ = dest.set_modified(time);
+ }
+ }
}
pub fn make_url_safe(text: &str) -> String {