-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ Support SSR for document website.
- Loading branch information
Showing
7 changed files
with
115 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use anyhow::Result; | ||
use std::str::FromStr; | ||
|
||
use hikari_boot::Application; | ||
use hikari_theme::types::ComponentType; | ||
use hikari_website::app::{App, AppStates, PageData}; | ||
|
||
pub async fn html(id: String) -> Result<String> { | ||
App::render_to_string( | ||
format!("/component/{}", id), | ||
AppStates { | ||
theme: Default::default(), | ||
data: PageData::Component(ComponentType::from_str(&id)?), | ||
}, | ||
) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use anyhow::Result; | ||
|
||
use hikari_boot::Application; | ||
use hikari_website::app::{App, AppStates, PageData}; | ||
|
||
pub async fn html(id: String) -> Result<String> { | ||
App::render_to_string( | ||
format!("/guide/{}", id), | ||
AppStates { | ||
theme: Default::default(), | ||
data: PageData::Guide { | ||
id, | ||
raw: "いいよ!こいよ".to_string(), | ||
}, | ||
}, | ||
) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
pub mod component; | ||
pub mod guide; | ||
pub mod portal; | ||
|
||
use anyhow::Result; | ||
|
||
use axum::{ | ||
extract::Path, | ||
http::{header, HeaderMap, StatusCode}, | ||
routing::get, | ||
Router, | ||
}; | ||
|
||
use crate::pages; | ||
|
||
pub async fn route() -> Result<Router> { | ||
let router = Router::new() | ||
.route( | ||
"/", | ||
get(|| async { | ||
pages::portal::html() | ||
.await | ||
.map(|raw| { | ||
let mut headers = HeaderMap::new(); | ||
headers.insert(header::CONTENT_TYPE, "text/html".parse().unwrap()); | ||
|
||
(headers, raw) | ||
}) | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())) | ||
}), | ||
) | ||
.route( | ||
"/guide/:id", | ||
get(move |Path(id): Path<String>| async move { | ||
pages::guide::html(id) | ||
.await | ||
.map(|raw| { | ||
let mut headers = HeaderMap::new(); | ||
headers.insert(header::CONTENT_TYPE, "text/html".parse().unwrap()); | ||
|
||
(headers, raw) | ||
}) | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())) | ||
}), | ||
) | ||
.route( | ||
"/component/*id", | ||
get(move |Path(id): Path<String>| async move { | ||
pages::component::html(id) | ||
.await | ||
.map(|raw| { | ||
let mut headers = HeaderMap::new(); | ||
headers.insert(header::CONTENT_TYPE, "text/html".parse().unwrap()); | ||
|
||
(headers, raw) | ||
}) | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string())) | ||
}), | ||
); | ||
|
||
Ok(router) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use anyhow::Result; | ||
|
||
use hikari_boot::Application; | ||
use hikari_website::app::{App, AppStates, PageData}; | ||
|
||
pub async fn html() -> Result<String> { | ||
App::render_to_string( | ||
"/".to_string(), | ||
AppStates { | ||
theme: Default::default(), | ||
data: PageData::Portal, | ||
}, | ||
) | ||
.await | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters