diff options
author | Kaiden Fey <kookie@spacekookie.de> | 2020-10-25 05:36:08 +0100 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2020-10-25 05:36:08 +0100 |
commit | 63cd5d0a8d3f77c0267f12a6aef52533cc2f7d09 (patch) | |
tree | d46fb6058a6ade2726154fff76d5bda1d6dfc7e0 /src | |
parent | 392444d21101ce7b637f2e5a385490605f93ccf1 (diff) |
Adding a whole lot of shit (octopus and supergit)
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 10 | ||||
-rw-r--r-- | src/pages/files.rs | 20 | ||||
-rw-r--r-- | src/pages/mod.rs | 38 | ||||
-rw-r--r-- | src/pages/overview.rs | 24 | ||||
-rw-r--r-- | src/templ_data/files.rs | 13 | ||||
-rw-r--r-- | src/templ_data/mod.rs | 18 | ||||
-rw-r--r-- | src/templ_data/overview.rs | 11 |
7 files changed, 90 insertions, 44 deletions
diff --git a/src/main.rs b/src/main.rs index 92e1bc7..8ed6445 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -mod git; +//mod git; mod pages; mod repo; mod templ_data; @@ -19,12 +19,8 @@ async fn main() -> io::Result<()> { HttpServer::new(move || { App::new() .service(fs::Files::new("/static", root.join("static"))) - // This is a bit of a hack so that people don't get the - // 404 on the root page. Especially as long as octopus - // doesn't have the account overview yet! - .service(web::resource("/").route(web::get().to(pages::index))) - .service(web::resource("/{repo}").route(web::get().to(pages::repo::about))) - .service(web::resource("/{repo}/details").route(web::get().to(pages::repo::details))) + .service(web::resource("/").route(web::get().to(pages::overview))) + .service(web::resource("/tree").route(web::get().to(pages::files))) .default_service(web::resource("").route(web::get().to(pages::p404))) }) .bind("127.0.0.1:8080")? diff --git a/src/pages/files.rs b/src/pages/files.rs new file mode 100644 index 0000000..73a86a4 --- /dev/null +++ b/src/pages/files.rs @@ -0,0 +1,20 @@ +//! The main file browser + +use crate::templ_data::{files::Files, BaseData}; +use actix_web::{web, HttpRequest, HttpResponse, Result}; +use askama::Template; + +pub async fn render(req: HttpRequest) -> Result<HttpResponse> { + let files = Files { + base: BaseData { + sitename: "dev.spacekookie.de".into(), + ..BaseData::default() + }, + readme: None, + path: "".into(), + } + .render() + .unwrap(); + + Ok(HttpResponse::Ok().content_type("text/html").body(files)) +} diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 5689af7..2f1ed57 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -3,39 +3,13 @@ //! 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; +// pub mod repo; + +mod overview; +pub use overview::render as overview; 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)) -} +mod files; +pub use files::render as files; diff --git a/src/pages/overview.rs b/src/pages/overview.rs new file mode 100644 index 0000000..ca8c9b3 --- /dev/null +++ b/src/pages/overview.rs @@ -0,0 +1,24 @@ +//! Overview page +//! +//! This is the first page a user sees when they just go to the site +//! root. It renders the `README`, or `README.md` file from the modo +//! repo root, to provide users with a starting point. + +use crate::templ_data::{overview::Index, BaseData}; +use actix_web::{web, HttpRequest, HttpResponse, Result}; +use askama::Template; + +pub async fn render(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(), + ..BaseData::default() + }, + readme, + } + .render() + .unwrap(); + Ok(HttpResponse::Ok().content_type("text/html").body(index)) +} diff --git a/src/templ_data/files.rs b/src/templ_data/files.rs new file mode 100644 index 0000000..27a5bde --- /dev/null +++ b/src/templ_data/files.rs @@ -0,0 +1,13 @@ +//! File browser template data + +use super::BaseData; +use askama::Template; + +// This struct needs escapng=none to render README files it encounters along the way +#[derive(Template)] +#[template(path = "files.html", escape = "none")] +pub(crate) struct Files { + pub base: BaseData, + pub path: String, + pub readme: Option<String>, +} diff --git a/src/templ_data/mod.rs b/src/templ_data/mod.rs index 6c93266..7645e95 100644 --- a/src/templ_data/mod.rs +++ b/src/templ_data/mod.rs @@ -10,21 +10,29 @@ //! `page` module, which then uses the appropriate template structures //! defined here. -pub(crate) mod repo; +pub(crate) mod overview; +pub(crate) mod files; + +use std::env; /// A basic application wide template structure pub(crate) struct BaseData { pub version: String, pub source: String, - pub url: String, + pub siteurl: String, + pub sitename: String, + pub has_wiki: bool, } impl Default for BaseData { fn default() -> Self { Self { - version: "0.2.0".into(), - source: "".into(), - url: "http://localhost:8080".into(), + version: env!("CARGO_PKG_VERSION").into(), + source: env::var("_OCTOPUS_SOURCE") + .unwrap_or("https://dev.spacekookie.de/web/octopus".to_string()), + siteurl: env::var("_OCTOPUS_SITE_URL").unwrap_or("localhost:8080".to_string()), + sitename: env::var("_OCTOPUS_SITE_NAME").unwrap_or("test-octopus".to_string()), + has_wiki: true, } } } diff --git a/src/templ_data/overview.rs b/src/templ_data/overview.rs new file mode 100644 index 0000000..693db0a --- /dev/null +++ b/src/templ_data/overview.rs @@ -0,0 +1,11 @@ +//! Template data for the main overview + +use super::BaseData; +use askama::Template; + +#[derive(Template)] +#[template(path = "index.html", escape = "none")] +pub(crate) struct Index { + pub base: BaseData, + pub readme: String, +} |