Skip to content

Commit

Permalink
feat(ssg): v0.0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Oct 4, 2023
1 parent 49108f2 commit 5e88664
Show file tree
Hide file tree
Showing 17 changed files with 585 additions and 135 deletions.
258 changes: 139 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ name = "ssg"
readme = "README.md"
repository = "https://github.com/sebastienrousseau/shokunin"
rust-version = "1.71.1"
version = "0.0.18"
version = "0.0.19"
include = [
"/CONTRIBUTING.md",
"/LICENSE-APACHE",
Expand All @@ -46,20 +46,20 @@ harness = false
path = "benches/bench.rs"

[dependencies]
clap = "4.4.5"
comrak = "0.18.0"
clap = "4.4.6"
comrak = "0.19.0"
dtt = "0.0.4"
log = {version="0.4.20", features = ["std"] }
minify-html = "0.11.1"
openssl = { version = "0.10.57", features = ["vendored"] }
quick-xml = "0.30.0"
regex = "1.9.5"
reqwest = { version = "0.11.20", features = ["blocking", "json"] }
regex = "1.9.6"
reqwest = { version = "0.11.22", features = ["blocking", "json"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
serde_yaml = "0.9.25"
tempfile = "3.8.0"
toml = "0.8.1"
toml = "0.8.2"
yaml-rust = "0.4.5"
vrd = "0.0.4"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ To use the Shokunin Static Site Generator (SSG) library in your project, add the

```toml
[dependencies]
shokunin = "0.0.18"
shokunin = "0.0.19"
```

Add the following to your `main.rs` file:
Expand Down Expand Up @@ -282,6 +282,6 @@ A special thank you goes to the [Rust Reddit][13] community for providing a lot
[crates-badge]: https://img.shields.io/crates/v/ssg.svg?style=for-the-badge 'Crates.io badge'
[divider]: https://kura.pro/common/images/elements/divider.svg "divider"
[docs-badge]: https://img.shields.io/docsrs/ssg.svg?style=for-the-badge 'Docs.rs badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.18-orange.svg?style=for-the-badge 'Lib.rs badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.19-orange.svg?style=for-the-badge 'Lib.rs badge'
[license-badge]: https://img.shields.io/crates/l/ssg.svg?style=for-the-badge 'License badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'
4 changes: 2 additions & 2 deletions TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<!-- markdownlint-enable MD033 MD041 -->

# Shokunin Static Site Generator v0.0.18 🦀
# Shokunin Static Site Generator v0.0.19 🦀

A Content-First Open Source Static Site Generator (SSG) written in Rust

Expand Down Expand Up @@ -70,7 +70,7 @@ Shokunin Static Site Generator (SSG) feature highlights include:
[crates-badge]: https://img.shields.io/crates/v/ssg.svg?style=for-the-badge 'Crates.io badge'
[divider]: https://kura.pro/common/images/elements/divider.svg "divider"
[docs-badge]: https://img.shields.io/docsrs/ssg.svg?style=for-the-badge 'Docs.rs badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.18-orange.svg?style=for-the-badge 'Lib.rs badge'
[libs-badge]: https://img.shields.io/badge/lib.rs-v0.0.19-orange.svg?style=for-the-badge 'Lib.rs badge'
[license-badge]: https://img.shields.io/crates/l/ssg.svg?style=for-the-badge 'License badge'
[made-with-rust-badge]: https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust 'Made With Rust badge'

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! *Part of the [Mini Functions][0] family of Rust libraries.*
//!
//! [![Crates.io](https://img.shields.io/crates/v/ssg.svg?style=for-the-badge&color=success&labelColor=27A006)](https://crates.io/crates/ssg "Crates.io")
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.18-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/ssg "Lib.rs")
//! [![Lib.rs](https://img.shields.io/badge/lib.rs-v0.0.19-success.svg?style=for-the-badge&color=8A48FF&labelColor=6F36E4)](https://lib.rs/crates/ssg "Lib.rs")
//! [![License](https://img.shields.io/crates/l/ssg.svg?style=for-the-badge&color=007EC6&labelColor=03589B)](https://opensource.org/license/apache-2-0/ "MIT or Apache License, Version 2.0")
//! [![Rust](https://img.shields.io/badge/rust-f04041?style=for-the-badge&labelColor=c0282d&logo=rust)](https://www.rust-lang.org "Rust")
//!
Expand Down Expand Up @@ -66,7 +66,7 @@
//!
//! ```toml
//! [dependencies]
//! shokunin = "0.0.18"
//! shokunin = "0.0.19"
//! ```
//!
//! And in your `main.rs`:
Expand Down
8 changes: 8 additions & 0 deletions src/models/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ impl MetaTagGroups {
_ => None,
}
}
/// Returns true if all fields are empty.
pub fn is_empty(&self) -> bool {
self.apple.is_empty() &&
self.primary.is_empty() &&
self.og.is_empty() &&
self.ms.is_empty() &&
self.twitter.is_empty()
}
}

