From eaa09999fea208f54f497abb30bad0577623d51d Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Fri, 10 Mar 2017 22:19:36 +0900 Subject: [PATCH] Clippy run --- src/cmd/serve.rs | 10 +++------- src/front_matter.rs | 2 +- src/markdown.rs | 2 +- src/page.rs | 20 ++++++++++---------- src/site.rs | 8 ++++---- src/utils.rs | 2 +- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index 87da4c3f..e84c5eb6 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -155,22 +155,18 @@ fn is_temp_file(path: &Path) -> bool { x if x.ends_with("jb_tmp___") => true, x if x.ends_with("jb_bak___") => true, // vim - x if x.ends_with("~") => true, + x if x.ends_with('~') => true, _ => { if let Some(filename) = path.file_stem() { // emacs - filename.to_str().unwrap().starts_with("#") + filename.to_str().unwrap().starts_with('#') } else { false } } }, None => { - if path.ends_with(".DS_STORE") { - true - } else { - false - } + path.ends_with(".DS_STORE") }, } } diff --git a/src/front_matter.rs b/src/front_matter.rs index ca5349b5..b94827ea 100644 --- a/src/front_matter.rs +++ b/src/front_matter.rs @@ -73,7 +73,7 @@ impl FrontMatter { pub fn parse_date(&self) -> Option { match self.date { Some(ref d) => { - if d.contains("T") { + if d.contains('T') { DateTime::parse_from_rfc3339(d).ok().and_then(|s| Some(s.naive_local())) } else { NaiveDate::parse_from_str(d, "%Y-%m-%d").ok().and_then(|s| Some(s.and_hms(0,0,0))) diff --git a/src/markdown.rs b/src/markdown.rs index f1fe3bbf..8bc6d339 100644 --- a/src/markdown.rs +++ b/src/markdown.rs @@ -73,7 +73,7 @@ impl<'a> Iterator for CodeHighlightingParser<'a> { .and_then(|lang| SETUP.syntax_set.find_syntax_by_token(lang)) .unwrap_or_else(|| SETUP.syntax_set.find_syntax_plain_text()); self.highlighter = Some( - HighlightLines::new(&syntax, &SETUP.theme_set.themes["base16-ocean.dark"]) + HighlightLines::new(syntax, &SETUP.theme_set.themes["base16-ocean.dark"]) ); let snippet = start_coloured_html_snippet(&SETUP.theme_set.themes["base16-ocean.dark"]); Some(Event::Html(Owned(snippet))) diff --git a/src/page.rs b/src/page.rs index 4f004bf1..5863ddeb 100644 --- a/src/page.rs +++ b/src/page.rs @@ -19,8 +19,6 @@ use markdown::markdown_to_html; lazy_static! { static ref PAGE_RE: Regex = Regex::new(r"^\n?\+\+\+\n((?s).*(?-s))\+\+\+\n((?s).*(?-s))$").unwrap(); - static ref SUMMARY_RE: Regex = Regex::new(r"").unwrap(); - static ref CODE_BLOCK_RE: Regex = Regex::new(r"```").unwrap(); } @@ -108,7 +106,7 @@ impl Page { let content = &caps[2]; // 3. create our page, parse front matter and assign all of that - let meta = FrontMatter::parse(&front_matter) + let meta = FrontMatter::parse(front_matter) .chain_err(|| format!("Error when parsing front matter of file `{}`", filepath))?; let mut page = Page::new(meta); @@ -120,15 +118,17 @@ impl Page { // if we see a code block in the content, we assume that this page needs // to be highlighted. It could potentially have false positive if the content // has ``` in it but that seems kind of unlikely - let mut should_highlight = config.highlight_code.unwrap(); - if should_highlight { - should_highlight = CODE_BLOCK_RE.is_match(&page.raw_content); - } + let should_highlight = if config.highlight_code.unwrap() { + page.raw_content.contains("```") + } else { + false + }; + page.content = markdown_to_html(&page.raw_content, should_highlight); if page.raw_content.contains("") { page.summary = { - let summary = SUMMARY_RE.split(&page.raw_content).collect::>()[0]; + let summary = page.raw_content.splitn(2, "").collect::>()[0]; markdown_to_html(summary, should_highlight) } } @@ -157,10 +157,10 @@ impl Page { if !page.sections.is_empty() { page.url = format!("{}/{}", page.sections.join("/"), page.slug); } else { - page.url = format!("{}", page.slug); + page.url = page.slug.clone(); } } - page.permalink = if config.base_url.ends_with("/") { + page.permalink = if config.base_url.ends_with('/') { format!("{}{}", config.base_url, page.url) } else { format!("{}/{}", config.base_url, page.url) diff --git a/src/site.rs b/src/site.rs index 0094982a..dd433d9d 100644 --- a/src/site.rs +++ b/src/site.rs @@ -87,7 +87,7 @@ impl Site { let page = Page::from_file(&entry.as_path(), &self.config)?; for section in &page.sections { - self.sections.entry(section.clone()).or_insert(vec![]).push(page.slug.clone()); + self.sections.entry(section.clone()).or_insert_with(|| vec![]).push(page.slug.clone()); } self.pages.insert(page.slug.clone(), page); @@ -195,11 +195,11 @@ impl Site { pages.push(page); if let Some(ref category) = page.meta.category { - category_pages.entry(category.to_string()).or_insert(vec![]).push(page); + category_pages.entry(category.to_string()).or_insert_with(|| vec![]).push(page); } if let Some(ref tags) = page.meta.tags { for tag in tags { - tag_pages.entry(tag.to_string()).or_insert(vec![]).push(page); + tag_pages.entry(tag.to_string()).or_insert_with(|| vec![]).push(page); } } } @@ -307,7 +307,7 @@ impl Site { context.add("last_build_date", &pages[0].meta.date); context.add("config", &self.config); - let rss_feed_url = if self.config.base_url.ends_with("/") { + let rss_feed_url = if self.config.base_url.ends_with('/') { format!("{}{}", self.config.base_url, "feed.xml") } else { format!("{}/{}", self.config.base_url, "feed.xml") diff --git a/src/utils.rs b/src/utils.rs index 23f509a1..d0280723 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -11,7 +11,7 @@ pub fn create_file>(path: P, content: &str) -> Result<()> { Ok(()) } -/// Very similar to create_dir from the std except it checks if the folder +/// Very similar to `create_dir` from the std except it checks if the folder /// exists before creating it pub fn create_directory>(path: P) -> Result<()> { let path = path.as_ref();