added askama, base template and index
This commit is contained in:
parent
f071a702af
commit
ae1b65957d
@ -6,6 +6,8 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
askama = { version = "0.12", features = ["with-axum", "mime", "mime_guess"] }
|
||||
askama_axum = "0.4.0"
|
||||
axum = "0.7.3"
|
||||
chrono = { version = "0.4.31", features = ["serde"] }
|
||||
gray_matter = "0.2.6"
|
||||
|
6
axum_server/askama.toml
Normal file
6
axum_server/askama.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[general]
|
||||
# Directories to search for templates, relative to the crate root.
|
||||
dirs = ["templates"]
|
||||
# Unless you add a `-` in a block, whitespace characters won't be trimmed.
|
||||
whitespace = "preserve"
|
||||
|
@ -1,8 +1,10 @@
|
||||
use axum;
|
||||
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||
|
||||
mod pages;
|
||||
mod post_parser;
|
||||
mod router;
|
||||
// mod template;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
|
9
axum_server/src/pages/index.rs
Normal file
9
axum_server/src/pages/index.rs
Normal file
@ -0,0 +1,9 @@
|
||||
use askama::Template;
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
pub struct IndexTemplate {}
|
||||
|
||||
pub async fn render_index() -> IndexTemplate {
|
||||
IndexTemplate {}
|
||||
}
|
1
axum_server/src/pages/mod.rs
Normal file
1
axum_server/src/pages/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod index;
|
@ -1,11 +1,11 @@
|
||||
use crate::post_parser::parse_post;
|
||||
use crate::{pages::index::render_index, post_parser::parse_post};
|
||||
use axum::{extract::MatchedPath, http::Request, routing::get, Router};
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::info_span;
|
||||
|
||||
pub fn get_router() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(|| async { "Hello, World!" }))
|
||||
.route("/", get(render_index))
|
||||
.route("/blog/:post_id", get(parse_post))
|
||||
.layer(
|
||||
TraceLayer::new_for_http().make_span_with(|request: &Request<_>| {
|
||||
|
9
axum_server/src/template.rs
Normal file
9
axum_server/src/template.rs
Normal file
@ -0,0 +1,9 @@
|
||||
pub use askama::*;
|
||||
use axum::http::Response;
|
||||
|
||||
pub fn into_response<T: Template>(t: &T) -> Response {
|
||||
match t.render() {
|
||||
Ok(body) => Html(body),
|
||||
Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
}
|
||||
}
|
36
axum_server/templates/base.html
Normal file
36
axum_server/templates/base.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{% block title %} {{title}} @michalvankodev {% endblock %}</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<meta name="theme-color" content="#333333" />
|
||||
|
||||
<meta name="description" content="Personal website of @michalvankodev" />
|
||||
<meta name="keywords" content="personal, blog, webdev, tech, programming" />
|
||||
<meta name="robots" content="index, follow" />
|
||||
<link
|
||||
rel="alternate"
|
||||
type="application/rss+xml"
|
||||
title="RSS feed for latest posts"
|
||||
href="https://michalvanko.dev/feed.xml"
|
||||
/>
|
||||
<link
|
||||
rel="alternate"
|
||||
title="JSON feed for latest posts"
|
||||
type="application/json"
|
||||
href="https://michalvanko.dev/feed.json"
|
||||
/>
|
||||
|
||||
<link rel="stylesheet" href="/print.css" media="print" />
|
||||
<link rel="stylesheet" href="/fonts.css" />
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<link rel="stylesheet" href="/prism.css" />
|
||||
|
||||
<link rel="icon" type="image/svg+xml" href="/m-logo.svg" />
|
||||
<link rel="icon" type="image/png" href="/m-logo-192.png" />
|
||||
</head>
|
||||
<body>
|
||||
{% block content %} Placeholder {% endblock %}
|
||||
</body>
|
||||
</html>
|
56
axum_server/templates/index.html
Normal file
56
axum_server/templates/index.html
Normal file
@ -0,0 +1,56 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Introduction{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<header class="index-header">
|
||||
<figure class="profile-pic">
|
||||
<picture>
|
||||
<img
|
||||
alt="Portrait"
|
||||
{# TODO generate `srcset` for optimal image #}
|
||||
{# TODO Take a new photo #}
|
||||
src="/images/profile-portugal-landscape.jpg"
|
||||
/>
|
||||
</picture>
|
||||
</figure>
|
||||
|
||||
<p class="motto">
|
||||
<cite>“Let your ambition carry you.”</cite>
|
||||
<span class="cite-owner">- La Flame</span>
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<p>
|
||||
Hey, welcome to my personal website. My name is
|
||||
<strong>Michal Vanko</strong>
|
||||
and I'm a
|
||||
<em> <a href="https://en.wikipedia.org/wiki/Programmer">programmer</a> </em>
|
||||
. I'll try to share some stories and opinions about things that I'm interested
|
||||
in.
|
||||
</p>
|
||||
|
||||
<section class="twitch-stream-promo">
|
||||
<h2>Follow my twitch stream</h2>
|
||||
<div class="twitch-embed">
|
||||
<div class="twitch-video">
|
||||
<iframe
|
||||
title="My twitch channel"
|
||||
src="https://player.twitch.tv/?channel=michalvankodev&parent=michalvanko.dev&parent=localhost&autoplay=false"
|
||||
loading="lazy"
|
||||
frameborder="0"
|
||||
scrolling="no"
|
||||
allowfullscreen
|
||||
height="100%"
|
||||
width="100%"
|
||||
class="embed"
|
||||
/>
|
||||
</div>
|
||||
<aside>
|
||||
Come hang out and chat with me <strong>every Tuesday and Thursday</strong>
|
||||
afternoon central Europe time. I stream working on my side-projects and talking
|
||||
anything about the developer lifestyle.
|
||||
</aside>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user