From ce6037350c21de861945c06830a191f3f9319d3d Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Sat, 28 Jun 2025 20:38:37 +0200 Subject: [PATCH] shit --- markdown_backend/src/markdown.rs | 50 ++++++++++++++++++++++++++++++-- posts/welcome.md | 34 ++++++++++++++++++++-- src/app/globals.css | 14 ++++++++- 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/markdown_backend/src/markdown.rs b/markdown_backend/src/markdown.rs index 2dfb905..2d3b6d4 100644 --- a/markdown_backend/src/markdown.rs +++ b/markdown_backend/src/markdown.rs @@ -30,6 +30,7 @@ use std::sync::RwLock; use serde_json; use sysinfo::{System, Pid, RefreshKind, CpuRefreshKind, ProcessRefreshKind}; use serde::Serialize; +use regex::Regex; const POSTS_CACHE_PATH: &str = "./cache/posts_cache.json"; const POST_STATS_PATH: &str = "./cache/post_stats.json"; @@ -145,6 +146,51 @@ fn strip_emojis(s: &str) -> String { .collect() } +// Function to process custom tags in markdown content +fn process_custom_tags(content: &str) -> String { + let mut processed = content.to_string(); + + // Handle simple tags without parameters FIRST + let simple_tags = [ + ("", "
This is my custom tag content!
"), + ("", "
⚠️ Warning: This is a custom warning tag!
"), + ("", "
ℹ️ Info: This is a custom info tag!
"), + ("", "
✅ Success: This is a custom success tag!
"), + ("", "
❌ Error: This is a custom error tag!
"), + ]; + + for (tag, replacement) in simple_tags.iter() { + processed = processed.replace(tag, replacement); + } + + // Handle tags with parameters like + let tag_with_params = Regex::new(r"<(\w+)\s+([^>]*?[a-zA-Z0-9=])[^>]*/>").unwrap(); + processed = tag_with_params.replace_all(&processed, |caps: ®ex::Captures| { + let tag_name = &caps[1]; + let params = &caps[2]; + + match tag_name { + "mytag" => { + // Parse parameters and generate custom HTML + format!("
Custom content with params: {}
", params, params) + }, + "alert" => { + // Parse alert type from params + if params.contains("type=\"warning\"") { + "
⚠️ Warning Alert!
".to_string() + } else if params.contains("type=\"error\"") { + "
❌ Error Alert!
".to_string() + } else { + "
ℹ️ Info Alert!
".to_string() + } + }, + _ => format!("
Unknown custom tag: {}
", tag_name, tag_name) + } + }).to_string(); + + processed +} + static AMMONIA: Lazy> = Lazy::new(|| { let mut builder = ammonia::Builder::default(); // All possible HTML Tags so that you can stylize via HTML @@ -170,7 +216,7 @@ static AMMONIA: Lazy> = Lazy::new(|| { builder.add_tag_attributes("pre", &["style"]); builder.add_tag_attributes("kbd", &["style"]); builder.add_tag_attributes("samp", &["style"]); - builder.add_tag_attributes("div", &["style"]); + builder.add_tag_attributes("div", &["style", "class"]); builder.add_tag_attributes("section", &["style"]); builder.add_tag_attributes("article", &["style"]); builder.add_tag_attributes("header", &["style"]); @@ -280,7 +326,7 @@ pub fn get_post_by_slug(slug: &str) -> Result> let created_at = get_file_creation_date(&file_path)?; - let processed_markdown = process_anchor_links(&result.content); + let processed_markdown = process_custom_tags(&process_anchor_links(&result.content)); let parser = Parser::new_ext(&processed_markdown, Options::all()); let mut html_output = String::new(); let mut heading_text = String::new(); diff --git a/posts/welcome.md b/posts/welcome.md index df7cd70..630aabb 100644 --- a/posts/welcome.md +++ b/posts/welcome.md @@ -24,6 +24,7 @@ author: Rattatwinko - [Features 🎉](#features) - [Administration 🚧](#administration) - [Customization 🎨](#customization) +- [Creating Posts with MdB ✍]() - [Troubleshooting 🚨](#troubleshooting) - [Support 🤝](#support) - [Support the Project ❤️](#support-the-project) @@ -31,7 +32,7 @@ author: Rattatwinko - [Folder Emojis 🇦🇹](#folder-emoji-technical-note) - [API 🏗️](#api) - [ToT, and Todo](#train-of-thought-for-this-project-and-todo) -- [Recent Changes](#) +- [Recent Changes](#recent-changes) --- @@ -302,6 +303,35 @@ The codebase is well-structured and documented. Key files: --- +## Creating Posts with MdB ✍ + +If you are reading posts. Then you probably dont need this explenation! + +Else you should read this. + +First of all, if you are creating posts within the terminal. then you should create posts with the following headers. + +```Markdown +--- +title: Welcome to MarkdownBlog +date: '2025-06-19' +tags: + - welcome + - introduction + - getting-started + - documentation +summary: A comprehensive guide to getting started with MarkdownBlog +author: Rattatwinko +--- +``` + +As you can see this is the header for the current Post. +You can write this like YML (idk). + +If you are writing posts within the Admin-Panel then you are a _lucky piece of shit_ cause there it does that **automatically** + +--- + ## Troubleshooting ### Common Issues @@ -450,4 +480,4 @@ If you are wondering: > > *"DEVELOPERS! DEVELOPERS! DEVELOPERS!"* - Steve Ballmer > -> — Rattatwinko, 2025 Q3 \ No newline at end of file +> — Rattatwinko, 2025 Q3 diff --git a/src/app/globals.css b/src/app/globals.css index 334b354..850807f 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -443,4 +443,16 @@ select:focus { .prose a { word-break: break-word; } -} \ No newline at end of file +} + +.custom-tag { + padding: 1rem; + border-radius: 6px; + margin: 1rem 0; + font-weight: 500; +} +.custom-tag.warning { background: #fff3cd; border: 1px solid #ffeaa7; color: #856404; } +.custom-tag.info { background: #d1ecf1; border: 1px solid #bee5eb; color: #0c5460; } +.custom-tag.success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; } +.custom-tag.error { background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; } +.custom-tag.mytag { background: #e3e3ff; border: 1px solid #b3b3ff; color: #333366; } \ No newline at end of file