This is a test project for Bard.
This was done because setting up a test even as an example was hard with the dependencies and other things. It may be doable, but the time required was not worth it.
This commit is contained in:
116
blog_test/src/main.rs
Normal file
116
blog_test/src/main.rs
Normal file
@ -0,0 +1,116 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
use axum::Router;
|
||||
#[cfg(feature = "server")]
|
||||
use axum::ServiceExt;
|
||||
#[cfg(feature = "server")]
|
||||
use axum::extract::{Extension, Host};
|
||||
#[cfg(feature = "server")]
|
||||
use axum::http::uri::{Parts, Uri};
|
||||
#[cfg(feature = "server")]
|
||||
use axum::http::StatusCode;
|
||||
#[cfg(feature = "server")]
|
||||
use axum::response::{IntoResponse, Redirect};
|
||||
#[cfg(feature = "server")]
|
||||
use axum::routing::get;
|
||||
|
||||
use bard::*;
|
||||
|
||||
|
||||
|
||||
const FAVICON: Asset = asset!("/assets/favicon.ico");
|
||||
|
||||
|
||||
|
||||
fn main()
|
||||
{
|
||||
#[cfg(feature = "server")]
|
||||
{
|
||||
tokio::runtime::Runtime::new()
|
||||
.unwrap()
|
||||
.block_on(async move { bard::init_database("/home/myrddin/cybermages/website/tavern.db").await });
|
||||
}
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
dioxus::launch(App);
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn App() -> Element
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
document::Link { rel: "icon", href: FAVICON }
|
||||
Router::<Page> {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Home page
|
||||
#[component]
|
||||
fn Home() -> Element
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
h1 { "Blog Test" }
|
||||
}
|
||||
}
|
||||
|
||||
/// This is the content for the About page.
|
||||
#[component]
|
||||
pub fn PageNotFound(route: Vec<String>) -> Element
|
||||
{
|
||||
rsx!
|
||||
{
|
||||
h1 { "Page not found" }
|
||||
p { "We are terribly sorry, but the page you requested doesn't exist." }
|
||||
pre { color: "red", "log:\nattemped to navigate to: {route:?}" }
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared navbar component.
|
||||
#[component]
|
||||
fn Navbar() -> Element
|
||||
{
|
||||
rsx! {
|
||||
div {
|
||||
id: "navbar",
|
||||
Link {
|
||||
to: Page::Home {},
|
||||
"Home"
|
||||
}
|
||||
Link {
|
||||
to: Page::Bard{ child: bard::Page::Blog { tag: String::from("all") }},
|
||||
"Blog"
|
||||
}
|
||||
//a { href: "/blog/all", "Blog" }
|
||||
}
|
||||
|
||||
Outlet::<Page> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Routable, PartialEq)]
|
||||
#[rustfmt::skip]
|
||||
pub enum Page
|
||||
{
|
||||
#[layout(Navbar)]
|
||||
#[route("/")]
|
||||
Home {},
|
||||
|
||||
// #[nest("/blog")]
|
||||
#[child("/blog")]
|
||||
Bard
|
||||
{
|
||||
child: bard::Page
|
||||
},
|
||||
// #[end_nest]
|
||||
|
||||
#[route("/:..route")]
|
||||
PageNotFound { route: Vec<String> }
|
||||
}
|
||||
Reference in New Issue
Block a user