1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use super::*;

#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(default)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "unstable", serde(deny_unknown_fields))]
#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
pub struct Collection {
    pub title: Option<liquid_core::model::KString>,
    pub description: Option<liquid_core::model::KString>,
    pub dir: Option<crate::RelPath>,
    pub drafts_dir: Option<crate::RelPath>,
    pub order: SortOrder,
    pub rss: Option<crate::RelPath>,
    pub jsonfeed: Option<crate::RelPath>,
    pub publish_date_in_filename: bool,
    pub default: Frontmatter,
}

impl From<PostCollection> for Collection {
    fn from(other: PostCollection) -> Collection {
        let PostCollection {
            title,
            description,
            dir,
            drafts_dir,
            order,
            rss,
            jsonfeed,
            publish_date_in_filename,
            default,
        } = other;
        Self {
            title,
            description,
            dir: Some(dir),
            drafts_dir,
            order,
            rss,
            jsonfeed,
            publish_date_in_filename,
            default,
        }
    }
}

impl From<PageCollection> for Collection {
    fn from(other: PageCollection) -> Collection {
        let PageCollection { default } = other;
        // By default, Disable excerpts
        let default = default.merge(&Frontmatter {
            excerpt_separator: Some("".into()),
            ..Default::default()
        });
        Self {
            default,
            dir: Some(crate::RelPath::new()),
            order: SortOrder::None,
            ..Default::default()
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)]
#[serde(default)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "unstable", serde(deny_unknown_fields))]
#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
pub struct PageCollection {
    pub default: Frontmatter,
}

#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(default)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(feature = "unstable", serde(deny_unknown_fields))]
#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
pub struct PostCollection {
    pub title: Option<liquid_core::model::KString>,
    pub description: Option<liquid_core::model::KString>,
    pub dir: crate::RelPath,
    pub drafts_dir: Option<crate::RelPath>,
    pub order: SortOrder,
    pub rss: Option<crate::RelPath>,
    pub jsonfeed: Option<crate::RelPath>,
    pub publish_date_in_filename: bool,
    pub default: Frontmatter,
}

impl Default for PostCollection {
    fn default() -> Self {
        Self {
            title: Default::default(),
            description: Default::default(),
            dir: crate::RelPath::from_unchecked("posts"),
            drafts_dir: Default::default(),
            order: Default::default(),
            rss: Default::default(),
            jsonfeed: Default::default(),
            publish_date_in_filename: true,
            default: Default::default(),
        }
    }
}

#[derive(Debug, Eq, PartialEq, Hash, Copy, Clone, serde::Serialize, serde::Deserialize)]
#[cfg_attr(feature = "preview_unstable", serde(rename_all = "snake_case"))]
#[cfg_attr(feature = "unstable", serde(deny_unknown_fields))]
#[cfg_attr(not(feature = "unstable"), non_exhaustive)]
#[derive(Default)]
pub enum SortOrder {
    None,
    Asc,
    #[default]
    Desc,
    #[cfg(not(feature = "unstable"))]
    #[doc(hidden)]
    #[serde(other)]
    Unknown,
}