gazetta_core/view/
page.rs1use std::fmt;
18use std::ops::Deref;
19
20use crate::model::DateTime;
21use crate::model::Entry;
22use crate::render::Gazetta;
23
24use super::Index;
25
26pub struct BasePage<'a, G>
28where
29 G: Gazetta + 'a,
30 G::PageMeta: 'a,
31 G::SiteMeta: 'a,
32{
33 pub title: &'a str,
35
36 pub description: Option<&'a str>,
38
39 pub date: Option<&'a DateTime>,
41
42 pub updated: &'a DateTime,
45
46 pub href: &'a str,
48
49 pub meta: &'a G::PageMeta,
51
52 pub content: Content<'a>,
62}
63
64impl<'a, G> BasePage<'a, G>
65where
66 G: Gazetta + 'a,
67 G::PageMeta: 'a,
68 G::SiteMeta: 'a,
69{
70 pub fn for_entry(entry: &'a Entry<G::PageMeta>) -> Self {
72 BasePage {
73 title: &entry.title,
74 date: entry.date.as_ref(),
75 updated: &entry.updated,
76 description: entry.description.as_deref(),
77 content: Content {
78 data: &entry.content,
79 format: &entry.format,
80 },
81 href: &entry.name,
82 meta: &entry.meta,
83 }
84 }
85}
86
87impl<'a, G> Deref for BasePage<'a, G>
88where
89 G: Gazetta + 'a,
90 G::PageMeta: 'a,
91 G::SiteMeta: 'a,
92{
93 type Target = G::PageMeta;
94 fn deref(&self) -> &Self::Target {
95 self.meta
96 }
97}
98
99pub struct Page<'a, G>
101where
102 G: Gazetta + 'a,
103 G::PageMeta: 'a,
104 G::SiteMeta: 'a,
105{
106 pub base: BasePage<'a, G>,
108
109 pub index: Option<Index<'a, G>>,
111
112 pub references: &'a [BasePage<'a, G>],
115}
116
117impl<'a, G> Deref for Page<'a, G>
118where
119 G: Gazetta + 'a,
120 G::PageMeta: 'a,
121 G::SiteMeta: 'a,
122{
123 type Target = BasePage<'a, G>;
124
125 fn deref(&self) -> &Self::Target {
126 &self.base
127 }
128}
129
130#[derive(Copy, Clone, Debug)]
131pub struct Content<'a> {
132 pub data: &'a str,
133 pub format: &'a str,
134}
135
136impl<'a, G> Copy for BasePage<'a, G>
139where
140 G: Gazetta + 'a,
141 G::PageMeta: 'a,
142 G::SiteMeta: 'a,
143{
144}
145
146impl<'a, G> Clone for BasePage<'a, G>
147where
148 G: Gazetta + 'a,
149 G::PageMeta: 'a,
150 G::SiteMeta: 'a,
151{
152 fn clone(&self) -> Self {
153 *self
154 }
155}
156
157impl<'a, G> Copy for Page<'a, G>
158where
159 G: Gazetta + 'a,
160 G::PageMeta: 'a,
161 G::SiteMeta: 'a,
162{
163}
164
165impl<'a, G> Clone for Page<'a, G>
166where
167 G: Gazetta + 'a,
168 G::PageMeta: 'a,
169 G::SiteMeta: 'a,
170{
171 fn clone(&self) -> Self {
172 *self
173 }
174}
175
176impl<'a, G> fmt::Debug for Page<'a, G>
177where
178 G: Gazetta + 'a,
179 G::PageMeta: fmt::Debug + 'a,
180 G::SiteMeta: 'a,
181{
182 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
183 f.debug_struct("Page")
184 .field("title", &self.title)
185 .field("date", &self.date)
186 .field("href", &self.href)
187 .field("index", &self.index)
188 .field("meta", &self.meta)
189 .field("content", &self.content)
190 .finish()
191 }
192}