#[derive(
Expand Down
14 changes: 12 additions & 2 deletions src/modules/metatags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ type MetaDataMap = HashMap<String, String>;
pub fn generate_custom_meta_tags(mapping: &[(String, Option<String>)]) -> String {
let filtered_mapping: Vec<(String, String)> = mapping
.iter()
.filter_map(|(key, value)| value.as_ref().map(|v| (key.clone(), v.clone())))
.filter_map(|(key, value)| {
if let Some(val) = value.as_ref() {
if !val.is_empty() {
Some((key.clone(), val.clone()))
} else {
None
}
} else {
None
}
})
.collect();
generate_metatags(&filtered_mapping)
}
Expand Down Expand Up @@ -62,7 +72,7 @@ pub fn load_metatags(tag_names: &[&str], metadata: &MetaDataMap) -> String {
///
/// # Returns
/// A `String` containing the HTML representation of the meta tag.
fn format_meta_tag(key: &str, value: &str) -> String {
pub fn format_meta_tag(key: &str, value: &str) -> String {
format!("<meta name=\"{}\" content=\"{}\">", key, value)
}

Expand Down
4 changes: 2 additions & 2 deletions src/term/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn build() -> Result<ArgMatches, Error> {
.author("Sebastien Rousseau")
.about("")
.bin_name("ssg")
.version("0.0.18")
.version("0.0.19")
.arg(
Arg::new("new")
.help("Create a new project.")
Expand Down Expand Up @@ -109,7 +109,7 @@ pub fn build() -> Result<ArgMatches, Error> {
/// ```
pub fn print_banner() {
// Set the title and description for the CLI
let title = "Shokunin 🦀 (v0.0.18)";
let title = "Shokunin 🦀 (v0.0.19)";
let description =
"A Fast and Flexible Static Site Generator written in Rust";

Expand Down
24 changes: 24 additions & 0 deletions tests/test_cname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[cfg(test)]
mod tests {
use ssg::modules::cname::create_cname_data;
use std::collections::HashMap;

#[test]
fn test_create_cname_data_with_valid_cname() {
let mut metadata = HashMap::new();
metadata.insert("cname".to_string(), "example.com".to_string());

let cname_data = create_cname_data(&metadata);

assert_eq!(cname_data.cname, "example.com");
}

#[test]
fn test_create_cname_data_with_missing_cname() {
let metadata = HashMap::new(); // Empty metadata

let cname_data = create_cname_data(&metadata);

assert_eq!(cname_data.cname, "");
}
}
49 changes: 49 additions & 0 deletions tests/test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ mod tests {
assert_eq!(cname_data, expected_cname_data);
}

#[test]
fn test_cname_data_new() {
let cname_data = CnameData::new("example.com".to_string());
assert_eq!(cname_data.cname, "example.com");
}

#[test]
fn test_file_data_default() {
let file_data = FileData::default();
Expand All @@ -32,6 +38,13 @@ mod tests {
assert_eq!(file_data, expected_file_data);
}

#[test]
fn test_file_data_new() {
let file_data = FileData::new("file.txt".to_string(), "Content".to_string());
assert_eq!(file_data.name, "file.txt");
assert_eq!(file_data.content, "Content");
}

#[test]
fn test_icon_data_default() {
let icon_data = IconData::default();
Expand All @@ -44,6 +57,13 @@ mod tests {
assert_eq!(icon_data, expected_icon_data);
}

#[test]
fn test_icon_data_new() {
let icon_data = IconData::new("icon.png".to_string(), "32x32".to_string());
assert_eq!(icon_data.src, "icon.png");
assert_eq!(icon_data.sizes, "32x32");
}

#[test]
fn test_manifest_options_default() {
let manifest_options = ManifestData::default();
Expand All @@ -62,6 +82,21 @@ mod tests {
assert_eq!(manifest_options, expected_manifest_options);
}

#[test]
fn test_manifest_data_new() {
let manifest_data = ManifestData::new();
assert_eq!(manifest_data.background_color, "");
assert_eq!(manifest_data.description, "");
assert_eq!(manifest_data.display, "");
assert_eq!(manifest_data.icons, Vec::<IconData>::new());
assert_eq!(manifest_data.name, "");
assert_eq!(manifest_data.orientation, "");
assert_eq!(manifest_data.scope, "");
assert_eq!(manifest_data.short_name, "");
assert_eq!(manifest_data.start_url, "");
assert_eq!(manifest_data.theme_color, "");
}

#[test]
fn test_sitemap_data_default() {
let sitemap_data = SiteMapData::default();
Expand All @@ -73,6 +108,14 @@ mod tests {
assert_eq!(sitemap_data, expected_sitemap_data);
}

#[test]
fn test_sitemap_data_new() {
let sitemap_data = SiteMapData::new("example.com".to_string(), "2023-01-01".to_string(), "daily".to_string());
assert_eq!(sitemap_data.loc, "example.com");
assert_eq!(sitemap_data.lastmod, "2023-01-01");
assert_eq!(sitemap_data.changefreq, "daily");
}

#[test]
fn test_txt_data_default() {
let txt_data = TxtData::default();
Expand All @@ -81,4 +124,10 @@ mod tests {
};
assert_eq!(txt_data, expected_txt_data);
}

#[test]
fn test_txt_data_new() {
let txt_data = TxtData::new("example.com".to_string());
assert_eq!(txt_data.permalink, "example.com");
}
}
48 changes: 48 additions & 0 deletions tests/test_human.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#[cfg(test)]
mod tests {
use ssg::modules::human::create_human_data;
use std::collections::HashMap;

#[test]
fn test_create_human_data_with_all_fields() {
let mut metadata = HashMap::new();
metadata.insert("author_location".to_string(), "Location".to_string());
metadata.insert("author_twitter".to_string(), "@twitter_handle".to_string());
metadata.insert("author_website".to_string(), "https://example.com".to_string());
metadata.insert("author".to_string(), "John Doe".to_string());
metadata.insert("site_components".to_string(), "Components".to_string());
metadata.insert("site_last_updated".to_string(), "2023-01-01".to_string());
metadata.insert("site_software".to_string(), "Software".to_string());
metadata.insert("site_standards".to_string(), "Standards".to_string());
metadata.insert("thanks".to_string(), "Contributors".to_string());

let human_data = create_human_data(&metadata);

assert_eq!(human_data.author_location, "Location");
assert_eq!(human_data.author_twitter, "@twitter_handle");
assert_eq!(human_data.author_website, "https://example.com");
assert_eq!(human_data.author, "John Doe");
assert_eq!(human_data.site_components, "Components");
assert_eq!(human_data.site_last_updated, "2023-01-01");
assert_eq!(human_data.site_software, "Software");
assert_eq!(human_data.site_standards, "Standards");
assert_eq!(human_data.thanks, "Contributors");
}

#[test]
fn test_create_human_data_with_missing_fields() {
let metadata = HashMap::new(); // Empty metadata

let human_data = create_human_data(&metadata);

assert_eq!(human_data.author_location, "");
assert_eq!(human_data.author_twitter, "");
assert_eq!(human_data.author_website, "");
assert_eq!(human_data.author, "");
assert_eq!(human_data.site_components, "");
assert_eq!(human_data.site_last_updated, "");
assert_eq!(human_data.site_software, "");
assert_eq!(human_data.site_standards, "");
assert_eq!(human_data.thanks, "");
}
}
34 changes: 34 additions & 0 deletions tests/test_keywords.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#[cfg(test)]
mod tests {
use ssg::modules::keywords::extract_keywords;
use std::collections::HashMap;

#[test]
fn test_extract_keywords_with_valid_keywords() {
let mut metadata = HashMap::new();
metadata.insert("keywords".to_string(), "rust,programming,testing".to_string());

let keywords = extract_keywords(&metadata);

assert_eq!(keywords, vec!["rust", "programming", "testing"]);
}

#[test]
fn test_extract_keywords_with_missing_keywords() {
let metadata = HashMap::new(); // Empty metadata

let keywords = extract_keywords(&metadata);

assert_eq!(keywords, Vec::<String>::new());
}

#[test]
fn test_extract_keywords_with_whitespace() {
let mut metadata = HashMap::new();
metadata.insert("keywords".to_string(), " rust , programming , testing ".to_string());

let keywords = extract_keywords(&metadata);

assert_eq!(keywords, vec!["rust", "programming", "testing"]);
}
}
Loading

0 comments on commit 5e88664

Please sign in to comment.