atproto blogging
1use crate::components::ENTRY_CSS;
2use crate::components::css::DefaultNotebookCss;
3use dioxus::prelude::*;
4use weaver_renderer::atproto::ClientWriter;
5
6const ABOUT_MD: &str = include_str!("../../assets/about.md");
7const TERMS_MD: &str = include_str!("../../assets/terms.md");
8const PRIVACY_MD: &str = include_str!("../../assets/privacy.md");
9
10fn render_markdown(content: &str) -> String {
11 let parser = markdown_weaver::Parser::new_ext(content, weaver_renderer::default_md_options())
12 .into_offset_iter();
13 let mut html = String::new();
14 let _ = ClientWriter::<_, _, ()>::new(parser, &mut html, content).run();
15 html
16}
17
18#[derive(Clone, Copy, PartialEq)]
19pub enum StaticPageKind {
20 About,
21 Terms,
22 Privacy,
23}
24
25impl StaticPageKind {
26 fn content(&self) -> &'static str {
27 match self {
28 StaticPageKind::About => ABOUT_MD,
29 StaticPageKind::Terms => TERMS_MD,
30 StaticPageKind::Privacy => PRIVACY_MD,
31 }
32 }
33
34 fn title(&self) -> &'static str {
35 match self {
36 StaticPageKind::About => "About",
37 StaticPageKind::Terms => "Terms of Service",
38 StaticPageKind::Privacy => "Privacy Policy",
39 }
40 }
41}
42
43#[component]
44pub fn StaticPage(kind: StaticPageKind) -> Element {
45 let html = render_markdown(kind.content());
46
47 rsx! {
48 DefaultNotebookCss {}
49 document::Link { rel: "stylesheet", href: ENTRY_CSS }
50 document::Title { "{kind.title()} - Weaver" }
51
52 div { class: "static-page",
53 article { class: "entry notebook-content",
54 dangerous_inner_html: "{html}"
55 }
56 }
57 }
58}
59
60#[component]
61pub fn AboutPage() -> Element {
62 rsx! { StaticPage { kind: StaticPageKind::About } }
63}
64
65#[component]
66pub fn TermsPage() -> Element {
67 rsx! { StaticPage { kind: StaticPageKind::Terms } }
68}
69
70#[component]
71pub fn PrivacyPage() -> Element {
72 rsx! { StaticPage { kind: StaticPageKind::Privacy } }
73}