Skip to content
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

Added support for multiple feeds (i.e. generating both Atom and RSS) #2477

Merged
merged 6 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Renamed MightBeSingle to SingleOrVec
  • Loading branch information
LunarEclipse363 committed Jun 17, 2024
commit e40ba5313684d7fdcd616be78dad0431f7f90b9d
4 changes: 2 additions & 2 deletions components/config/src/config/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use errors::{bail, Result};
use libs::unic_langid::LanguageIdentifier;
use serde::{Deserialize, Serialize};

use crate::config::might_be_single;
use crate::config::search;
use crate::config::single_or_vec;
use crate::config::taxonomies;

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
Expand All @@ -20,7 +20,7 @@ pub struct LanguageOptions {
pub generate_feeds: bool,
LunarEclipse363 marked this conversation as resolved.
Show resolved Hide resolved
/// 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 = "might_be_single")]
#[serde(alias = "feed_filename", deserialize_with = "single_or_vec")]
pub feed_filenames: Vec<String>,
LunarEclipse363 marked this conversation as resolved.
Show resolved Hide resolved
pub taxonomies: Vec<taxonomies::TaxonomyConfig>,
/// Whether to generate search index for that language, defaults to `false`
Expand Down
18 changes: 9 additions & 9 deletions components/config/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct Config {
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 = "might_be_single")]
#[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,
Expand Down Expand Up @@ -401,26 +401,26 @@ impl Default for Config {
}

/// Used for deserializing values that can be either a single value or a vec of values
pub(crate) fn might_be_single<'de, T, D>(deserializer: D) -> Result<Vec<T>, D::Error>
pub(crate) fn single_or_vec<'de, T, D>(deserializer: D) -> Result<Vec<T>, D::Error>
where
T: DeserializeOwned,
D: Deserializer<'de>,
{
let v = MightBeSingle::deserialize(deserializer)?;
let v = SingleOrVec::deserialize(deserializer)?;
Ok(v.into())
}

#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
#[serde(untagged)]
pub(crate) enum MightBeSingle<T> {
pub(crate) enum SingleOrVec<T> {
Multiple(Vec<T>),
One(T),
None,
}

impl<T> From<MightBeSingle<T>> for Vec<T> {
fn from(x: MightBeSingle<T>) -> Vec<T> {
use MightBeSingle::*;
impl<T> From<SingleOrVec<T>> for Vec<T> {
fn from(x: SingleOrVec<T>) -> Vec<T> {
use SingleOrVec::*;

match x {
Multiple(v) => v,
Expand All @@ -430,13 +430,13 @@ impl<T> From<MightBeSingle<T>> for Vec<T> {
}
}

impl<T> From<Vec<T>> for MightBeSingle<T> {
impl<T> From<Vec<T>> for SingleOrVec<T> {
fn from(value: Vec<T>) -> Self {
Self::Multiple(value)
}
}

impl<T> Default for MightBeSingle<T> {
impl<T> Default for SingleOrVec<T> {
fn default() -> Self {
Self::None
}
Expand Down