use metadata from frontmatter
Some checks are pending
ci/woodpecker/push/publish Pipeline is pending

This commit is contained in:
Mylloon 2023-04-21 16:48:31 +02:00
parent a1dc7d538a
commit 0541887c28
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 15 additions and 17 deletions

View file

@ -30,7 +30,7 @@ pub struct File {
} }
/// Options used for parser and compiler MD --> HTML /// Options used for parser and compiler MD --> HTML
fn get_options() -> ComrakOptions { pub fn get_options() -> ComrakOptions {
ComrakOptions { ComrakOptions {
extension: ComrakExtensionOptions { extension: ComrakExtensionOptions {
strikethrough: true, strikethrough: true,
@ -63,13 +63,13 @@ fn get_options() -> ComrakOptions {
} }
pub fn read(raw_text: &str) -> File { pub fn read(raw_text: &str) -> File {
let options = get_options();
let arena = Arena::new(); let arena = Arena::new();
let options = get_options();
let root = parse_document(&arena, raw_text, &options); let root = parse_document(&arena, raw_text, &options);
// Find metadata // Find metadata
let _metadata = get_metadata(root); let metadata = get_metadata(root);
// Convert to HTML // Convert to HTML
let mut html = vec![]; let mut html = vec![];
@ -77,7 +77,7 @@ pub fn read(raw_text: &str) -> File {
File { File {
metadata: Metadata { metadata: Metadata {
info: FileMetadata::default(), info: metadata,
math: false, math: false,
mermaid: false, mermaid: false,
syntax_highlight: false, syntax_highlight: false,

View file

@ -1,13 +1,14 @@
use actix_web::{get, web, HttpResponse, Responder}; use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once; use cached::proc_macro::once;
use chrono::{DateTime, Datelike, Utc}; use chrono::{DateTime, Datelike, Utc};
use comrak::{parse_document, Arena};
use ramhorns::Content; use ramhorns::Content;
use crate::{ use crate::{
config::Config, config::Config,
misc::{ misc::{
date::Date, date::Date,
markdown::{read_file, File, FileMetadata}, markdown::{get_metadata, get_options, read_file, File, FileMetadata},
}, },
template::Infos, template::Infos,
}; };
@ -65,22 +66,19 @@ fn get_posts(location: &str) -> Vec<Post> {
let file_without_ext = filename.split_at(filename.len() - 3).0; let file_without_ext = filename.split_at(filename.len() - 3).0;
let file_metadata = match std::fs::read_to_string(format!("{location}/{filename}")) { let file_metadata = match std::fs::read_to_string(format!("{location}/{filename}")) {
Ok(_text) => { Ok(text) => {
/* let md_tree = get_md_asm(&text); let arena = Arena::new();
let md_nodes = md_tree.children().unwrap();
let mut metadata = get_md_metadata(md_nodes); let options = get_options();
let root = parse_document(&arena, &text, &options);
let mut metadata = get_metadata(root);
metadata.title = match metadata.title { metadata.title = match metadata.title {
Some(t) => Some(t), Some(title) => Some(title),
None => Some(file_without_ext.to_string()), None => Some(file_without_ext.to_string()),
}; };
metadata */ metadata
FileMetadata {
title: Some(file_without_ext.to_string()),
link: None,
date: None,
}
} }
Err(_) => FileMetadata { Err(_) => FileMetadata {
title: Some(file_without_ext.to_string()), title: Some(file_without_ext.to_string()),