about summary refs log tree commit diff
path: root/kittybox-rs/templates/src/templates.rs
blob: 60daa55b239949d393a65ada9cf4408c7ddc9d02 (plain) (blame)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use http::StatusCode;
use kittybox_util::MicropubChannel;

use crate::{Feed, VCard};

markup::define! {
    Template<'a>(title: &'a str, blog_name: &'a str, feeds: Vec<MicropubChannel>, user: Option<String>, content: String) {
        @markup::doctype()
        html {
            head {
                title { @title }
                link[rel="preconnect", href="https://fonts.gstatic.com"];
                link[rel="stylesheet", href="/.kittybox/static/style.css"];
                meta[name="viewport", content="initial-scale=1, width=device-width"];

                link[rel="micropub", href="/.kittybox/micropub"];
                link[rel="micropub_media", href="/.kittybox/media"];
                link[rel="indieauth_metadata", href="/.kittybox/indieauth/metadata"];
                // legacy links for some dumb clients
                link[rel="authorization_endpoint", href="/.kittybox/indieauth/auth"];
                link[rel="token_endpoint", href="/.kittybox/indieauth/token"];
                /*@if let Some(endpoints) = endpoints {
                    @if let Some(webmention) = &endpoints.webmention {
                        link[rel="webmention", href=&webmention];
                    }
                    @if let Some(microsub) = &endpoints.microsub {
                        link[rel="microsub", href=&microsub];
                    }
                }*/
            }
            body {
                // TODO Somehow compress headerbar into a menu when the screen space is tight
                nav #headerbar {
                    ul {
                        li { a #homepage[href="/"] { @blog_name } }
                        @for feed in feeds.iter() {
                            li { a[href=&feed.uid] { @feed.name } }
                        }
                        li.shiftright {
                            @if user.is_none() {
                                a #login[href="/login"] { "Sign in" }
                            } else {
                                span {
                                    @user.as_ref().unwrap() " - " a #logout[href="/logout"] { "Sign out" }
                                }
                            }
                        }
                    }
                }
                main {
                    @markup::raw(content)
                }
                footer {
                    p {
                        "Powered by " a[href="https://sr.ht/~vikanezrimaya/kittybox"] {
                            "Kittybox"
                        }
                    }
                }
            }
        }
    }
    MainPage<'a>(feed: &'a serde_json::Value, card: &'a serde_json::Value) {
        .sidebyside {
            @VCard { card }
            #dynamicstuff {
                p { "This section will provide interesting statistics or tidbits about my life in this exact moment (with maybe a small delay)." }
                p { "It will probably require JavaScript to self-update, but I promise to keep this widget lightweight and open-source!" }
                p { small {
                    "JavaScript isn't a menace, stop fearing it or I will switch to WebAssembly "
                    "and knock your nico-nico-kneecaps so fast with its speed you won't even notice that... "
                    small { "omae ha mou shindeiru" }
                    @markup::raw("<!-- NANI?!!! -->")
                } }
            }
        }
        @Feed { feed }
    }
    ErrorPage(code: StatusCode, msg: Option<String>) {
        h1 { @format!("HTTP {}", code) }
        @match *code {
            StatusCode::UNAUTHORIZED => {
                p { "Looks like you need to authenticate yourself before seeing this page. Try logging in with IndieAuth using the Login button above!" }
            }
            StatusCode::FORBIDDEN => {
                p { "Looks like you're forbidden from viewing this page." }
                p {
                    "This might've been caused by being banned from viewing my website"
                    "or simply by trying to see what you're not supposed to see, "
                    "like a private post that's not intended for you. It's ok, it happens."
                }
            }
            StatusCode::GONE => {
                p { "Looks like the page you're trying to find is gone and is never coming back." }
            }
            StatusCode::UNAVAILABLE_FOR_LEGAL_REASONS => {
            p { "The page is there, but I can't legally provide it to you because the censorship said so." }
            }
            StatusCode::NOT_FOUND => {
                p { "Looks like there's no such page. Maybe you or someone else mistyped a URL or my database experienced data loss." }
            }
            StatusCode::IM_A_TEAPOT => {
                p { "Wait, do you seriously expect my website to brew you coffee? It's not a coffee machine!" }

                p {
                    small {
                        "I could brew you some coffee tho if we meet one day... "
                        small {
                            i {
                                "i-it's nothing personal, I just like brewing coffee, b-baka!!!~ >.<!"
                            }
                        }
                    }
                }
            }
            StatusCode::BAD_REQUEST => {
                @match msg {
                    None => {
                        p {
                            "There was an undescribed error in your request. "
                            "Please try again later or with a different request."
                        }
                    }
                    Some(msg) => {
                        p {
                            "There was a following error in your request:"
                        }
                        blockquote { pre { @msg } }
                    }
                }
            }
            StatusCode::INTERNAL_SERVER_ERROR => {
                @match msg {
                    None => {
                        p { "It seems like you have found an error. Not to worry, it has already been logged." }
                    }
                    Some(msg) => {
                        p { "The server encountered an error while processing your request:" }
                        blockquote { @msg }
                        p { "Don't worry, it has already been logged." }
                    }
                }
            }
            _ => {
                p { "It seems like you have found an error. Not to worry, it has already been logged." }
            }
        }
        P { "For now, may I suggest to visit " a[href="/"] {"the main page"} " of this website?" }

    }
}