Clippy run

This commit is contained in:
Vincent Prouillet 2017-03-10 22:19:36 +09:00
parent 2d26bf038c
commit eaa09999fe
6 changed files with 20 additions and 24 deletions

View file

@ -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_tmp___") => true,
x if x.ends_with("jb_bak___") => true, x if x.ends_with("jb_bak___") => true,
// vim // vim
x if x.ends_with("~") => true, x if x.ends_with('~') => true,
_ => { _ => {
if let Some(filename) = path.file_stem() { if let Some(filename) = path.file_stem() {
// emacs // emacs
filename.to_str().unwrap().starts_with("#") filename.to_str().unwrap().starts_with('#')
} else { } else {
false false
} }
} }
}, },
None => { None => {
if path.ends_with(".DS_STORE") { path.ends_with(".DS_STORE")
true
} else {
false
}
}, },
} }
} }

View file

@ -73,7 +73,7 @@ impl FrontMatter {
pub fn parse_date(&self) -> Option<NaiveDateTime> { pub fn parse_date(&self) -> Option<NaiveDateTime> {
match self.date { match self.date {
Some(ref d) => { Some(ref d) => {
if d.contains("T") { if d.contains('T') {
DateTime::parse_from_rfc3339(d).ok().and_then(|s| Some(s.naive_local())) DateTime::parse_from_rfc3339(d).ok().and_then(|s| Some(s.naive_local()))
} else { } else {
NaiveDate::parse_from_str(d, "%Y-%m-%d").ok().and_then(|s| Some(s.and_hms(0,0,0))) NaiveDate::parse_from_str(d, "%Y-%m-%d").ok().and_then(|s| Some(s.and_hms(0,0,0)))

View file

@ -73,7 +73,7 @@ impl<'a> Iterator for CodeHighlightingParser<'a> {
.and_then(|lang| SETUP.syntax_set.find_syntax_by_token(lang)) .and_then(|lang| SETUP.syntax_set.find_syntax_by_token(lang))
.unwrap_or_else(|| SETUP.syntax_set.find_syntax_plain_text()); .unwrap_or_else(|| SETUP.syntax_set.find_syntax_plain_text());
self.highlighter = Some( 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"]); let snippet = start_coloured_html_snippet(&SETUP.theme_set.themes["base16-ocean.dark"]);
Some(Event::Html(Owned(snippet))) Some(Event::Html(Owned(snippet)))

View file

@ -19,8 +19,6 @@ use markdown::markdown_to_html;
lazy_static! { lazy_static! {
static ref PAGE_RE: Regex = Regex::new(r"^\n?\+\+\+\n((?s).*(?-s))\+\+\+\n((?s).*(?-s))$").unwrap(); static ref PAGE_RE: Regex = Regex::new(r"^\n?\+\+\+\n((?s).*(?-s))\+\+\+\n((?s).*(?-s))$").unwrap();
static ref SUMMARY_RE: Regex = Regex::new(r"<!-- more -->").unwrap();
static ref CODE_BLOCK_RE: Regex = Regex::new(r"```").unwrap();
} }
@ -108,7 +106,7 @@ impl Page {
let content = &caps[2]; let content = &caps[2];
// 3. create our page, parse front matter and assign all of that // 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))?; .chain_err(|| format!("Error when parsing front matter of file `{}`", filepath))?;
let mut page = Page::new(meta); 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 // 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 // to be highlighted. It could potentially have false positive if the content
// has ``` in it but that seems kind of unlikely // has ``` in it but that seems kind of unlikely
let mut should_highlight = config.highlight_code.unwrap(); let should_highlight = if config.highlight_code.unwrap() {
if should_highlight { page.raw_content.contains("```")
should_highlight = CODE_BLOCK_RE.is_match(&page.raw_content); } else {
} false
};
page.content = markdown_to_html(&page.raw_content, should_highlight); page.content = markdown_to_html(&page.raw_content, should_highlight);
if page.raw_content.contains("<!-- more -->") { if page.raw_content.contains("<!-- more -->") {
page.summary = { page.summary = {
let summary = SUMMARY_RE.split(&page.raw_content).collect::<Vec<&str>>()[0]; let summary = page.raw_content.splitn(2, "<!-- more -->").collect::<Vec<&str>>()[0];
markdown_to_html(summary, should_highlight) markdown_to_html(summary, should_highlight)
} }
} }
@ -157,10 +157,10 @@ impl Page {
if !page.sections.is_empty() { if !page.sections.is_empty() {
page.url = format!("{}/{}", page.sections.join("/"), page.slug); page.url = format!("{}/{}", page.sections.join("/"), page.slug);
} else { } 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) format!("{}{}", config.base_url, page.url)
} else { } else {
format!("{}/{}", config.base_url, page.url) format!("{}/{}", config.base_url, page.url)

View file

@ -87,7 +87,7 @@ impl Site {
let page = Page::from_file(&entry.as_path(), &self.config)?; let page = Page::from_file(&entry.as_path(), &self.config)?;
for section in &page.sections { 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); self.pages.insert(page.slug.clone(), page);
@ -195,11 +195,11 @@ impl Site {
pages.push(page); pages.push(page);
if let Some(ref category) = page.meta.category { 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 { if let Some(ref tags) = page.meta.tags {
for tag in 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("last_build_date", &pages[0].meta.date);
context.add("config", &self.config); 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") format!("{}{}", self.config.base_url, "feed.xml")
} else { } else {
format!("{}/{}", self.config.base_url, "feed.xml") format!("{}/{}", self.config.base_url, "feed.xml")

View file

@ -11,7 +11,7 @@ pub fn create_file<P: AsRef<Path>>(path: P, content: &str) -> Result<()> {
Ok(()) 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 /// exists before creating it
pub fn create_directory<P: AsRef<Path>>(path: P) -> Result<()> { pub fn create_directory<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref(); let path = path.as_ref();