This commit is contained in:
2025-06-27 20:41:04 +02:00
parent a843208422
commit e444d0d7ae
3 changed files with 73 additions and 5 deletions

View File

@@ -4,6 +4,9 @@ mod markdown;
use markdown::{get_all_posts, get_post_by_slug, get_posts_by_tag, watch_posts};
use serde_json;
use std::fs;
use std::io;
use std::io::Read; // STD AYOOOOOOOOOOOOOO - Tsodin
#[derive(Parser)]
#[command(name = "Markdown Backend")]
@@ -31,6 +34,15 @@ enum Commands {
Rsparseinfo,
/// Check backend health
Checkhealth,
/// Parse markdown from file or stdin
Parse {
#[arg(long)]
file: Option<String>,
#[arg(long)]
stdin: bool,
#[arg(long)]
ast: bool,
},
}
fn main() {
@@ -80,5 +92,39 @@ fn main() {
let health = markdown::checkhealth();
println!("{}", serde_json::to_string_pretty(&health).unwrap());
}
Commands::Parse { file, stdin, ast } => {
let input = if let Some(file_path) = file {
match std::fs::read_to_string(file_path) {
Ok(content) => content,
Err(e) => {
eprintln!("Failed to read file: {}", e);
std::process::exit(1);
}
}
} else if *stdin {
let mut buffer = String::new();
if let Err(e) = io::stdin().read_to_string(&mut buffer) {
eprintln!("Failed to read from stdin: {}", e);
std::process::exit(1);
}
buffer
} else {
eprintln!("Please provide --file <path> or --stdin");
std::process::exit(1);
};
if *ast {
// Print pulldown_cmark events as debug output
let parser = pulldown_cmark::Parser::new_ext(&input, pulldown_cmark::Options::all());
for event in parser {
println!("{:?}", event);
}
} else {
// Print HTML output
let parser = pulldown_cmark::Parser::new_ext(&input, pulldown_cmark::Options::all());
let mut html_output = String::new();
pulldown_cmark::html::push_html(&mut html_output, parser);
println!("{}", html_output);
}
}
}
}

22
run-local-backend.sh Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# This script builds and runs the Rust backend locally, similar to the Docker container.
# Usage: ./run-local-backend.sh [args for markdown_backend]
# AnalSex with the frontend ( Cursor Autocompletion xD )
set -e
# Set environment variables as in Docker (customize as needed)
export BLOG_OWNER=${BLOG_OWNER:-"rattatwinko"}
# Build the backend in release mode
cd "$(dirname "$0")/markdown_backend"
echo "Building Rust backend..."
cargo build --release
# Run the backend with any arguments passed to the script
cd target/release
echo "Running: ./markdown_backend $@"
./markdown_backend "$@"
npm run dev ## start the fuckass frontend

View File

@@ -121,12 +121,12 @@ export default function RustStatusPage() {
{/* Health Check Section */}
<div className="mb-6">
<h2 className="text-base sm:text-lg font-semibold mb-2">Health-Check</h2>
<h2 className="text-base sm:text-lg font-semibold mb-2 text-center">Health-Check</h2>
{healthLoading && <div className="text-center py-4 text-base">Lade Health-Check...</div>}
{healthError && <div className="text-red-500 text-center text-base">{healthError}</div>}
{health && (
<div className="bg-white rounded-lg shadow p-4 flex flex-col gap-2">
<div className="flex flex-wrap gap-4">
<div className="bg-white rounded-lg shadow p-4 flex flex-col gap-2 items-center">
<div className="flex flex-wrap gap-4 justify-center">
<div className="flex flex-col items-center">
<span className={`text-lg font-bold ${health.posts_dir_exists ? 'text-green-700' : 'text-red-700'}`}>{health.posts_dir_exists ? '✔' : '✖'}</span>
<span className="text-xs text-gray-600">Posts-Verzeichnis</span>
@@ -165,9 +165,9 @@ export default function RustStatusPage() {
)}
</div>
{health.errors.length > 0 && (
<div className="mt-2 text-red-600 text-xs">
<div className="mt-2 text-red-600 text-xs text-center">
<b>Fehler:</b>
<ul className="list-disc ml-5">
<ul className="list-disc ml-5 inline-block text-left">
{health.errors.map((err, i) => <li key={i}>{err}</li>)}
</ul>
</div>