dioxus_docs_kit/blog/
config.rs1use crate::blog::registry::BlogRegistry;
4use crate::config::ThemeConfig;
5use std::collections::HashMap;
6
7pub struct BlogConfig {
18 manifest_json: String,
19 content_map: HashMap<&'static str, &'static str>,
20 posts_per_page: usize,
21 date_format: String,
22 theme: Option<ThemeConfig>,
23}
24
25impl BlogConfig {
26 pub fn new(manifest_json: &str, content_map: HashMap<&'static str, &'static str>) -> Self {
28 Self {
29 manifest_json: manifest_json.to_string(),
30 content_map,
31 posts_per_page: 9,
32 date_format: "%B %d, %Y".to_string(),
33 theme: None,
34 }
35 }
36
37 pub fn with_posts_per_page(mut self, n: usize) -> Self {
39 self.posts_per_page = n;
40 self
41 }
42
43 pub fn with_date_format(mut self, fmt: &str) -> Self {
45 self.date_format = fmt.to_string();
46 self
47 }
48
49 pub fn with_theme(mut self, theme: &str) -> Self {
51 self.theme = Some(ThemeConfig {
52 default_theme: theme.to_string(),
53 toggle_themes: None,
54 storage_key: "docs-theme".to_string(),
55 });
56 self
57 }
58
59 pub fn with_theme_toggle(mut self, light: &str, dark: &str, default: &str) -> Self {
61 self.theme = Some(ThemeConfig {
62 default_theme: default.to_string(),
63 toggle_themes: Some((light.to_string(), dark.to_string())),
64 storage_key: "docs-theme".to_string(),
65 });
66 self
67 }
68
69 pub fn build(self) -> BlogRegistry {
71 BlogRegistry::from_config(self)
72 }
73
74 pub(crate) fn manifest_json(&self) -> &str {
75 &self.manifest_json
76 }
77
78 pub(crate) fn content_map(&self) -> &HashMap<&'static str, &'static str> {
79 &self.content_map
80 }
81
82 pub(crate) fn posts_per_page(&self) -> usize {
83 self.posts_per_page
84 }
85
86 pub(crate) fn date_format(&self) -> &str {
87 &self.date_format
88 }
89
90 pub(crate) fn theme_config(&self) -> Option<&ThemeConfig> {
91 self.theme.as_ref()
92 }
93}