Skip to content

Commit

Permalink
Deleted the old tags (filtered by institution) and targeted the new t…
Browse files Browse the repository at this point in the history
…ag that I added in `data/planet-source.yml`
  • Loading branch information
Zineb-Ada committed Jul 31, 2023
1 parent fa11bb1 commit 1eb8982
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/ocamlorg_data/data.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ module Planet = struct
include Planet

let all_tags =
"all"
:: List.sort_uniq compare (List.concat_map (fun item -> item.tags) all)
List.sort_uniq compare
(List.map (fun (item : Planet.t) -> item.source.tag) all)

let featured = List.filter (fun x -> x.featured) all
let get_by_slug slug = List.find_opt (fun x -> String.equal slug x.slug) all
Expand Down
3 changes: 1 addition & 2 deletions src/ocamlorg_data/data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ end

module Planet : sig
module Source : sig
type t = { id : string option; name : string; url : string }
type t = { id : string option; name : string; url : string; tag : string }
end

type t = {
Expand All @@ -278,7 +278,6 @@ module Planet : sig
preview_image : string option;
featured : bool;
body_html : string;
tags : string list;
}

val all_tags : string list
Expand Down
4 changes: 2 additions & 2 deletions src/ocamlorg_frontend/pages/blog.eml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Layout.render
~canonical:(Url.blog ^ if planet_page = 1 then "" else "?p=" ^ string_of_int planet_page)
~active_top_nav_item:Header.Blog @@
<div class="bg-default dark:bg-dark-default py-10">
<div class="container-fluid wide" x-data="{ tags: 'All' }">
<div class="container-fluid wide" x-data="{ tag: 'All' }">
<h1 class="sr-only">OCaml Blog</h1>

<div class="grid grid-cols-1 md:grid-cols-3 gap-16">
Expand Down Expand Up @@ -93,4 +93,4 @@ Layout.render
</div>
</div>
</div>
</div>
</div>
5 changes: 2 additions & 3 deletions src/ocamlorg_web/lib/handler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ let blog req =
let filtred_items_by_tags =
if filter = "all" then Data.Planet.all
else
List.filter
(fun item -> List.mem filter item.Data.Planet.tags)
Data.Planet.all
Data.Planet.all
|> List.filter (fun (item : Data.Planet.t) -> filter = item.source.tag)
in
let page, number_of_pages, current_items =
paginate ~req ~n:10
Expand Down
15 changes: 7 additions & 8 deletions tool/ood-gen/lib/planet.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Source = struct
type t = { id : string option; name : string; url : string }
type t = { id : string option; name : string; url : string; tag : string }
[@@deriving yaml, show { with_path = false }]

type sources = t list [@@deriving yaml]
Expand Down Expand Up @@ -34,11 +34,10 @@ type t = {
preview_image : string option;
featured : bool;
body_html : string;
tags : string list;
}
[@@deriving
stable_record ~version:metadata ~modify:[ featured; source ]
~remove:[ slug; body_html; tags ],
~remove:[ slug; body_html ],
show { with_path = false }]

let all_sources = Source.all ()
Expand Down Expand Up @@ -66,6 +65,7 @@ let decode (path, (head, body)) =
id = Some "ocamlorg";
name = "OCaml.org Blog";
url = "https://ocaml.org/blog";
tag = "all";
}
else failwith ("No source found for: " ^ path))
| _ ->
Expand All @@ -74,10 +74,9 @@ let decode (path, (head, body)) =
^ " but there path is not long enough (should start with \
data/SOURCE_NAME/...)")
in
let tags = [ List.nth (String.split_on_char '/' path) 1 ] in
metadata
|> Result.map_error (fun (`Msg m) -> `Msg ("In " ^ path ^ ": " ^ m))
|> Result.map (of_metadata ~source ~body_html ~tags)
|> Result.map (of_metadata ~source ~body_html)

let all () =
Utils.map_files decode "planet/*/*.md"
Expand All @@ -94,7 +93,7 @@ let template () =
Format.asprintf
{|
module Source = struct
type t = { id : string option; name : string; url : string }
type t = { id : string option; name : string; url : string; tag : string }
end

type t =
Expand All @@ -108,7 +107,6 @@ type t =
; preview_image : string option
; featured : bool
; body_html : string
;tags : string list;
}

let all = %a
Expand Down Expand Up @@ -234,7 +232,8 @@ module Scraper = struct
let scrape () =
let sources = Source.all () in
sources
|> List.map (fun ({ id; url; name } : Source.t) : (string * River.source) ->
|> List.map
(fun ({ id; url; name; _ } : Source.t) : (string * River.source) ->
(Option.get id, { name; url }))
|> List.filter_map fetch_feed |> List.iter scrape_feed
end

0 comments on commit 1eb8982

Please sign in to comment.