@@ -14,6 +14,11 @@ use crate::{
14
14
} ;
15
15
use leptos_mdx:: mdx:: Mdx ;
16
16
17
+ /// # Panics
18
+ /// If no article is found with the tag "esta semana en rust", the call to `unwrap()` will panic.
19
+ /// If no article is found with the tag "anuncio de la comunidad", the second `unwrap()` will panic.
20
+ /// If the "video" attribute is missing in any `YouTube` component, the `unwrap()` inside the closure will panic.
21
+ /// If the value of the "video" attribute is None, the second `unwrap()` will also panic.
17
22
pub async fn featured_articles ( ) -> impl IntoView {
18
23
let articles = ARTICLES . read ( ) . await . clone ( ) ;
19
24
let _invalid_tags = [
@@ -24,15 +29,13 @@ pub async fn featured_articles() -> impl IntoView {
24
29
let esta_semana_en_rust = articles
25
30
. clone ( )
26
31
. into_iter ( )
27
- . filter ( |article| filter_article_by_tag ( article. clone ( ) , "esta semana en rust" . to_string ( ) ) )
32
+ . filter ( |article| filter_article_by_tag ( article, "esta semana en rust" ) )
28
33
. take ( 1 )
29
34
. collect :: < Vec < Article > > ( ) ;
30
35
let esta_semana_en_rust = esta_semana_en_rust. first ( ) . unwrap ( ) . to_owned ( ) ;
31
36
let anuncio_de_la_comunidad = articles
32
37
. into_iter ( )
33
- . filter ( |article| {
34
- filter_article_by_tag ( article. clone ( ) , "anuncio de la comunidad" . to_string ( ) )
35
- } )
38
+ . filter ( |article| filter_article_by_tag ( article, "anuncio de la comunidad" ) )
36
39
. take ( 1 )
37
40
. collect :: < Vec < Article > > ( ) ;
38
41
@@ -64,9 +67,9 @@ pub async fn featured_articles() -> impl IntoView {
64
67
}
65
68
66
69
#[ must_use]
67
- pub fn filter_article_by_tag ( article : Article , tag : String ) -> bool {
70
+ pub fn filter_article_by_tag ( article : & Article , tag : & str ) -> bool {
68
71
if let Some ( tags) = & article. tags {
69
- tags. contains ( & tag)
72
+ tags. contains ( & tag. to_string ( ) )
70
73
} else {
71
74
false
72
75
}
0 commit comments