doordesk-js/doordesk/app/src/components/slingshot.rs

40 lines
1.3 KiB
Rust
Raw Normal View History

2024-01-18 23:14:50 -05:00
use crate::components::article::ArticleData;
2024-01-19 17:49:12 -05:00
use leptos::*;
2024-01-06 04:26:09 -05:00
2024-01-17 00:06:08 -05:00
#[server]
2024-01-18 17:39:20 -05:00
pub async fn slingshot(path: String) -> Result<Vec<ArticleData>, ServerFnError> {
2024-01-17 00:06:08 -05:00
let mut articles = vec![];
2024-01-18 17:39:20 -05:00
for dir in std::fs::read_dir(path)? {
2024-01-18 14:02:24 -05:00
for file in std::fs::read_dir(dir?.path())? {
let fileinfo = file?;
2024-01-17 00:06:08 -05:00
let filepath = fileinfo.path();
2024-01-18 14:02:24 -05:00
if let Some(filetype) = filepath.extension() {
if filetype == "md" {
let file = std::fs::read_to_string(filepath)?;
2024-01-19 17:49:12 -05:00
let html_from_md = femark::process_markdown_to_html(&file.to_string())
.expect("Problem processing markdown");
let content = html_from_md.content;
let _toc = html_from_md.toc;
let _frontmatter = html_from_md.frontmatter;
2024-01-18 14:02:24 -05:00
articles.push(ArticleData {
content_type: String::from("Blog"),
title: String::from("Test article"),
date: String::from("12/21/2022"),
2024-01-19 17:49:12 -05:00
content,
2024-01-18 14:02:24 -05:00
})
}
2024-01-17 00:06:08 -05:00
}
}
}
2024-01-06 04:26:09 -05:00
2024-01-16 12:47:02 -05:00
// Simulate lag
use std::thread::sleep;
use std::time::Duration;
2024-01-18 14:02:24 -05:00
sleep(Duration::from_millis(300));
2024-01-16 12:47:02 -05:00
2024-01-17 00:06:08 -05:00
Ok(articles)
2024-01-06 04:26:09 -05:00
}