Skip to content

Commit

Permalink
Fix some bugs + cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Keats committed Jul 11, 2022
1 parent bf7dbfe commit 0d4c2e8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
3 changes: 2 additions & 1 deletion components/imageproc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ pub fn fix_orientation(img: &DynamicImage, path: &Path) -> Option<DynamicImage>
let mut buf_reader = std::io::BufReader::new(&file);
let exif_reader = exif::Reader::new();
let exif = exif_reader.read_from_container(&mut buf_reader).ok()?;
let orientation = exif.get_field(exif::Tag::Orientation, exif::In::PRIMARY)?.value.get_uint(0)?;
let orientation =
exif.get_field(exif::Tag::Orientation, exif::In::PRIMARY)?.value.get_uint(0)?;
match orientation {
// Values are taken from the page 30 of
// https://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf
Expand Down
2 changes: 1 addition & 1 deletion components/markdown/src/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ pub fn markdown_to_html(
let anchor_idx = match context.insert_anchor {
InsertAnchor::Left => start_idx + 1,
InsertAnchor::Right => end_idx,
InsertAnchor::Heading => 0, // modified later to the correct value
InsertAnchor::Heading => 0, // modified later to the correct value
InsertAnchor::None => unreachable!(),
};
let mut c = tera::Context::new();
Expand Down
8 changes: 2 additions & 6 deletions components/markdown/tests/codeblocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,9 @@ bar

#[test]
fn can_add_line_numbers_windows_eol() {
let body = render_codeblock(
"```linenos\r\nfoo\r\nbar\r\n```\r\n",
true,
);
let body = render_codeblock("```linenos\r\nfoo\r\nbar\r\n```\r\n", true);
insta::assert_snapshot!(body);
}

}

#[test]
fn can_add_line_numbers_with_lineno_start() {
Expand Down
5 changes: 0 additions & 5 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,7 @@ impl Site {

/// Find all the tags and categories if it's asked in the config
pub fn populate_taxonomies(&mut self) -> Result<()> {
if self.config.taxonomies.is_empty() {
return Ok(());
}

self.taxonomies = self.library.read().unwrap().find_taxonomies(&self.config);

Ok(())
}

Expand Down
15 changes: 11 additions & 4 deletions components/templates/src/global_fns/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ impl TeraFn for GetUrl {
// anything else
let mut segments = vec![];

if lang != self.config.default_language && !path[1..].starts_with(&lang) {
segments.push(lang);
};
if lang != self.config.default_language {
if path.is_empty() || !path[1..].starts_with(&lang) {
segments.push(lang);
}
}

segments.push(path);

Expand Down Expand Up @@ -366,7 +368,12 @@ title = "A title"
);
let config = Config::parse(CONFIG_DATA).unwrap();
let dir = create_temp_dir();
let static_fn = GetUrl::new(dir.path().to_path_buf(), config, permalinks, PathBuf::new());
let static_fn = GetUrl::new(
dir.path().to_path_buf(),
config.clone(),
permalinks.clone(),
PathBuf::new(),
);
let mut args = HashMap::new();
args.insert("path".to_string(), to_value("@/a_section/a_page.md").unwrap());
args.insert("lang".to_string(), to_value("fr").unwrap());
Expand Down
5 changes: 2 additions & 3 deletions components/utils/src/anchors.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use libs::regex::Regex;
use libs::regex::escape;
use libs::regex::Regex;

pub fn has_anchor_id(content: &str, anchor: &str) -> bool {
let checks = anchor_id_checks(anchor);
checks.is_match(content)
}

fn anchor_id_checks(anchor: &str) -> Regex {
Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#,
escape(anchor))).unwrap()
Regex::new(&format!(r#"\s(?i)(id|name) *= *("|')*{}("|'| |>)+"#, escape(anchor))).unwrap()
}

#[cfg(test)]
Expand Down

0 comments on commit 0d4c2e8

Please sign in to comment.