Remove glob and move to markdowns folder
This commit is contained in:
parent
4a5e2cd99b
commit
c2df86fc33
8 changed files with 27 additions and 58 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -961,12 +961,6 @@ version = "0.28.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
|
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glob"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gloo-net"
|
name = "gloo-net"
|
||||||
version = "0.2.6"
|
version = "0.2.6"
|
||||||
|
@ -1838,7 +1832,6 @@ dependencies = [
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"console_log",
|
"console_log",
|
||||||
"futures",
|
"futures",
|
||||||
"glob",
|
|
||||||
"gloo-net 0.4.0",
|
"gloo-net 0.4.0",
|
||||||
"gray_matter",
|
"gray_matter",
|
||||||
"leptos",
|
"leptos",
|
||||||
|
|
|
@ -36,7 +36,6 @@ actix-files = { version = "0.6", optional = true }
|
||||||
actix-web = { version = "4", features = ["macros"], optional = true }
|
actix-web = { version = "4", features = ["macros"], optional = true }
|
||||||
futures = { version = "0.3", optional = true }
|
futures = { version = "0.3", optional = true }
|
||||||
simple_logger = { version = "4.2", optional = true }
|
simple_logger = { version = "4.2", optional = true }
|
||||||
glob = { version = "0.3", optional = true }
|
|
||||||
serde = { version = "1.0", optional = true }
|
serde = { version = "1.0", optional = true }
|
||||||
pulldown-cmark = { version = "0.9", optional = true } # markdown parser
|
pulldown-cmark = { version = "0.9", optional = true } # markdown parser
|
||||||
gray_matter = { version = "0.2", optional = true } # frontmatter parser
|
gray_matter = { version = "0.2", optional = true } # frontmatter parser
|
||||||
|
@ -68,7 +67,6 @@ ssr = [
|
||||||
"dep:actix-files",
|
"dep:actix-files",
|
||||||
"dep:futures",
|
"dep:futures",
|
||||||
"dep:simple_logger",
|
"dep:simple_logger",
|
||||||
"dep:glob",
|
|
||||||
"dep:serde",
|
"dep:serde",
|
||||||
"dep:pulldown-cmark",
|
"dep:pulldown-cmark",
|
||||||
"dep:gray_matter",
|
"dep:gray_matter",
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
mod components;
|
mod components;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
|
||||||
#[cfg(feature = "ssr")]
|
|
||||||
mod server;
|
|
||||||
|
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use leptos_router::*;
|
use leptos_router::*;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use serde::{Deserialize, Serialize};
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "ssr", derive(serde::Serialize, serde::Deserialize))]
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
|
||||||
pub struct PostMetadata {
|
pub struct PostMetadata {
|
||||||
image_path: Option<String>,
|
image_path: Option<String>,
|
||||||
title: String,
|
title: String,
|
||||||
|
@ -9,7 +8,8 @@ pub struct PostMetadata {
|
||||||
project_link: Option<String>,
|
project_link: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "ssr", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct Post {
|
pub struct Post {
|
||||||
metadata: PostMetadata,
|
metadata: PostMetadata,
|
||||||
content: String,
|
content: String,
|
||||||
|
@ -42,12 +42,31 @@ cfg_if::cfg_if! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
pub fn get_all() -> Result<Vec<Self>, String> {
|
pub fn get_all(folder: &str) -> Result<Vec<Self>, String> {
|
||||||
let files_content = super::super::server::utils::get_files_content_with_blob("posts/*.md")?;
|
use std::{path::Path, fs::read_dir};
|
||||||
|
|
||||||
let mut posts: Vec<Self> = Vec::new();
|
let mut posts: Vec<Self> = Vec::new();
|
||||||
|
|
||||||
for (_filename, content) in files_content {
|
let folder_path = Path::new("markdowns").join(folder);
|
||||||
|
let paths = read_dir(folder_path).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
|
for path_result in paths {
|
||||||
|
let path = match path_result {
|
||||||
|
Ok(path) => path.path(),
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{:?}", e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let content = std::fs::read_to_string(path);
|
||||||
|
let content = match content {
|
||||||
|
Ok(content) => content,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("{:?}", e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
let post = Self::from(content);
|
let post = Self::from(content);
|
||||||
posts.push(post);
|
posts.push(post);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
pub mod utils;
|
|
|
@ -1,37 +0,0 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
pub fn get_files_content_with_blob(blob: &str) -> Result<HashMap<String, String>, String> {
|
|
||||||
let mut files_content: HashMap<String, String> = HashMap::new();
|
|
||||||
|
|
||||||
use glob::glob;
|
|
||||||
|
|
||||||
for entry in glob(blob).map_err(|e| e.to_string())? {
|
|
||||||
match entry {
|
|
||||||
Ok(path) => {
|
|
||||||
if path.is_dir() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let filename = path.to_str();
|
|
||||||
let filename = match filename {
|
|
||||||
Some(filename) => filename.to_string(),
|
|
||||||
None => continue,
|
|
||||||
};
|
|
||||||
|
|
||||||
let file_content = std::fs::read_to_string(path);
|
|
||||||
let file_content = match file_content {
|
|
||||||
Ok(file_content) => file_content,
|
|
||||||
Err(e) => {
|
|
||||||
println!("{:?}", e);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
files_content.insert(filename, file_content.to_string());
|
|
||||||
},
|
|
||||||
Err(e) => println!("{:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(files_content)
|
|
||||||
}
|
|
|
@ -11,7 +11,7 @@ cfg_if! {
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
let posts = app::models::Post::get_all();
|
let posts = app::models::Post::get_all("posts");
|
||||||
for post in posts.unwrap() {
|
for post in posts.unwrap() {
|
||||||
println!("{:?}", post);
|
println!("{:?}", post);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue