Skip to content

Commit

Permalink
Merge pull request #71 from dicej/main
Browse files Browse the repository at this point in the history
refactor: make `maybe_translate_relative_link` more concise
  • Loading branch information
dicej authored Jun 29, 2022
2 parents 7ecec5c + 275df6f commit 60a56d8
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/content.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::fs::{read_dir, DirEntry};
use std::iter;
use std::path::PathBuf;
use std::str::FromStr;

Expand Down Expand Up @@ -136,15 +135,9 @@ fn visit_files(dir: PathBuf, cb: &mut dyn FnMut(&DirEntry)) -> anyhow::Result<()
fn maybe_translate_relative_link(dest: markdown::CowStr) -> markdown::CowStr {
if let Some(dest) = dest.strip_suffix(".md") {
if let Some(dest) = dest.strip_prefix("./") {
return iter::once('/')
.chain(dest.chars())
.collect::<String>()
.into();
return format!("/{dest}").into();
} else if !dest.contains('/') {
return iter::once('/')
.chain(dest.chars())
.collect::<String>()
.into();
return format!("/{dest}").into();
}
}

Expand Down

0 comments on commit 60a56d8

Please sign in to comment.