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:
7
blog_test/.gitignore
vendored
Normal file
7
blog_test/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
/target
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
30
blog_test/Cargo.toml
Normal file
30
blog_test/Cargo.toml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[package]
|
||||||
|
name = "blog_test"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Myrddin Dundragon <myrddin@cybermages.tech>"]
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
axum = { version = "0.7.0", optional = true }
|
||||||
|
axum-server = { version = "0.7.1", optional = true }
|
||||||
|
dioxus = { version = "*", features = ["router", "fullstack"] }
|
||||||
|
dioxus-cli-config = { version = "*", optional = true }
|
||||||
|
bard = { version = "*", path="../bard", optional = true }
|
||||||
|
tokio = { version = "1.0", optional = true }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["web"]
|
||||||
|
web = ["dioxus/web", "bard"]
|
||||||
|
server = ["dioxus/server", "axum", "axum-server", "tokio/rt-multi-thread", "tokio/macros", "dioxus-cli-config", "bard/server"]
|
||||||
|
|
||||||
|
[profile.wasm-dev]
|
||||||
|
inherits = "dev"
|
||||||
|
opt-level = 1
|
||||||
|
|
||||||
|
[profile.server-dev]
|
||||||
|
inherits = "dev"
|
||||||
|
|
||||||
|
[profile.android-dev]
|
||||||
|
inherits = "dev"
|
||||||
21
blog_test/Dioxus.toml
Normal file
21
blog_test/Dioxus.toml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[application]
|
||||||
|
|
||||||
|
[web.app]
|
||||||
|
|
||||||
|
# HTML title tag content
|
||||||
|
title = "blog_test"
|
||||||
|
|
||||||
|
# include `assets` in web platform
|
||||||
|
[web.resource]
|
||||||
|
|
||||||
|
# Additional CSS style files
|
||||||
|
style = []
|
||||||
|
|
||||||
|
# Additional JavaScript files
|
||||||
|
script = []
|
||||||
|
|
||||||
|
[web.resource.dev]
|
||||||
|
|
||||||
|
# Javascript code file
|
||||||
|
# serve: [dev-server] only
|
||||||
|
script = []
|
||||||
25
blog_test/README.md
Normal file
25
blog_test/README.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Development
|
||||||
|
|
||||||
|
Your new bare-bones project includes minimal organization with a single `main.rs` file and a few assets.
|
||||||
|
|
||||||
|
```
|
||||||
|
project/
|
||||||
|
├─ assets/ # Any assets that are used by the app should be placed here
|
||||||
|
├─ src/
|
||||||
|
│ ├─ main.rs # main.rs is the entry point to your application and currently contains all components for the app
|
||||||
|
├─ Cargo.toml # The Cargo.toml file defines the dependencies and feature flags for your project
|
||||||
|
```
|
||||||
|
|
||||||
|
### Serving Your App
|
||||||
|
|
||||||
|
Run the following command in the root of your project to start developing with the default platform:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dx serve --platform web
|
||||||
|
```
|
||||||
|
|
||||||
|
To run for a different platform, use the `--platform platform` flag. E.g.
|
||||||
|
```bash
|
||||||
|
dx serve --platform desktop
|
||||||
|
```
|
||||||
|
|
||||||
BIN
blog_test/assets/favicon.ico
Normal file
BIN
blog_test/assets/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
20
blog_test/assets/header.svg
Normal file
20
blog_test/assets/header.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 23 KiB |
107
blog_test/assets/main.css
Normal file
107
blog_test/assets/main.css
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/* App-wide styling */
|
||||||
|
body {
|
||||||
|
background-color: #0f1116;
|
||||||
|
color: #ffffff;
|
||||||
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#hero {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#links {
|
||||||
|
width: 400px;
|
||||||
|
text-align: left;
|
||||||
|
font-size: x-large;
|
||||||
|
color: white;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
#links a {
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
margin-top: 20px;
|
||||||
|
margin: 10px 0px;
|
||||||
|
border: white 1px solid;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#links a:hover {
|
||||||
|
background-color: #1f1f1f;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#header {
|
||||||
|
max-width: 1200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Navbar */
|
||||||
|
#navbar {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navbar a {
|
||||||
|
color: #ffffff;
|
||||||
|
margin-right: 20px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: color 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#navbar a:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
color: #91a4d2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Blog page */
|
||||||
|
#blog {
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#blog a {
|
||||||
|
color: #ffffff;
|
||||||
|
margin-top: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Echo */
|
||||||
|
#echo {
|
||||||
|
width: 360px;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
margin-top: 50px;
|
||||||
|
background-color: #1e222d;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#echo>h4 {
|
||||||
|
margin: 0px 0px 15px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#echo>input {
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px white solid;
|
||||||
|
background-color: transparent;
|
||||||
|
color: #ffffff;
|
||||||
|
transition: border-bottom-color 0.2s ease;
|
||||||
|
outline: none;
|
||||||
|
display: block;
|
||||||
|
padding: 0px 0px 5px 0px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#echo>input:focus {
|
||||||
|
border-bottom-color: #6d85c6;
|
||||||
|
}
|
||||||
|
|
||||||
|
#echo>p {
|
||||||
|
margin: 20px 0px 0px auto;
|
||||||
|
}
|
||||||
8
blog_test/clippy.toml
Normal file
8
blog_test/clippy.toml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
await-holding-invalid-types = [
|
||||||
|
"generational_box::GenerationalRef",
|
||||||
|
{ path = "generational_box::GenerationalRef", reason = "Reads should not be held over an await point. This will cause any writes to fail while the await is pending since the read borrow is still active." },
|
||||||
|
"generational_box::GenerationalRefMut",
|
||||||
|
{ path = "generational_box::GenerationalRefMut", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." },
|
||||||
|
"dioxus_signals::Write",
|
||||||
|
{ path = "dioxus_signals::Write", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." },
|
||||||
|
]
|
||||||
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