diff --git a/Cargo.lock b/Cargo.lock
index 1831ba7..9154e24 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -933,6 +933,15 @@ dependencies = [
"version_check",
]
+[[package]]
+name = "getopts"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5"
+dependencies = [
+ "unicode-width",
+]
+
[[package]]
name = "getrandom"
version = "0.2.11"
@@ -952,6 +961,12 @@ version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0"
+[[package]]
+name = "glob"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
+
[[package]]
name = "gloo-net"
version = "0.2.6"
@@ -1805,6 +1820,7 @@ dependencies = [
"console_error_panic_hook",
"console_log",
"futures",
+ "glob",
"gloo-net 0.4.0",
"leptos",
"leptos_actix",
@@ -1812,6 +1828,7 @@ dependencies = [
"leptos_meta",
"leptos_router",
"log",
+ "pulldown-cmark",
"simple_logger",
"wasm-bindgen",
]
@@ -1914,6 +1931,18 @@ dependencies = [
"syn 1.0.109",
]
+[[package]]
+name = "pulldown-cmark"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77a1a2f1f0a7ecff9c31abbe177637be0e97a0aef46cf8738ece09327985d998"
+dependencies = [
+ "bitflags 1.3.2",
+ "getopts",
+ "memchr",
+ "unicase",
+]
+
[[package]]
name = "quote"
version = "1.0.33"
@@ -2665,6 +2694,12 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
+[[package]]
+name = "unicode-width"
+version = "0.1.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
+
[[package]]
name = "unicode-xid"
version = "0.2.4"
diff --git a/Cargo.toml b/Cargo.toml
index dccdc06..f1c93af 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -36,6 +36,8 @@ actix-files = { version = "0.6", optional = true }
actix-web = { version = "4", features = ["macros"], optional = true }
futures = { version = "0.3", optional = true }
simple_logger = { version = "4.2", optional = true }
+pulldown-cmark = { version = "0.9", optional = true }
+glob = { version = "0.3", optional = true }
[features]
default = ["csr"]
@@ -64,6 +66,8 @@ ssr = [
"dep:actix-files",
"dep:futures",
"dep:simple_logger",
+ "dep:pulldown-cmark",
+ "dep:glob",
]
[package.metadata.cargo-all-features]
diff --git a/posts/test.md b/posts/test.md
new file mode 100644
index 0000000..02bb163
--- /dev/null
+++ b/posts/test.md
@@ -0,0 +1,68 @@
+---
+image_path: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Test-Logo.svg/783px-Test-Logo.svg.png?20150906031702"
+title: Testing layout
+date: 2023-11-26
+description: Testing the layout of the site.
+project_link: none
+---
+
+### Heading Tags
+
+# Heading 1
+## Heading 2
+### Heading 3
+#### Heading 4
+##### Heading 5
+###### Heading 6
+
+This is a paragraph tag. It's used for displaying text content.
+
+[Click me to visit Example website!](https://www.example.com)
+
+Unordered list
+
+* Item 1
+* Item 2
+* Item 3
+
+Ordered list
+
+1. Item 1
+2. Item 2
+3. Item 3
+
+
+> It's probably important that images look okay here by default as well:
+
+
+
+### Code Blocks
+
+```python
+def hello_world():
+ print("Hello World!")
+```
+
+```rust
+fn main() {
+ println!("Hello World!");
+}
+```
+
+```javascript
+function helloWorld() {
+ console.log("Hello World!");
+}
+```
+
+```ruby
+def hello_world
+ puts "Hello World!"
+end
+```
+
+```dockerfile
+FROM rust
+RUN cargo build --release
+CMD ["./target/release/hello_world"]
+```
diff --git a/src/app/mod.rs b/src/app/mod.rs
index fc1abbc..4bb3261 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -1,4 +1,8 @@
mod components;
+pub mod models;
+
+#[cfg(feature = "ssr")]
+mod server;
use leptos::*;
use leptos_meta::*;
diff --git a/src/app/models/mod.rs b/src/app/models/mod.rs
new file mode 100644
index 0000000..40d1b51
--- /dev/null
+++ b/src/app/models/mod.rs
@@ -0,0 +1,3 @@
+mod post;
+
+pub use post::Post;
\ No newline at end of file
diff --git a/src/app/models/post.rs b/src/app/models/post.rs
new file mode 100644
index 0000000..f95905f
--- /dev/null
+++ b/src/app/models/post.rs
@@ -0,0 +1,55 @@
+pub struct PostMetadata {
+ image_path: Option,
+ title: String,
+ date: String,
+ description: String,
+ project_link: Option,
+}
+
+pub struct Post {
+ metadata: PostMetadata,
+ content: String,
+}
+
+cfg_if::cfg_if! {
+ if #[cfg(feature = "ssr")] {
+ impl From for Post {
+ fn from(content: String) -> Self {
+ use pulldown_cmark::{Parser, Options, html};
+
+ let parser = Parser::new_ext(&content, Options::all());
+
+ let mut html_output = String::new();
+ html::push_html(&mut html_output, parser);
+ println!("\nHTML output:\n{}\n", &html_output);
+
+ Self {
+ metadata: PostMetadata {
+ image_path: None,
+ title: String::from(""),
+ date: String::from(""),
+ description: String::from(""),
+ project_link: None,
+ },
+ content: html_output,
+ }
+ }
+ }
+
+ impl Post {
+ pub fn get_all() -> Result, String> {
+ let files_content = super::super::server::utils::get_files_content_with_blob("posts/*.md")?;
+
+ let mut posts: Vec = Vec::new();
+
+ for (_filename, content) in files_content {
+ let post = Self::from(content);
+ posts.push(post);
+ }
+
+ Ok(posts)
+ }
+ }
+ }
+}
+
diff --git a/src/app/server/mod.rs b/src/app/server/mod.rs
new file mode 100644
index 0000000..fab870e
--- /dev/null
+++ b/src/app/server/mod.rs
@@ -0,0 +1 @@
+pub mod utils;
\ No newline at end of file
diff --git a/src/app/server/utils.rs b/src/app/server/utils.rs
new file mode 100644
index 0000000..77f6157
--- /dev/null
+++ b/src/app/server/utils.rs
@@ -0,0 +1,37 @@
+use std::collections::HashMap;
+
+pub fn get_files_content_with_blob(blob: &str) -> Result, String> {
+ let mut files_content: HashMap = 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)
+}
\ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index a8777cb..fd3dd3a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,6 +11,7 @@ cfg_if! {
#[actix_web::main]
async fn main() -> std::io::Result<()> {
+ let _ = app::models::Post::get_all();
// Setting this to None means we'll be using cargo-leptos and its env vars.
let conf = get_configuration(None).await.unwrap();