main #1

Merged
heavyweaponsgal merged 5 commits from slonk/bingus-blog:main into main 2024-05-03 01:27:49 +03:00
5 changed files with 56 additions and 72 deletions
Showing only changes of commit 8678758440 - Show all commits

View file

@ -59,8 +59,8 @@ struct IndexTemplate {
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "view_post.html")] #[template(path = "post.html")]
struct ViewPostTemplate { struct PostTemplate {
meta: PostMetadata, meta: PostMetadata,
rendered: String, rendered: String,
rendered_in: RenderStats, rendered_in: RenderStats,
@ -176,7 +176,7 @@ async fn post(State(state): State<ArcState>, Path(name): Path<String>) -> AppRes
Ok(([("content-type", "text/plain")], buf).into_response()) Ok(([("content-type", "text/plain")], buf).into_response())
} else { } else {
let post = state.posts.get_post(&name).await?; let post = state.posts.get_post(&name).await?;
let page = ViewPostTemplate { let page = PostTemplate {
meta: post.0, meta: post.0,
rendered: post.1, rendered: post.1,
rendered_in: post.2, rendered_in: post.2,

View file

@ -8,7 +8,7 @@ use crate::config::RenderConfig;
use crate::post::PostMetadata; use crate::post::PostMetadata;
/// do not persist cache if this version number changed /// do not persist cache if this version number changed
pub const CACHE_VERSION: u16 = 1; pub const CACHE_VERSION: u16 = 2;
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Deserialize, Clone)]
pub struct CacheValue { pub struct CacheValue {

View file

@ -5,7 +5,6 @@ use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::{Duration, Instant, SystemTime}; use std::time::{Duration, Instant, SystemTime};
use askama::Template;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use fronma::parser::{parse, ParsedData}; use fronma::parser::{parse, ParsedData};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -63,14 +62,6 @@ pub struct PostMetadata {
pub tags: Vec<String>, pub tags: Vec<String>,
} }
use crate::filters;
#[derive(Template)]
#[template(path = "post.html")]
struct Post<'a> {
pub meta: &'a PostMetadata,
pub rendered_markdown: String,
}
#[allow(unused)] #[allow(unused)]
pub enum RenderStats { pub enum RenderStats {
Cached(Duration), Cached(Duration),
@ -127,12 +118,7 @@ impl PostManager {
let parsing = parsing_start.elapsed(); let parsing = parsing_start.elapsed();
let before_render = Instant::now(); let before_render = Instant::now();
let rendered_markdown = render(body, &self.config); let post = render(body, &self.config);
let post = Post {
meta: &metadata,
rendered_markdown,
}
.render()?;
let rendering = before_render.elapsed(); let rendering = before_render.elapsed();
if let Some(cache) = self.cache.as_ref() { if let Some(cache) = self.cache.as_ref() {

View file

@ -1,16 +1,52 @@
{%- import "macros.askama" as macros -%} {%- import "macros.askama" as macros -%}
<h1 class="post-title"> <!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="{{ meta.title }}" />
<meta property="og:title" content="{{ meta.title }}" />
<meta property="og:description" content="{{ meta.description }}" />
{% match meta.icon %} {% when Some with (url) %}
<meta property="og:image" content="{{ url }}" />
<link rel="shortcut icon" href="{{ url }}" />
{% when None %} {% endmatch %}
<title>{{ meta.title }}</title>
<link rel="stylesheet" href="/static/style.css" />
<link rel="stylesheet" href="/static/post.css" />
</head>
</head>
<body>
<main>
<h1 class="post-title">
{{ meta.title }} {{ meta.title }}
<span class="post-author">- by {{ meta.author }}</span> <span class="post-author">- by {{ meta.author }}</span>
</h1> </h1>
<p class="post-desc">{{ meta.description }}</p> <p class="post-desc">{{ meta.description }}</p>
<p> <div class="" post>
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div> <div>
{% call macros::table(meta) %} {% call macros::table(meta) %}
</div> </div>
<a href="/posts/{{ meta.name }}">link</a><br /> <a href="/posts/{{ meta.name }}">link</a><br />
<a href="/">back to home</a> <a href="/">back to home</a>
</p> </div>
<hr /> <hr />
{{ rendered_markdown|escape("none") }} {{ rendered|escape("none") }}
</main>
<!-- prettier-ignore -->
<footer>
{% match rendered_in %}
{% when RenderStats::ParsedAndRendered(total, parsing, rendering) %}
<span class="tooltipped" title="parsing took {{ parsing|duration }}">parsed</span> and
<span class="tooltipped" title="rendering took {{ rendering|duration }}">rendered</span> in {{ total|duration }}
{% when RenderStats::Cached(total) %}
retrieved from cache in {{ total|duration }}
{% endmatch %}
{% if markdown_access %}
- <a href="/posts/{{ meta.name }}.md">view raw</a>
{% endif %}
</footer>
</body>
</html>

View file

@ -1,38 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<meta name="description" content="{{ meta.title }}" />
<meta property="og:title" content="{{ meta.title }}" />
<meta property="og:description" content="{{ meta.description }}" />
{% match meta.icon %} {% when Some with (url) %}
<meta property="og:image" content="{{ url }}" />
<link rel="shortcut icon" href="{{ url }}" />
{% when None %} {% endmatch %}
<title>{{ meta.title }}</title>
<link rel="stylesheet" href="/static/style.css" />
<link rel="stylesheet" href="/static/post.css" />
</head>
</head>
<body>
<main>{{ rendered|escape("none") }}</main>
<!-- prettier-ignore -->
<footer>
{% match rendered_in %}
{% when RenderStats::ParsedAndRendered(total, parsing, rendering) %}
<span class="tooltipped" title="parsing took {{ parsing|duration }}">parsed</span> and
<span class="tooltipped" title="rendering took {{ rendering|duration }}">rendered</span> in {{ total|duration }}
{% when RenderStats::Cached(total) %}
retrieved from cache in {{ total|duration }}
{% endmatch %}
{% if markdown_access %}
- <a href="/posts/{{ meta.name }}.md">view raw</a>
{% endif %}
</footer>
</body>
</html>