From d1c5d0c3010cc11cbb249b056b77e65cbb7f9468 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sat, 19 Aug 2023 00:56:35 +0100 Subject: enable html and checkbox checkability when rendering blogposts --- src/posts/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/posts/mod.rs') diff --git a/src/posts/mod.rs b/src/posts/mod.rs index 7f8e6c4..c75dd53 100644 --- a/src/posts/mod.rs +++ b/src/posts/mod.rs @@ -6,7 +6,7 @@ use std::collections::HashSet; use async_trait::async_trait; use chrono::{DateTime, Utc}; -use markdown::{mdast::Node, Constructs, Options, ParseOptions}; +use markdown::{mdast::Node, CompileOptions, Constructs, Options, ParseOptions}; use rocket::http::Status; use serde::{ser::SerializeStruct, Deserialize, Serialize}; use tokio::fs; @@ -22,7 +22,7 @@ enum PostType { #[derive(Debug)] pub struct Post { - // id: i64, + id: String, subject: Option, created_at: DateTime, updated_at: Option>, @@ -182,11 +182,15 @@ impl Content for Article { parse: ParseOptions { constructs: Constructs { frontmatter: true, - ..Constructs::default() + ..Constructs::gfm() }, ..ParseOptions::default() }, - ..Options::default() + compile: CompileOptions { + gfm_task_list_item_checkable: true, + allow_dangerous_html: true, + ..CompileOptions::default() + }, }; Ok(markdown::to_html_with_options(&buf, &options).unwrap()) } @@ -211,6 +215,7 @@ impl Post
{ }; Ok(Post { + id: article.name.to_owned(), subject: Some(metadata.title), created_at: metadata.created_at.parse::>()?, updated_at, -- cgit