forked from getzola/zola
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made the multiple feeds config changes "loudly" backwards-incompatible
- Loading branch information
1 parent
ff92ecd
commit fae17a5
Showing
5 changed files
with
47 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,7 @@ use std::path::{Path, PathBuf}; | |
|
||
use libs::globset::GlobSet; | ||
use libs::toml::Value as Toml; | ||
use serde::de::DeserializeOwned; | ||
use serde::{Deserialize, Deserializer, Serialize}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::theme::Theme; | ||
use errors::{anyhow, bail, Result}; | ||
|
@@ -31,7 +30,7 @@ pub enum Mode { | |
} | ||
|
||
#[derive(Clone, Debug, Deserialize)] | ||
#[serde(default)] | ||
#[serde(default, deny_unknown_fields)] | ||
pub struct Config { | ||
/// Base URL of the site, the only required config argument | ||
pub base_url: String, | ||
|
@@ -51,13 +50,11 @@ pub struct Config { | |
translations: HashMap<String, String>, | ||
|
||
/// Whether to generate feeds. Defaults to false. | ||
#[serde(alias = "generate_feed")] | ||
pub generate_feeds: bool, | ||
/// The number of articles to include in the feed. Defaults to including all items. | ||
pub feed_limit: Option<usize>, | ||
/// The filenames to use for feeds. Used to find the templates, too. | ||
/// Defaults to ["atom.xml"], with "rss.xml" also having a template provided out of the box. | ||
#[serde(alias = "feed_filename", deserialize_with = "single_or_vec")] | ||
pub feed_filenames: Vec<String>, | ||
/// If set, files from static/ will be hardlinked instead of copied to the output dir. | ||
pub hard_link_static: bool, | ||
|
@@ -400,48 +397,6 @@ impl Default for Config { | |
} | ||
} | ||
|
||
/// Used for deserializing values that can be either a single value or a vec of values | ||
pub(crate) fn single_or_vec<'de, T, D>(deserializer: D) -> Result<Vec<T>, D::Error> | ||
where | ||
T: DeserializeOwned, | ||
D: Deserializer<'de>, | ||
{ | ||
let v = SingleOrVec::deserialize(deserializer)?; | ||
Ok(v.into()) | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)] | ||
#[serde(untagged)] | ||
pub(crate) enum SingleOrVec<T> { | ||
Multiple(Vec<T>), | ||
One(T), | ||
None, | ||
} | ||
|
||
impl<T> From<SingleOrVec<T>> for Vec<T> { | ||
fn from(x: SingleOrVec<T>) -> Vec<T> { | ||
use SingleOrVec::*; | ||
|
||
match x { | ||
Multiple(v) => v, | ||
One(v) => vec![v], | ||
None => vec![], | ||
} | ||
} | ||
} | ||
|
||
impl<T> From<Vec<T>> for SingleOrVec<T> { | ||
fn from(value: Vec<T>) -> Self { | ||
Self::Multiple(value) | ||
} | ||
} | ||
|
||
impl<T> Default for SingleOrVec<T> { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
@@ -1025,15 +980,14 @@ author = "[email protected] (Some Person)" | |
} | ||
|
||
#[test] | ||
fn test_backwards_compatibility_for_feeds() { | ||
#[should_panic] | ||
fn test_backwards_incompatibility_for_feeds() { | ||
let config = r#" | ||
base_url = "example.com" | ||
generate_feed = true | ||
feed_filename = "test.xml" | ||
"#; | ||
|
||
let config = Config::parse(config).unwrap(); | ||
assert_eq!(config.generate_feeds, true); | ||
assert_eq!(config.feed_filenames, vec!["test.xml".to_owned()]); | ||
Config::parse(config).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters