Skip to content

Commit

Permalink
Fix resource loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Jan 11, 2025
1 parent b77de6b commit 179cb65
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ impl Site {

fn load_resources(&self, root_path: &str) {
let content_root = Path::new(root_path)
.join("sites")
.join(self.domain.to_string())
.join("_content");
if !content_root.exists() {
Expand All @@ -174,7 +175,7 @@ impl Site {
if relative_path.starts_with("files/") {
continue;
}
println!("Scanning file {}...", path.display());
log::debug!("Scanning file {}...", path.display());
let file = File::open(&path).unwrap();
let mut reader = BufReader::new(file);
let filename = path.to_str().unwrap().to_string();
Expand All @@ -185,7 +186,7 @@ impl Site {
let mut slug: Option<String> = None;
let content_source: ContentSource;
if let Some(event) = nostr::parse_event(&front_matter, &content) {
println!("Event: id={}.", &event.id);
log::info!("Event: id={}.", &event.id);
let event_ref = EventRef {
id: event.id.to_owned(),
created_at: event.created_at,
Expand Down Expand Up @@ -222,7 +223,7 @@ impl Site {
let file_stem = relative_path.file_stem().unwrap().to_str().unwrap();
// TODO: extract path patterns from config
if relative_path.starts_with("data") {
println!("Data: id={}.", file_stem);
log::info!("Data: id={}.", file_stem);
let data: serde_yaml::Value = serde_yaml::from_str(&content).unwrap();
let mut site_data = self.data.write().unwrap();
site_data.insert(file_stem.to_string(), data);
Expand All @@ -243,10 +244,10 @@ impl Site {
date = Some(NaiveDateTime::new(d, midnight));
slug = Some(file_stem[11..].to_owned());
} else {
println!("Post missing title: {}", file_stem);
log::warn!("Post missing title: {}", file_stem);
}
} else {
println!("Cannot parse post date from filename: {}", file_stem);
log::warn!("Cannot parse post date from filename: {}", file_stem);
};
} else if relative_path.starts_with("pages") {
if front_matter.contains_key("title") {
Expand All @@ -266,7 +267,7 @@ impl Site {
.to_string(),
);
} else {
println!("Page missing title: {}", file_stem);
log::warn!("Page missing title: {}", file_stem);
}
} else if relative_path.starts_with("notes") {
kind = Some(ResourceKind::Note);
Expand All @@ -289,7 +290,7 @@ impl Site {
content_source,
};
if let Some(url) = resource.get_resource_url() {
println!("Resource: url={}.", &url);
log::info!("Resource: url={}.", &url);
let mut resources = self.resources.write().unwrap();
resources.insert(url, resource);
}
Expand Down Expand Up @@ -565,7 +566,7 @@ pub fn load_sites(root_path: &str) -> HashMap<String, Site> {
}
}

println!("{} sites loaded!", sites.len());
log::info!("{} sites loaded!", sites.len());

sites
}
Expand Down

0 comments on commit 179cb65

Please sign in to comment.