/ web / src / content / docs / router.rs
router.rs
  1  #[derive(
  2      Clone,
  3      Copy,
  4      dioxus_router::Routable,
  5      PartialEq,
  6      Eq,
  7      Hash,
  8      Debug,
  9      serde::Serialize,
 10      serde::Deserialize
 11  )]
 12  pub enum BookRoute {
 13      #[route("/#:section")]
 14      Index { section: IndexSection },
 15  }
 16  impl BookRoute {
 17      /// Get the markdown for a page by its ID
 18      pub const fn page_markdown(id: use_mdbook::mdbook_shared::PageId) -> &'static str {
 19          match id.0 {
 20              0usize => {
 21                  "# Introduction\n\nDocumentation is currently a work in progress.\n\nThe previous pages have been removed for now while the firmware and web app are still changing."
 22              }
 23              _ => panic!("Invalid page ID:"),
 24          }
 25      }
 26      pub fn sections(&self) -> &'static [use_mdbook::mdbook_shared::Section] {
 27          &self.page().sections
 28      }
 29      pub fn page(&self) -> &'static use_mdbook::mdbook_shared::Page<Self> {
 30          LAZY_BOOK.get_page(self)
 31      }
 32      pub fn page_id(&self) -> use_mdbook::mdbook_shared::PageId {
 33          match self {
 34              BookRoute::Index { .. } => use_mdbook::mdbook_shared::PageId(0usize),
 35          }
 36      }
 37  }
 38  impl Default for BookRoute {
 39      fn default() -> Self {
 40          BookRoute::Index {
 41              section: IndexSection::Empty,
 42          }
 43      }
 44  }
 45  pub static LAZY_BOOK: use_mdbook::Lazy<use_mdbook::mdbook_shared::MdBook<BookRoute>> = use_mdbook::Lazy::new(||
 46  {
 47      {
 48          let mut page_id_mapping = ::std::collections::HashMap::new();
 49          let mut pages = Vec::new();
 50          let __push_page_0: fn(_, _) = |
 51              _pages: &mut Vec<_>,
 52              _page_id_mapping: &mut std::collections::HashMap<_, _>|
 53          {
 54              _pages
 55                  .push((
 56                      0usize,
 57                      {
 58                          ::use_mdbook::mdbook_shared::Page {
 59                              title: "Introduction".to_string(),
 60                              url: BookRoute::Index {
 61                                  section: IndexSection::Empty,
 62                              },
 63                              segments: vec![],
 64                              sections: vec![
 65                                  ::use_mdbook::mdbook_shared::Section {
 66                                      title: "Introduction".to_string(),
 67                                      id: "introduction".to_string(),
 68                                      level: 1usize,
 69                                  },
 70                              ],
 71                              raw: String::new(),
 72                              id: ::use_mdbook::mdbook_shared::PageId(0usize),
 73                          }
 74                      },
 75                  ));
 76              _page_id_mapping
 77                  .insert(
 78                      BookRoute::Index {
 79                          section: IndexSection::Empty,
 80                      },
 81                      ::use_mdbook::mdbook_shared::PageId(0usize),
 82                  );
 83          };
 84          __push_page_0(&mut pages, &mut page_id_mapping);
 85          ::use_mdbook::mdbook_shared::MdBook {
 86              summary: ::use_mdbook::mdbook_shared::Summary {
 87                  title: Some("Summary".to_string()),
 88                  prefix_chapters: vec![],
 89                  numbered_chapters: vec![
 90                      ::use_mdbook::mdbook_shared::SummaryItem::Link(::use_mdbook::mdbook_shared::Link {
 91                          name: "Introduction".to_string(),
 92                          location: Some(BookRoute::Index {
 93                              section: IndexSection::Empty,
 94                          }),
 95                          number: Some(
 96                              ::use_mdbook::mdbook_shared::SectionNumber(vec![1u32]),
 97                          ),
 98                          nested_items: vec![],
 99                      }),
100                  ],
101                  suffix_chapters: vec![],
102              },
103              pages: pages.into_iter().collect(),
104              page_id_mapping,
105          }
106      }
107  });
108  #[derive(
109      Clone,
110      Copy,
111      PartialEq,
112      Eq,
113      Hash,
114      Debug,
115      Default,
116      serde::Serialize,
117      serde::Deserialize
118  )]
119  pub enum IndexSection {
120      #[default]
121      Empty,
122      Introduction,
123  }
124  impl std::str::FromStr for IndexSection {
125      type Err = &'static str;
126      fn from_str(s: &str) -> Result<Self, Self::Err> {
127          match s {
128              "" => Ok(Self::Empty),
129              "introduction" => Ok(Self::Introduction),
130              _ => Err("Invalid section name. Expected one of IndexSectionintroduction"),
131          }
132      }
133  }
134  impl std::fmt::Display for IndexSection {
135      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136          match self {
137              Self::Empty => f.write_str(""),
138              Self::Introduction => f.write_str("introduction"),
139          }
140      }
141  }
142  #[component(no_case_check)]
143  pub fn Index(section: IndexSection) -> Element {
144      rsx! {
145          h1 { id : "introduction", Link { to : BookRoute::Index { section :
146          IndexSection::Introduction, }, class : "header", "Introduction" } } p {
147          "Documentation is currently a work in progress." } p {
148          "The previous pages have been removed for now while the firmware and web app are still changing."
149          }
150      }
151  }
152  
153  use super::*;