This commit is contained in:
parent
aca074ef01
commit
34e81035d0
9 changed files with 208 additions and 0 deletions
35
Cargo.lock
generated
35
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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]
|
||||
|
|
68
posts/test.md
Normal file
68
posts/test.md
Normal file
|
@ -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:
|
||||
|
||||
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Test-Logo.svg/783px-Test-Logo.svg.png?20150906031702">
|
||||
|
||||
### 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"]
|
||||
```
|
|
@ -1,4 +1,8 @@
|
|||
mod components;
|
||||
pub mod models;
|
||||
|
||||
#[cfg(feature = "ssr")]
|
||||
mod server;
|
||||
|
||||
use leptos::*;
|
||||
use leptos_meta::*;
|
||||
|
|
3
src/app/models/mod.rs
Normal file
3
src/app/models/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod post;
|
||||
|
||||
pub use post::Post;
|
55
src/app/models/post.rs
Normal file
55
src/app/models/post.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
pub struct PostMetadata {
|
||||
image_path: Option<String>,
|
||||
title: String,
|
||||
date: String,
|
||||
description: String,
|
||||
project_link: Option<String>,
|
||||
}
|
||||
|
||||
pub struct Post {
|
||||
metadata: PostMetadata,
|
||||
content: String,
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(feature = "ssr")] {
|
||||
impl From<String> 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<Vec<Self>, String> {
|
||||
let files_content = super::super::server::utils::get_files_content_with_blob("posts/*.md")?;
|
||||
|
||||
let mut posts: Vec<Self> = Vec::new();
|
||||
|
||||
for (_filename, content) in files_content {
|
||||
let post = Self::from(content);
|
||||
posts.push(post);
|
||||
}
|
||||
|
||||
Ok(posts)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
src/app/server/mod.rs
Normal file
1
src/app/server/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod utils;
|
37
src/app/server/utils.rs
Normal file
37
src/app/server/utils.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
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,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();
|
||||
|
|
Loading…
Reference in a new issue