Browse Source

Clippy run

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
eaa09999fe
6 changed files with 20 additions and 24 deletions
  1. +3
    -7
      src/cmd/serve.rs
  2. +1
    -1
      src/front_matter.rs
  3. +1
    -1
      src/markdown.rs
  4. +10
    -10
      src/page.rs
  5. +4
    -4
      src/site.rs
  6. +1
    -1
      src/utils.rs

+ 3
- 7
src/cmd/serve.rs 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_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")
},
}
}


+ 1
- 1
src/front_matter.rs View File

@@ -73,7 +73,7 @@ impl FrontMatter {
pub fn parse_date(&self) -> Option<NaiveDateTime> {
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)))


+ 1
- 1
src/markdown.rs View File

@@ -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)))


+ 10
- 10
src/page.rs View File

@@ -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"<!-- more -->").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("<!-- more -->") {
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)
}
}
@@ -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)


+ 4
- 4
src/site.rs View File

@@ -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")


+ 1
- 1
src/utils.rs View File

@@ -11,7 +11,7 @@ pub fn create_file<P: AsRef<Path>>(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<P: AsRef<Path>>(path: P) -> Result<()> {
let path = path.as_ref();


Loading…
Cancel
Save