Skip to content

Commit

Permalink
feat: Added unsafe HTML Rendering and additional metadata in frontmatter
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhRowjee committed Apr 6, 2024
1 parent c179307 commit e60877e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/frontmatter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct FrontMatter {
Expand All @@ -11,7 +11,7 @@ pub struct FrontMatter {
pub wip: Option<bool>,
pub template: Option<String>,
pub link: Option<String>,
pub meta: Option<Value>,
pub meta: Option<HashMap<String, String>>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod frontmatter;
mod saaru;
mod utils;

/// modal
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Arguments {
Expand Down Expand Up @@ -53,12 +54,11 @@ fn main() {
commandline_arguments.live_rerender,
);
let mut instance = SaaruInstance::new(args);

let start = time::Instant::now();
instance.set_template_environment();
let start = time::Instant::now();
instance.render_pipeline();
let end = time::Instant::now();
log::info!("Total Time Taken -> {:?}", end - start);
println!("Total Time Taken -> {:?}", end - start);

// Implementing Browser-Side Live-Reload
//
Expand Down
16 changes: 12 additions & 4 deletions src/saaru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@ impl SaaruInstance {

let mut options = ComrakOptions::default();
options.extension.front_matter_delimiter = Some("---".to_owned());

// Allow raw HTML!

options.extension.table = true;
options.extension.autolink = true;
options.extension.tasklist = true;
options.extension.tagfilter = true;
// options.extension.tagfilter = true;
options.extension.footnotes = true;
options.extension.strikethrough = true;
options.extension.description_lists = true;
// options.extension.superscript = true;

// options.extension.tagfilter = true;
options.render.unsafe_ = true;

// TODO see where this can fail
let default_template = args.json_content["metadata"]["templates"]["default"]
.as_str()
.unwrap()
Expand Down Expand Up @@ -154,6 +161,7 @@ impl SaaruInstance {
let mut reader = BufReader::new(file);
let mut markdown_file_content = String::new();
reader.read_to_string(&mut markdown_file_content).unwrap();

// Parse the frontmatter
let parsed_frontmatter: FrontMatter = self
.frontmatter_parser
Expand Down Expand Up @@ -392,9 +400,9 @@ impl SaaruInstance {

log::debug!("Generating DDM Context...");
self.base_context = context!(
tags => &self.tag_map,
collections => &self.collection_map,
json => &self.arguments.json_content
tags => &self.tag_map,
collections => &self.collection_map,
json => &self.arguments.json_content
);

log::info!("Rendering All Files...");
Expand Down

0 comments on commit e60877e

Please sign in to comment.