aboutsummaryrefslogtreecommitdiff
path: root/src/pages/mod.rs
blob: 5689af7f6ef7ecf68f4ee077586d158426ca328c (plain)
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
//! All the pages in webgit
//!
//! A page is defined by it's template type as well as it's route,
//! which is exported from the module and then called by the router

pub mod repo;

mod p404;
pub use p404::render as p404;

use actix_web::{web, HttpRequest, HttpResponse, Result};
use askama::Template;

pub(crate) struct BaseData {
    sitename: String,
    has_wiki: bool,
}

#[derive(Template)]
#[template(path = "index.html", escape = "none")]
pub(crate) struct Index {
    base: BaseData,
    readme: String,
}

pub async fn index(req: HttpRequest) -> Result<HttpResponse> {

    let readme: String = markdown::to_html(include_str!("../../fake-readme.md").into());
    
    let index = Index {
        base: BaseData {
            sitename: "dev.spacekookie.de".into(),
            has_wiki: true,
        },
        readme
        
    }
    .render()
    .unwrap();
    Ok(HttpResponse::Ok().content_type("text/html").body(index))
}