From 840ab94d9c7d2f026b2bb0120c0ba1d447c8c02d Mon Sep 17 00:00:00 2001 From: Imk Date: Tue, 1 Oct 2024 13:35:25 +0200 Subject: [PATCH] Made tags visible on the front-end, added pinning to both back and front-end --- posts/my-first-article/post_frontmatter.toml | 1 + posts/test1/post.md | 21 ++++++++++++++++++++ posts/test1/post_frontmatter.toml | 9 +++++++++ src/handlers/home_handler.rs | 7 +++++-- static/css/index.css | 8 ++++++++ templates/home.html | 3 ++- 6 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 posts/test1/post.md create mode 100644 posts/test1/post_frontmatter.toml diff --git a/posts/my-first-article/post_frontmatter.toml b/posts/my-first-article/post_frontmatter.toml index e63e21a..2bdc478 100644 --- a/posts/my-first-article/post_frontmatter.toml +++ b/posts/my-first-article/post_frontmatter.toml @@ -6,3 +6,4 @@ posted = '22/08/2022' estimated_reading_time = 1 author = 'IMK' # feel free to swap with your own name order = 1 +pinned = true diff --git a/posts/test1/post.md b/posts/test1/post.md new file mode 100644 index 0000000..e495616 --- /dev/null +++ b/posts/test1/post.md @@ -0,0 +1,21 @@ +# WELCOME TO MY BLOG!!! + +So uh the plan is to update this blog as often as possible as I learn more about rust :3 + +Don't expect me to word posts professionally as this is intended to be more of something where I can turn off my mind and write my thoughts down. + +## I aim to post daily though so that's cool + +also this blog was made with a random tutorial from The Medium so yeahhhhhhh I can barely understand the codebase or whatever the fancy term for the source code is + +so uhh have fun and stuff :3 + +P.S. I go by IMK, IMKJET on most places (and IMKTHECOOL[x] rarely), It's like capitalized usually but I honestly don't give a fuckkkkkk + +1. number +2. list +3. test + +- unsorted +- yeahhh + diff --git a/posts/test1/post_frontmatter.toml b/posts/test1/post_frontmatter.toml new file mode 100644 index 0000000..aafa317 --- /dev/null +++ b/posts/test1/post_frontmatter.toml @@ -0,0 +1,9 @@ +title = 'unpinned therefore should be at the bottom' +file_name = 'test1' +description = 'about this blog and stuff' +tags = ["Casual"] +posted = '22/08/2022' +estimated_reading_time = 1 +author = 'IMK' # feel free to swap with your own name +order = 1 +pinned = false diff --git a/src/handlers/home_handler.rs b/src/handlers/home_handler.rs index a88a363..2da0a7c 100644 --- a/src/handlers/home_handler.rs +++ b/src/handlers/home_handler.rs @@ -12,6 +12,7 @@ pub struct Frontmatter { author: String, estimated_reading_time: u32, order: u32, + pinned: bool, } #[get("/")] @@ -62,8 +63,10 @@ fn find_all_frontmatters() -> Result, std::io::Error> { if fm.path().is_file() { let fm_content = fs::read_to_string(fm.path())?; let frontmatter: Frontmatter = toml::from_str::(&fm_content).unwrap(); - - frontmatters.push(frontmatter); + if frontmatter.pinned { + frontmatters.insert(0,frontmatter); + }else{ + frontmatters.push(frontmatter);} } } Err(e) => { diff --git a/static/css/index.css b/static/css/index.css index 52fb130..f8d99bc 100644 --- a/static/css/index.css +++ b/static/css/index.css @@ -8,6 +8,14 @@ a { text-decoration: none; } +.pinned-false { + display: none; +} + +.pinned-true { + text-align: right; +} + a:link{ color: white; } diff --git a/templates/home.html b/templates/home.html index df2387d..e2f817d 100644 --- a/templates/home.html +++ b/templates/home.html @@ -7,12 +7,13 @@ {% for fm in posts %}
-

{{fm.title}}

+

{{fm.title}}

!!


  • On: {{fm.posted}}
  • By: {{fm.author}}
  • Reading time:{{fm.estimated_reading_time}} min
  • +
  • Tags: {{fm.tags}}