kochab/examples/document.rs

48 lines
1.8 KiB
Rust

use anyhow::*;
use log::LevelFilter;
use kochab::{Server, Response, Gemtext};
#[tokio::main]
async fn main() -> Result<()> {
env_logger::builder()
.filter_module("kochab", LevelFilter::Debug)
.init();
// Generate a fancy procedural response
let response: Response = Gemtext::new()
.preformatted("kochab", include_str!("kochab_logo.txt"))
.blank_line()
.text(
concat!(
"Kochab is an extension & a fork of the Gemini SDK [northstar]. Where",
" northstar creates an efficient and flexible foundation for Gemini projects,",
" kochab seeks to be as ergonomic and intuitive as possible, making it",
" possible to get straight into getting your ideas into geminispace, with no",
" worrying about needing to build the tools to get there."
)
)
.blank_line()
.link("https://github.com/Alch-Emi/kochab", Some("GitHub"))
.blank_line()
.heading(2, "Usage")
.blank_line()
.text("Add the latest version of kochab to your `Cargo.toml`.")
.blank_line()
.preformatted("toml", r#"kochab = { git = "https://github.com/Alch-Emi/kochab.git" }"#)
.blank_line()
.heading(2, "Generating a key & certificate")
.blank_line()
.preformatted("sh", concat!(
"mkdir cert && cd cert\n",
"openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365",
))
.into();
Server::new()
// You can also return the response from any one of your response handlers, but if
// you want to serve a static response, this works too
.add_route("/", response)
.serve_unix("kochab.sock")
.await
}