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

View file

@ -1,13 +1,14 @@
use actix_web::{get, web, HttpResponse, Responder};
use cached::proc_macro::once;
use chrono::{DateTime, Datelike, Utc};
use comrak::{parse_document, Arena};
use ramhorns::Content;
use crate::{
config::Config,
misc::{
date::Date,
markdown::{read_file, File, FileMetadata},
markdown::{get_metadata, get_options, read_file, File, FileMetadata},
},
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_metadata = match std::fs::read_to_string(format!("{location}/{filename}")) {
Ok(_text) => {
/* let md_tree = get_md_asm(&text);
let md_nodes = md_tree.children().unwrap();
let mut metadata = get_md_metadata(md_nodes);
Ok(text) => {
let arena = Arena::new();
let options = get_options();
let root = parse_document(&arena, &text, &options);
let mut metadata = get_metadata(root);
metadata.title = match metadata.title {
Some(t) => Some(t),
Some(title) => Some(title),
None => Some(file_without_ext.to_string()),
};
metadata */
FileMetadata {
title: Some(file_without_ext.to_string()),
link: None,
date: None,
}
metadata
}
Err(_) => FileMetadata {
title: Some(file_without_ext.to_string()),