Skip to content

Commit 84082aa

Browse files
cuihtlauacCuihtlauac ALVARADO
andauthored
Provide lists of featured items (#945)
Applies to books, papers and industrial users. Co-authored-by: Cuihtlauac ALVARADO <[email protected]>
1 parent c7cab97 commit 84082aa

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/ocamlorg_data/ood.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ end
77
module Book = struct
88
include Book
99

10+
let featured = all |> List.filter (fun book -> book.featured)
1011
let get_by_slug slug = List.find_opt (fun x -> String.equal slug x.slug) all
1112
end
1213

@@ -23,6 +24,7 @@ end
2324
module Industrial_user = struct
2425
include Industrial_user
2526

27+
let featured = all |> List.filter (fun user -> user.featured)
2628
let get_by_slug slug = List.find_opt (fun x -> String.equal slug x.slug) all
2729
end
2830

@@ -32,6 +34,7 @@ module Packages = Packages
3234
module Paper = struct
3335
include Paper
3436

37+
let featured = all |> List.filter (fun paper -> paper.featured)
3538
let get_by_slug slug = List.find_opt (fun x -> String.equal slug x.slug) all
3639
end
3740

src/ocamlorg_data/ood.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Book : sig
4444
}
4545

4646
val all : t list
47+
val featured : t list
4748
val get_by_slug : string -> t option
4849
end
4950

@@ -105,6 +106,7 @@ module Industrial_user : sig
105106
}
106107

107108
val all : t list
109+
val featured : t list
108110
val get_by_slug : string -> t option
109111
end
110112

@@ -130,6 +132,7 @@ module Paper : sig
130132
}
131133

132134
val all : t list
135+
val featured : t list
133136
val get_by_slug : string -> t option
134137
end
135138

src/ocamlorg_web/lib/handler.ml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ let not_found _req = Dream.html ~code:404 (Ocamlorg_frontend.not_found ())
44
let index _req = Dream.html (Ocamlorg_frontend.home ())
55

66
let learn _req =
7-
let papers =
8-
Ood.Paper.all |> List.filter (fun (paper : Ood.Paper.t) -> paper.featured)
9-
in
10-
let books =
11-
Ood.Book.all |> List.filter (fun (book : Ood.Book.t) -> book.featured)
12-
in
7+
let papers = Ood.Paper.featured in
8+
let books = Ood.Book.featured in
139
let tutorials = Ood.Tutorial.all in
1410
let release = List.hd Ood.Release.all in
1511
Dream.html (Ocamlorg_frontend.learn ~papers ~books ~release ~tutorials)
@@ -32,10 +28,7 @@ let success_story req =
3228
| None -> not_found req
3329

3430
let industrial_users _req =
35-
let users =
36-
Ood.Industrial_user.all
37-
|> List.filter (fun (item : Ood.Industrial_user.t) -> item.featured)
38-
in
31+
let users = Ood.Industrial_user.featured in
3932
let success_stories = Ood.Success_story.all in
4033
Dream.html (Ocamlorg_frontend.industrial_users ~users ~success_stories)
4134

@@ -248,9 +241,7 @@ let papers req =
248241
| None -> Ood.Paper.all
249242
| Some search -> search_paper search Ood.Paper.all
250243
in
251-
let recommended_papers =
252-
Ood.Paper.all |> List.filter (fun (paper : Ood.Paper.t) -> paper.featured)
253-
in
244+
let recommended_papers = Ood.Paper.featured in
254245
Dream.html (Ocamlorg_frontend.papers ?search ~recommended_papers papers)
255246

256247
let tutorial req =

0 commit comments

Comments
 (0)