remove intermediate template and cache rendered markdown directly instead
This commit is contained in:
parent
ad2a8c6ba4
commit
8678758440
5 changed files with 56 additions and 72 deletions
|
@ -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,
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
|
Loading…
Reference in a new issue