Skip to content

Commit

Permalink
Rename no_robots and no_sitemap into generate_robots_txt and generate…
Browse files Browse the repository at this point in the history
…_sitemap (default to true)
  • Loading branch information
Bromind committed Jul 21, 2024
1 parent 7834870 commit 63ef902
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
64 changes: 49 additions & 15 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ pub struct Config {
/// All user params set in `[extra]` in the config
pub extra: HashMap<String, Toml>,
/// Disable the generation of Sitemap.xml
pub no_sitemap: bool,
pub generate_sitemap: bool,
/// Disable the generation of robots.txt
pub no_robots: bool,
pub generate_robots_txt: bool,
}

#[derive(Serialize)]
Expand All @@ -121,8 +121,8 @@ pub struct SerializedConfig<'a> {
extra: &'a HashMap<String, Toml>,
markdown: &'a markup::Markdown,
search: search::SerializedSearch<'a>,
no_sitemap: bool,
no_robots: bool,
generate_sitemap: bool,
generate_robots_txt: bool,
}

impl Config {
Expand Down Expand Up @@ -338,8 +338,8 @@ impl Config {
extra: &self.extra,
markdown: &self.markdown,
search: self.search.serialize(),
no_sitemap: self.no_sitemap,
no_robots: self.no_robots,
generate_sitemap: self.generate_sitemap,
generate_robots_txt: self.generate_robots_txt,
}
}
}
Expand Down Expand Up @@ -403,8 +403,8 @@ impl Default for Config {
search: search::Search::default(),
markdown: markup::Markdown::default(),
extra: HashMap::new(),
no_sitemap: false,
no_robots: false,
generate_sitemap: true,
generate_robots_txt: true,
}
}
}
Expand Down Expand Up @@ -1004,33 +1004,67 @@ feed_filename = "test.xml"
}

#[test]
fn parse_no_sitemap() {
fn parse_generate_sitemap_true() {
let config = r#"
title = "My Site"
base_url = "example.com"
no_sitemap = true
generate_sitemap = true
"#;
let config = Config::parse(config).unwrap();
assert!(config.no_sitemap);
assert!(config.generate_sitemap);
}

#[test]
fn default_no_sitemap_false() {
fn parse_generate_sitemap_false() {
let config = r#"
title = "My Site"
base_url = "example.com"
generate_sitemap = false
"#;
let config = Config::parse(config).unwrap();
assert!(!config.no_sitemap);
assert!(!config.generate_sitemap);
}

#[test]
fn default_no_robots_false() {
fn default_no_sitemap_true() {
let config = r#"
title = "My Site"
base_url = "example.com"
"#;
let config = Config::parse(config).unwrap();
assert!(!config.no_robots);
assert!(config.generate_sitemap);
}

#[test]
fn parse_generate_robots_true() {
let config = r#"
title = "My Site"
base_url = "example.com"
generate_robots_txt = true
"#;
let config = Config::parse(config).unwrap();
assert!(config.generate_robots_txt);
}

#[test]
fn parse_generate_robots_false() {
let config = r#"
title = "My Site"
base_url = "example.com"
generate_robots_txt = false
"#;
let config = Config::parse(config).unwrap();
assert!(!config.generate_robots_txt);
}


#[test]
fn default_no_robots_true() {
let config = r#"
title = "My Site"
base_url = "example.com"
"#;
let config = Config::parse(config).unwrap();
assert!(config.generate_robots_txt);
}
}
4 changes: 2 additions & 2 deletions components/site/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ impl Site {
start = log_time(start, "Rendered sections");
self.render_orphan_pages()?;
start = log_time(start, "Rendered orphan pages");
if !self.config.no_sitemap {
if self.config.generate_sitemap{
self.render_sitemap()?;
start = log_time(start, "Rendered sitemap");
}
Expand Down Expand Up @@ -771,7 +771,7 @@ impl Site {
start = log_time(start, "Rendered themes css");
self.render_404()?;
start = log_time(start, "Rendered 404");
if !self.config.no_robots {
if self.config.generate_robots_txt {
self.render_robots()?;
start = log_time(start, "Rendered robots.txt");
}
Expand Down
8 changes: 4 additions & 4 deletions docs/content/documentation/getting-started/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ taxonomies = []
# content for `default_language`.
build_search_index = false

# When set to "true", Sitemap.xml is not generated (default: false)
no_sitemap = false
# When set to "false", Sitemap.xml is not generated (default: true)
generate_sitemap = false

# When set to "true", robots.txt is not generated (default: false)
no_robots = false
# When set to "false", robots.txt is not generated (default: true)
generate_robots_txt = false

# Configuration of the Markdown rendering
[markdown]
Expand Down

0 comments on commit 63ef902

Please sign in to comment.