This commit is contained in:
Mylloon 2023-04-19 18:55:03 +02:00
parent d8a1693dd7
commit 1d860d58b7
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
5 changed files with 164 additions and 6 deletions

View file

@ -2,7 +2,10 @@ use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use ramhorns::Content;
use crate::config::Config;
use crate::{
config::Config,
template::{read_md_file, File, Infos},
};
#[get("/blog")]
pub async fn index(config: web::Data<Config>) -> impl Responder {
@ -10,7 +13,9 @@ pub async fn index(config: web::Data<Config>) -> impl Responder {
}
#[derive(Content)]
struct BlogIndexTemplate {}
struct BlogIndexTemplate {
post: Option<File>,
}
#[once(time = 60)]
pub fn get_index(_config: Config) -> String {
@ -18,11 +23,22 @@ pub fn get_index(_config: Config) -> String {
}
#[get("/blog/{id}")]
pub async fn page(path: web::Path<(u32,)>, config: web::Data<Config>) -> impl Responder {
pub async fn page(path: web::Path<(String,)>, config: web::Data<Config>) -> impl Responder {
HttpResponse::Ok().body(get_page(path.into_inner().0, config.get_ref().clone()))
}
#[once(time = 60)]
pub fn get_page(id: u32, _config: Config) -> String {
format!("Salut pour {id}")
pub fn get_page(file: String, config: Config) -> String {
let blog_dir = "data/blog";
let ext = ".md";
let post = read_md_file(&format!("{blog_dir}/{file}{ext}"));
let infos = Infos {
page_title: Some(format!("Post: {file}")),
page_desc: Some("Blog d'Anri".to_string()),
};
config
.tmpl
.render("blog/post.html", BlogIndexTemplate { post }, infos)
}

33
static/css/blog.css Normal file
View file

@ -0,0 +1,33 @@
@media (prefers-color-scheme: light) {
:root {
--selection: rgba(92, 54, 131, 0.7);
--visited: #005cc5;
}
}
@media (prefers-color-scheme: dark) {
:root {
--selection: rgba(124, 75, 173, 0.5);
--visited: #8be9fd;
}
}
:root {
--font-size: 17px;
}
html {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial,
sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: var(--font-size);
}
::selection {
color: rgb(255, 255, 255);
background: var(--selection);
}
html {
scroll-behavior: smooth;
}

View file

@ -0,0 +1,42 @@
<footer>
<a href="/blog" target="_self">Retour à la liste des posts</a>
</footer>
{{#data}} {{#post}} {{#metadata}} {{#math}}
<!-- KaTeX -->
<script
defer
src="https://cdn.jsdelivr.net/npm/katex@0.16.6/dist/katex.min.js"
integrity="sha384-j/ZricySXBnNMJy9meJCtyXTKMhIJ42heyr7oAdxTDBy/CYA9hzpMo+YTNV5C+1X"
crossorigin="anonymous"
></script>
<script
defer
src="https://cdn.jsdelivr.net/npm/katex@0.16.6/dist/contrib/auto-render.min.js"
integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05"
crossorigin="anonymous"
onload="renderMathInElement(document.body);"
></script>
{{/math}} {{#mermaid}}
<!-- Mermaid diagrams -->
<script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";
mermaid.initialize({ startOnLoad: true });
</script>
{{/mermaid}} {{#syntax_highlight}}
<!-- Syntax highligthing -->
<script src="https://cdn.jsdelivr.net/npm/shiki"></script>
<script>
shiki
.getHighlighter({
theme: "nord",
})
.then((highlighter) => {
const code = highlighter.codeToHtml(`console.log('shiki');`, {
lang: "js",
});
document.getElementById("output").innerHTML = code;
});
</script>
{{/syntax_highlight}} {{/metadata}} {{/post}} {{/data}}

51
templates/blog/head.html Normal file
View file

@ -0,0 +1,51 @@
<head dir="ltr">
<title>{{page_title}}{{#page_title}} - {{/page_title}}{{app_name}}</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/css/blog.css" />
<meta name="author" content="Mylloon" />
<meta name="description" content="{{page_desc}} " />
<base target="_blank" />
<!-- Icones (https://realfavicongenerator.net/) -->
<link
rel="apple-touch-icon"
sizes="180x180"
href="/icons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/icons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/icons/favicon-16x16.png"
/>
<link rel="manifest" href="/icons/site.webmanifest" />
<link rel="mask-icon" href="/icons/safari-pinned-tab.svg" color="#5bbad5" />
<link rel="shortcut icon" href="/icons/favicon.ico" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-config" content="/icons/browserconfig.xml" />
<meta name="theme-color" content="#2a2424" />
<!-- Embed réseaux sociaux -->
<meta content="{{page_title}} " property="og:title" />
<meta content="{{page_desc}} " property="og:description" />
<meta content="/icons/apple-touch-icon.png" property="og:image" />
<meta content="#43B581" data-react-helmet="true" name="theme-color" />
{{#data}} {{#post}} {{#metadata}} {{#math}}
<!-- KaTeX -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/katex@0.16.6/dist/katex.min.css"
integrity="sha384-mXD7x5S50Ko38scHSnD4egvoExgMPbrseZorkbE49evAfv9nNcbrXJ8LLNsDgh9d"
crossorigin="anonymous"
/>
{{/math}} {{/metadata}} {{/post}} {{/data}}
</head>

16
templates/blog/post.html Normal file
View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html class="index" lang="fr">
{{>blog/head.html}}
<body class="index">
{{#data}}
<header></header>
<main>
{{^post}}
<p>This post doesn't exist... sorry</p>
{{/post}} {{#post}}
<article>{{&content}}</article>
{{/post}}
</main>
{{/data}}{{>blog/footer.html}}
</body>
</html>