From 4173da519322dd9b2001f29b57c494bffbccc39e Mon Sep 17 00:00:00 2001 From: Awstin Date: Sun, 17 Dec 2023 15:43:25 -0500 Subject: [PATCH] Adding base template and another page to the project --- assets/main.css | 20 +++++++++++++++++++- src/main.rs | 20 ++++++++++++++++---- templates/another-page.html | 8 ++++++++ templates/base.html | 20 ++++++++++++++++++++ templates/hello.html | 19 +++++++------------ 5 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 templates/another-page.html create mode 100644 templates/base.html diff --git a/assets/main.css b/assets/main.css index 89171ad..db19a20 100644 --- a/assets/main.css +++ b/assets/main.css @@ -44,7 +44,7 @@ html { -o-tab-size: 4; tab-size: 4; /* 3 */ - font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; + font-family: Inter var, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; /* 4 */ font-feature-settings: normal; /* 5 */ @@ -539,3 +539,21 @@ video { --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; } + +.block { + display: block; +} + +.font-bold { + font-weight: 700; +} + +.text-green-500 { + --tw-text-opacity: 1; + color: rgb(34 197 94 / var(--tw-text-opacity)); +} + +.text-indigo-500 { + --tw-text-opacity: 1; + color: rgb(99 102 241 / var(--tw-text-opacity)); +} diff --git a/src/main.rs b/src/main.rs index b558a3a..3f06e5f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,10 +23,13 @@ async fn main() -> anyhow::Result<()> { let assets_path = std::env::current_dir().unwrap(); let port = 8000_u16; let addr = std::net::SocketAddr::from(([0, 0, 0, 0], port)); - let router = Router::new().route("/", get(hello)).nest_service( - "/assets", - ServeDir::new(format!("{}/assets", assets_path.to_str().unwrap())), - ); + let router = Router::new() + .route("/", get(hello)) + .route("/another-page", get(another_page)) + .nest_service( + "/assets", + ServeDir::new(format!("{}/assets", assets_path.to_str().unwrap())), + ); info!("router initialized, now listening on port {}", port); axum::Server::bind(&addr) .serve(router.into_make_service()) @@ -66,3 +69,12 @@ where } } } + +async fn another_page() -> impl IntoResponse { + let template = AnotherPageTemplate {}; + HtmlTemplate(template) +} + +#[derive(Template)] +#[template(path = "another-page.html")] +struct AnotherPageTemplate; diff --git a/templates/another-page.html b/templates/another-page.html new file mode 100644 index 0000000..65892fe --- /dev/null +++ b/templates/another-page.html @@ -0,0 +1,8 @@ + +{% extends "base.html" %} + +{% block title %}Another page!{% endblock %} + +{% block content %} +

Another page

+{% endblock %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..f9ac400 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,20 @@ + + + + + + + + {% block title %}{{ title }}{% endblock %} + + {% block head %}{% endblock %} + + + +
+ + {% block content %}{% endblock %} +
+ + + diff --git a/templates/hello.html b/templates/hello.html index c1a0c36..2a323f0 100644 --- a/templates/hello.html +++ b/templates/hello.html @@ -1,13 +1,8 @@ - - + +{% extends "base.html" %} - - - - - - -

Howdy!

- - - +{% block title %}Hello!{% endblock %} + +{% block content %} +

Howdy!

+{% endblock %}