Skip to content

Commit

Permalink
[code] apply clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestthompson3 committed Jan 25, 2024
1 parent ed2de11 commit 28c9328
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libs/build/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn process_migration_file(entry_path: PathBuf, target: PathBuf, data_dir: &Path)
let file_name = file_name.to_str().unwrap();
if file_name == "todo.txt" {
let new_loc = data_dir.join(file_name);
fs::rename(&entry_path, &new_loc).unwrap();
fs::rename(&entry_path, new_loc).unwrap();
return;
}
if file_name.ends_with("md") {
Expand Down
19 changes: 12 additions & 7 deletions libs/build/src/pages.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_recursion::async_recursion;
use futures::{stream, StreamExt};
use std::fmt::Write;

use render::static_site_page::StaticSitePage;
use wikitext::{
Expand Down Expand Up @@ -78,7 +79,7 @@ impl Default for Builder {
}
}

async fn process_file(path: PathBuf, backlinks: &mut GlobalBacklinks, pages: ParsedPages) {
async fn process_file(path: PathBuf, backlinks: &GlobalBacklinks, pages: ParsedPages) {
let note = path_to_data_structure(&path).unwrap();
let structured = note.to_structured().as_owned();
let mut backlinks = backlinks.lock().await;
Expand All @@ -95,14 +96,14 @@ async fn parse_entries(
) {
let entries = read_dir(entrypoint).unwrap();
let pipeline = stream::iter(entries).for_each(|entry| async {
let mut links = Arc::clone(&backlinks);
let links = Arc::clone(&backlinks);
let pages = Arc::clone(&rendered_pages);
let entry = entry.unwrap();
let file_name = entry.file_name();
let file_name = file_name.to_str().unwrap();
if entry.file_type().unwrap().is_file() && file_name.ends_with(".txt") {
tokio::spawn(async move {
process_file(entry.path(), &mut links, pages).await;
process_file(entry.path(), &links, pages).await;
})
.await
.unwrap();
Expand All @@ -117,10 +118,14 @@ async fn parse_entries(

async fn write_index_page(pages: &ParsedPages) {
let page_vals = pages.lock().await;
let pages: String = page_vals
.iter()
.map(|page| format!(r#"<li><a href="{}">{}</a></li>"#, page.title, page.title))
.collect();
let pages: String = page_vals.iter().fold(String::new(), |mut output, page| {
let _ = write!(
output,
r#"<li><a href="{}">{}</a></li>"#,
page.title, page.title
);
output
});
let body = format!(
r#"<h1>Pages</h1><ul style="margin: 1rem 0rem;">{}</ul>"#,
pages
Expand Down
2 changes: 1 addition & 1 deletion libs/persistance/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ pub async fn move_archive(old_title: String, new_title: String) {
// TODO: this is really dependent on file system ops, won't be good if we change the storage
// backend.
pub fn path_to_string<P: AsRef<Path> + ?Sized>(path: &P) -> Result<String, std::io::Error> {
std::fs::read_to_string(&path)
std::fs::read_to_string(path)
}

pub fn path_to_data_structure(path: &Path) -> Result<Note, ReadPageError> {
Expand Down

0 comments on commit 28c9328

Please sign in to comment.