Skip to content

Commit

Permalink
feat: add some mdx files
Browse files Browse the repository at this point in the history
  • Loading branch information
Phosphorus-M committed Sep 19, 2023
1 parent fe2983b commit ca65be0
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 6 deletions.
6 changes: 6 additions & 0 deletions articles/bienvenido.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ los videojuegos, etc.
Rust es un lenguaje de programación de sistemas que se enfoca en la seguridad,
la velocidad y la concurrencia. Su sintaxis es similar a la de C++, pero
introduce conceptos nuevos que lo hacen más seguro y más fácil de usar.

Dejamos este video de referencia:

<center>
<youtube video="KOABboz7PBs"></youtube>
</center>
33 changes: 30 additions & 3 deletions src/components/blog_content.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
use crate::{components::icons::StrToIcon, models::article::Article};
use crate::{
components::{
icons::StrToIcon,
mdx::{
center::{Center, CenterProps},
youtube::{Youtube, YoutubeProps},
},
},
models::article::Article,
};
use leptos::*;
use leptos_mdx::mdx::{Components, Mdx};
use leptos_mdx::mdx::{Components, Mdx, MdxComponentProps};

#[component]
pub fn BlogContent(#[prop()] article: Article) -> impl IntoView {
let components = Components::new();
let mut components = Components::new();

components.add_props(
"youtube".to_string(),
Youtube,
|props: MdxComponentProps| {
let video_id = props.attributes.get("video").unwrap().clone();

YoutubeProps {
video: video_id.unwrap(),
}
},
);

components.add_props("center".to_string(), Center, |props: MdxComponentProps| {
CenterProps {
children: props.children,
}
});

view! {
<div class="group flex flex-col gap-y-6 border border-black p-6 bg-orange-100 drop-shadow-[0_0_0_rgba(0,0,0)] transition justify-between">
Expand Down
6 changes: 6 additions & 0 deletions src/components/mdx/center.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use leptos::*;

#[component]
pub fn Center(children: Children) -> impl IntoView {
view! { <div class="mx-auto">{children()}</div> }
}
2 changes: 2 additions & 0 deletions src/components/mdx/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod center;
pub mod youtube;
18 changes: 18 additions & 0 deletions src/components/mdx/youtube.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use leptos::*;

#[component]
pub fn Youtube(video: String) -> impl IntoView {
view! {
<div class="layout">
<iframe
width="560"
height="315"
src=format!("https://www.youtube.com/embed/{video}?si=mvuVOHvxBTxYOujJ")
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen
></iframe>
</div>
}
}
1 change: 1 addition & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod button_link;
pub mod header;
pub mod icons;
pub mod layout;
pub mod mdx;
37 changes: 34 additions & 3 deletions src/pages/home.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use crate::{async_component::Async, components::layout::Layout, list_articles};
use crate::{
async_component::Async,
components::{
layout::Layout,
mdx::{
center::{Center, CenterProps},
youtube::{Youtube, YoutubeProps},
},
},
list_articles,
};
use leptos::*;
use leptos_mdx::mdx::{Components, Mdx};
use leptos_mdx::mdx::{Components, Mdx, MdxComponentProps};

#[component]
pub fn Homepage() -> impl IntoView {
Expand All @@ -27,7 +37,28 @@ async fn list_of_articles() -> impl IntoView {
.map(|article| {
let binding = article.content.to_string().clone();
let description = binding.split('\n').take(3).collect::<Vec<&str>>().join("\n");
let components = Components::new();
let mut components = Components::new();
components
.add_props(
"youtube".to_string(),
Youtube,
|props: MdxComponentProps| {
let video_id = props.attributes.get("video").unwrap().clone();
YoutubeProps {
video: video_id.unwrap(),
}
},
);
components
.add_props(
"center".to_string(),
Center,
|props: MdxComponentProps| {
CenterProps {
children: props.children,
}
},
);
view! {
<li class="group flex flex-col gap-y-1 border border-black p-2 sm:p-6 hover:bg-orange-500 bg-orange-200 drop-shadow-[0_0_0_rgba(0,0,0)] hover:drop-shadow-[-4px_-4px_0_rgba(0,0,0)] transition justify-between">
<a href=format!("./articles/{}.html", article.slug)>
Expand Down

0 comments on commit ca65be0

Please sign in to comment.