Skip to content

Commit

Permalink
Merge pull request #1209 from epage/template
Browse files Browse the repository at this point in the history
chore: Update from _rust template
  • Loading branch information
epage authored Sep 27, 2024
2 parents c6c0232 + 2e2573d commit 8321749
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp
PRs should tell a cohesive story, with test and refactor commits that keep the
fix or feature commits simple and clear.

Specifically, we would encouage
Specifically, we would encourage
- File renames be isolated into their own commit
- Add tests in a commit before their feature or fix, showing the current behavior.
The diff for the feature/fix commit will then show how the behavior changed,
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ string_lit_as_bytes = "warn"
# string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
# wildcard_imports = "warn"
zero_sized_map_values = "warn"
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl fmt::Display for Config {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut converted = serde_yaml::to_string(self).map_err(|_| fmt::Error)?;
converted.drain(..4);
write!(f, "{}", converted)
write!(f, "{converted}")
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/config/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod test {
fn split_document_no_new_line_after_front_matter() {
let input = "invalid_front_matter---\nbody";
let (cobalt_model, content) = split_document(input);
println!("{:?}", cobalt_model);
println!("{cobalt_model:?}");
assert!(cobalt_model.is_none());
assert_eq!(content, input);
}
Expand All @@ -196,7 +196,7 @@ mod test {
fn split_document_multiline_body() {
let input = "---\ncobalt_model\n---\nfirst\nsecond";
let (cobalt_model, content) = split_document(input);
println!("{:?}", cobalt_model);
println!("{cobalt_model:?}");
assert_eq!(cobalt_model.unwrap(), "cobalt_model\n");
assert_eq!(content, "first\nsecond");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/frontmatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl fmt::Display for Frontmatter {
if converted.is_empty() {
Ok(())
} else {
write!(f, "{}", converted)
write!(f, "{converted}")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ mod test_rel_path {
#[test]
fn test_try_from_abspath_fails() {
let case = RelPath::try_from("/foo/bar");
println!("{:?}", case);
println!("{case:?}");
assert!(case.is_err());
}
}
7 changes: 2 additions & 5 deletions crates/engarde/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ impl Raw {
pub fn format(&self, code: &str, lang: Option<&str>, _theme: Option<&str>) -> String {
let code = html_escape(code);
if let Some(ref lang) = lang {
format!(
"<pre><code class=\"language-{}\">{}</code></pre>\n",
lang, code
)
format!("<pre><code class=\"language-{lang}\">{code}</code></pre>\n")
} else {
format!("<pre><code>{}</code></pre>\n", code)
format!("<pre><code>{code}</code></pre>\n")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/file-serve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ServerBuilder {

Server {
source,
addr: format!("{}:{}", hostname, port),
addr: format!("{hostname}:{port}"),
server: RwLock::new(None),
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ fn static_file_handler(dest: &std::path::Path, req: tiny_http::Request) -> Resul
let file = std::fs::File::open(&serve_path).map_err(Error::new)?;
let mut response = tiny_http::Response::from_file(file);
if let Some(mime) = mime_guess::MimeGuess::from_path(&serve_path).first_raw() {
let content_type = format!("Content-Type:{}", mime);
let content_type = format!("Content-Type:{mime}");
let content_type =
tiny_http::Header::from_str(&content_type).expect("formatted correctly");
response.add_header(content_type);
Expand Down
2 changes: 1 addition & 1 deletion crates/file-serve/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
let path = match std::env::current_dir() {
Ok(path) => path,
Err(err) => {
eprintln!("Cannot serve CWD: {}", err);
eprintln!("Cannot serve CWD: {err}");
std::process::exit(1);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/bin/cobalt/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ impl DebugCommands {
Self::Config { config } => {
let config = config.load_config()?;
let config = cobalt::cobalt_model::Config::from_config(config)?;
println!("{}", config);
println!("{config}");
}
Self::Highlight(HighlightCommands::Themes { config }) => {
let config = config.load_config()?;
let config = cobalt::cobalt_model::Config::from_config(config)?;
for name in config.syntax.themes() {
println!("{}", name);
println!("{name}");
}
}
Self::Highlight(HighlightCommands::Syntaxes { config }) => {
let config = config.load_config()?;
let config = cobalt::cobalt_model::Config::from_config(config)?;
for name in config.syntax.syntaxes() {
println!("{}", name);
println!("{name}");
}
}
Self::Files { collection, config } => {
Expand Down
4 changes: 2 additions & 2 deletions src/bin/cobalt/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub(crate) fn create_new_document(
(parent_dir, filename, ext)
};

let interim_path = parent_dir.join(format!("NON_EXISTENT.{}", extension));
let interim_path = parent_dir.join(format!("NON_EXISTENT.{extension}"));
let interim_path = cobalt_core::SourcePath::from_root(&config.source, &interim_path)
.ok_or_else(|| {
anyhow::format_err!(
Expand Down Expand Up @@ -271,7 +271,7 @@ pub(crate) fn create_new_document(

let source_path = config
.source
.join(format!("_defaults/{}.{}", collection_slug, extension));
.join(format!("_defaults/{collection_slug}.{extension}"));
let source = if source_path.is_file() {
cobalt_model::files::read_file(&source_path)
.with_context(|| anyhow::format_err!("Failed to read default: {:?}", source_path))?
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cobalt/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn serve(server: &file_serve::Server) -> Result<()> {
fn open_browser(url: String) -> Result<()> {
match open::that(url) {
Ok(()) => info!("Please check your browser!"),
Err(why) => eprintln!("Failure to execute command: {}", why),
Err(why) => eprintln!("Failure to execute command: {why}"),
}
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions src/cobalt_model/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ impl Config {
ignore.push(format!("/{}", rel_dest.to_owned()).into());
}
}
ignore.push(format!("/{}", includes_dir).into());
ignore.push(format!("/{}", layouts_dir).into());
ignore.push(format!("/{includes_dir}").into());
ignore.push(format!("/{layouts_dir}").into());
ignore.push("/_defaults".into());
ignore.push(format!("/{}", assets.sass.import_dir).into());
assert_eq!(pages.dir, "");
assert_eq!(pages.drafts_dir, None);
ignore.push(format!("!/{}", posts.dir).into());
if let Some(dir) = posts.drafts_dir.as_deref() {
ignore.push(format!("!/{}", dir).into());
ignore.push(format!("!/{dir}").into());
}
ignore.extend(custom_ignore);

Expand Down Expand Up @@ -151,7 +151,7 @@ impl fmt::Display for Config {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut converted = serde_yaml::to_string(self).map_err(|_| fmt::Error)?;
converted.drain(..4);
write!(f, "{}", converted)
write!(f, "{converted}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cobalt_model/frontmatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl fmt::Display for Frontmatter {
if converted.is_empty() {
Ok(())
} else {
write!(f, "{}", converted)
write!(f, "{converted}")
}
}
}
8 changes: 3 additions & 5 deletions src/syntax_highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ mod test_syntsx {
.unwrap();
let template = parser
.parse(&format!(
"{{% highlight rust %}}{}{{% endhighlight %}}",
CODE_BLOCK
"{{% highlight rust %}}{CODE_BLOCK}{{% endhighlight %}}"
))
.unwrap();
let output = template.render(&liquid::Object::new());
Expand All @@ -264,9 +263,8 @@ mod test_syntsx {
fn markdown_renders_rust() {
let html = format!(
"```rust
{}
```",
CODE_BLOCK
{CODE_BLOCK}
```"
);

let mut buf = String::new();
Expand Down

0 comments on commit 8321749

Please sign in to comment.