Skip to content

rustfmt: Fix broken formatting #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion serve/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ async fn main() -> Result<(), Box<dyn Error>> {

let footer = format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));

warpy::server::run(format!("{}/../site", env!("CARGO_MANIFEST_DIR")), [0, 0, 0, 0], footer, Some(8000), false).await?;
warpy::server::run(
format!("{}/../site", env!("CARGO_MANIFEST_DIR")),
[0, 0, 0, 0],
footer,
Some(8000),
false,
)
.await?;
Ok(())
}
7 changes: 5 additions & 2 deletions src/blog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ pub fn main() -> eyre::Result<()> {

lib::main()?;

println!("blog has been generated; you can now serve its content by running\n\
println!(
"blog has been generated; you can now serve its content by running\n\
{INDENT}python3 -m http.server --directory {ROOT}/site\n\
or running:\n\
{INDENT}cargo run -p serve\n\
or you can read it directly by opening a web browser on:\n\
{INDENT}file:///{ROOT}/site/index.html",
ROOT=env!("CARGO_MANIFEST_DIR"), INDENT=" ");
ROOT = env!("CARGO_MANIFEST_DIR"),
INDENT = " "
);

Ok(())
}
6 changes: 1 addition & 5 deletions src/blogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,7 @@ pub(crate) fn load(base: &Path) -> eyre::Result<Vec<Blog>> {
Ok(blogs)
}

fn load_recursive(
base: &Path,
current: &Path,
blogs: &mut Vec<Blog>,
) -> eyre::Result<()> {
fn load_recursive(base: &Path, current: &Path, blogs: &mut Vec<Blog>) -> eyre::Result<()> {
for entry in std::fs::read_dir(current)? {
let path = entry?.path();
let file_type = path.metadata()?.file_type();
Expand Down
19 changes: 12 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ mod posts;
use self::blogs::Blog;
use self::posts::Post;
use chrono::Timelike;
use eyre::{eyre, WrapErr};
use handlebars::{handlebars_helper, Handlebars};
use rayon::prelude::*;
use sass_rs::{compile_file, Options};
use serde_derive::Serialize;
use serde_json::json;
use std::convert::AsRef;
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use eyre::{eyre, WrapErr};
use rayon::prelude::*;

struct Generator<'a> {
handlebars: Handlebars<'a>,
Expand Down Expand Up @@ -102,22 +102,23 @@ impl<'a> Generator<'a> {
let css = compile_file(&scss_file, Options::default())
.map_err(|error| eyre!(error))
.wrap_err_with(|| format!("couldn't compile sass: {}", &scss_file))?;
let mut file =
File::create(&css_file).wrap_err_with(|| format!("couldn't make css file: {}", &css_file))?;
let mut file = File::create(&css_file)
.wrap_err_with(|| format!("couldn't make css file: {}", &css_file))?;
file.write_all(&css.into_bytes())
.wrap_err_with(|| format!("couldn't write css file: {}", &css_file))?;

Ok(())
}

fn concat_vendor_css(&self, files: Vec<&str>)-> eyre::Result<()> {
fn concat_vendor_css(&self, files: Vec<&str>) -> eyre::Result<()> {
let mut concatted = String::new();
for filestem in files {
let vendor_path = format!("./static/styles/{}.css", filestem);
let contents = fs::read_to_string(vendor_path).wrap_err("couldn't read vendor css")?;
concatted.push_str(&contents);
}
fs::write("./static/styles/vendor.css", &concatted).wrap_err("couldn't write vendor css")?;
fs::write("./static/styles/vendor.css", &concatted)
.wrap_err("couldn't write vendor css")?;

Ok(())
}
Expand All @@ -132,7 +133,11 @@ impl<'a> Generator<'a> {
self.render_feed(blog)?;
self.render_releases_feed(blog)?;

let paths = blog.posts().par_iter().map(|post| self.render_post(blog, post)).collect::<Result<Vec<_>, _>>()?;
let paths = blog
.posts()
.par_iter()
.map(|post| self.render_post(blog, post))
.collect::<Result<Vec<_>, _>>()?;
if let Some(path) = paths.first() {
println!("└─ Latest post: {}\n", self.file_url(path));
}
Expand Down
12 changes: 7 additions & 5 deletions src/posts.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::blogs::Manifest;
use eyre::eyre;
use regex::Regex;
use serde_derive::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use eyre::eyre;

#[derive(Debug, PartialEq, Deserialize)]
struct YamlHeader {
Expand Down Expand Up @@ -50,9 +50,9 @@ impl Post {

let contents = std::fs::read_to_string(path)?;
if contents.len() < 5 {
return Err(
eyre!("{path:?} is empty, or too short to have valid front matter")
);
return Err(eyre!(
"{path:?} is empty, or too short to have valid front matter"
));
}

// yaml headers.... we know the first four bytes of each file are "---\n"
Expand All @@ -68,7 +68,9 @@ impl Post {
} = serde_yaml::from_str(yaml)?;
// next, the contents. we add + to get rid of the final "---\n\n"
let options = comrak::Options {
render: comrak::RenderOptionsBuilder::default().unsafe_(true).build()?,
render: comrak::RenderOptionsBuilder::default()
.unsafe_(true)
.build()?,
extension: comrak::ExtensionOptionsBuilder::default()
.header_ids(Some(String::new()))
.footnotes(true)
Expand Down