Browse Source

Skeleton

This is mostly coming from another project, which I already set up to
this point.
master
Julio Biason 4 months ago
commit
3df083eea9
  1. 1
      .gitignore
  2. 1047
      Cargo.lock
  3. 11
      Cargo.toml
  4. 3
      README.md
  5. 12
      src/args/mod.rs
  6. 14
      src/index/mod.rs
  7. 21
      src/main.rs
  8. 27
      src/staticfiles/mod.rs
  9. 5
      staticfiles/main.css
  10. 14
      templates/index.html

1
.gitignore vendored

@ -0,0 +1 @@
/target

1047
Cargo.lock generated

File diff suppressed because it is too large Load Diff

11
Cargo.toml

@ -0,0 +1,11 @@
[package]
name = "markvault"
version = "0.1.0"
edition = "2021"
[dependencies]
askama = "0.12.1"
axum = "0.7.5"
clap = { version = "4.5.7", features = ["derive", "env"] }
phf = { version = "0.11.2", features = ["macros"] }
tokio = { version = "1.38.0", features = ["rt-multi-thread", "macros"] }

3
README.md

@ -0,0 +1,3 @@
# MarkVault
A Bookmark/Read-It-Later service, for personal use.

12
src/args/mod.rs

@ -0,0 +1,12 @@
//! Command line arguments
use std::net::SocketAddr;
use clap::Parser;
#[derive(Parser)]
pub(super) struct Cli {
/// Address and port to listen to connections
#[arg(default_value = "0.0.0.0:3000")]
pub address: SocketAddr
}

14
src/index/mod.rs

@ -0,0 +1,14 @@
//! Index content
use askama::Template;
use axum::response::Html;
pub(super) async fn index() -> Html<String> {
let template = IndexTemplate {};
Html(template.render().unwrap())
}
#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate {}

21
src/main.rs

@ -0,0 +1,21 @@
mod args;
mod index;
mod staticfiles;
use axum::routing::get;
use axum::Router;
use clap::Parser;
#[tokio::main]
async fn main() {
// tracing_subscriber::fmt::init();
let opts = args::Cli::parse();
println!("Starting server at {:?}", &opts.address);
let app = Router::new()
.route("/", get(index::index))
.route("/static/:file", get(staticfiles::staticfile));
let listener = tokio::net::TcpListener::bind(&opts.address).await.unwrap();
axum::serve(listener, app).await.unwrap();
}

27
src/staticfiles/mod.rs

@ -0,0 +1,27 @@
//! Static file serving
use axum::body::Body;
use axum::extract::Path;
use axum::http::header;
use axum::http::StatusCode;
use axum::response::Response;
use phf::phf_map;
static FILES: phf::Map<&'static str, &'static str> = phf_map! {
"main.css" => include_str!("../../staticfiles/main.css")
};
pub(super) async fn staticfile(Path(filename): Path<String>) -> Response {
match FILES.get(&filename) {
Some(content) => Response::builder()
.status(StatusCode::OK)
.header(header::CONTENT_TYPE, "text/css")
.body(Body::from(*content))
.unwrap(),
None => Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from("Not found"))
.unwrap(),
}
}

5
staticfiles/main.css

@ -0,0 +1,5 @@
/* main */
body {
background-color: #14142E;
color: #ffffff;
}

14
templates/index.html

@ -0,0 +1,14 @@
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>NoteVine</title>
<link rel="stylesheet" href="static/main.css" />
</head>
<body>
{% block main %}
Content!
{% endblock %}
</body>
</html>
Loading…
Cancel
Save