-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5: Add markdown rendering to eportfolio (#16)
* added markdown dependency and created markdown render operation * move file path of markdown operation to context * refactor course routes and context and add course list page * styling to courses list and more in context * tailwindstyles and under development markers * simplify error handling into function
- Loading branch information
Showing
14 changed files
with
1,405 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
/target | ||
package.json | ||
pnpm-lock.yaml | ||
**/*/node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::collections::HashMap; | ||
|
||
use markdown::Options; | ||
use unchained::{ | ||
error::WebResult, | ||
templates::{ | ||
context::{ContextMap, ContextTree::*, Primitive::*}, | ||
operations::{unwrap_n_params, TemplateOperation}, | ||
render::{load_template, RenderOptions}, | ||
}, | ||
}; | ||
|
||
pub fn render_md(path: &str, context: Option<ContextMap>) -> WebResult<String> { | ||
let closure = { | ||
|call, ctx, opts| { | ||
let file_path = unwrap_n_params::<1>(&call.parameters)?[0]; | ||
let path_in_context = ctx.get(file_path); | ||
let file_path = if let Some(Leaf(Str(valid_path))) = path_in_context { | ||
valid_path | ||
} else { | ||
file_path | ||
}; | ||
let file_content = load_template(file_path, Some(ctx.clone()), opts)?; | ||
let md = markdown::to_html_with_options(&file_content, &Options::gfm()); | ||
Ok(md.unwrap_or_default()) | ||
} | ||
} as TemplateOperation; | ||
|
||
load_template( | ||
path, | ||
context.clone(), | ||
&RenderOptions { | ||
custom_operations: HashMap::from([("md", closure)]), | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,7 @@ module.exports = { | |
}, | ||
}, | ||
}, | ||
plugins: [], | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{* component templates/base.html { | ||
<div class="flex flex-col gap-5 items-start px-6 lg:px-20 py-6"> | ||
<a href="/courses" class="border-b border-black mvn-button">🠐 List of courses</a> | ||
<div class="grid w-full"> | ||
<div class="prose prose-sm lg:prose-lg m-auto"> | ||
{* md course_md_path *} | ||
</div> | ||
</div></div> | ||
} *} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{* comment { | ||
Takes in a list of page information called "pages". Each has a course id (also file name), title, and possible image path. | ||
} *} | ||
{* component templates/base.html { | ||
<div class="w-full my-10"> | ||
<div class="m-10"> | ||
<h1 class="text-3xl lg:text-5xl font-bold lg:w-2/3">Courses</h1> | ||
<p class="text-gray-700">Following is a list of pages with information about some of the courses I have taken.</p> | ||
</div> | ||
<div class="grid lg:grid-cols-3 grid-cols-1 gap-5 p-4 place-items-stretch"> | ||
{* for page in course_pages { | ||
<a href="/courses/{* get page.course_id *}" class="focus:ring-2 focus:rounded-lg focus:ring-black focus:outline-none"> | ||
<div class="border-2 border-gray-500 rounded-lg p-4 bg-zinc-50 mvn-button shadow-gray-800 shadow-md h-full"> | ||
<p class="text-sm ">{* get page.course_id *}</p> | ||
<h3 class="text-xl">{* get page.title *}</h3> | ||
</div> | ||
</a> | ||
} *} | ||
</div> | ||
</div> | ||
} *} | ||
|
Oops, something went wrong.