Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is yet category slug #2303

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ocamlorg_data/data.mli
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ module Is_ocaml_yet : sig
status : string;
description : string;
packages : package list;
slug : string;
}

type t = {
Expand Down
8 changes: 4 additions & 4 deletions src/ocamlorg_frontend/pages/is_ocaml_yet.eml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let render
=
let toc =
let category_to_toc_entry (category: Data.Is_ocaml_yet.category) =
Toc.{ href = "#" ^ Utils.slugify category.name; title = category.name; children = [] }
Toc.{ href = "#" ^ category.slug; title = category.name; children = [] }
in
List.map category_to_toc_entry meta.categories
in
Expand All @@ -31,7 +31,7 @@ Learn_layout.three_column_layout
<ul class="mt-8 px-0 font-light leading-8 text-neutral-800 text-lg flex flex-wrap gap-x-4 gap-y-1">
<% meta.categories |> List.iter (fun (category : Data.Is_ocaml_yet.category) -> %>
<li class="inline-flex m-0 whitespace-nowrap">
<a href="#<%s Utils.slugify category.name %>" class="leading-8"><span class="text-sm"><%s category.status %></span> <%s category.name %></a>
<a href="#<%s category.slug %>" class="leading-8"><span class="text-sm"><%s category.status %></span> <%s category.name %></a>
</li>
<% ); %>
</ul>
Expand All @@ -55,8 +55,8 @@ Learn_layout.three_column_layout
<div>
<h2>Details</h2>
<% meta.categories |> List.iter (fun (category : Data.Is_ocaml_yet.category) -> %>
<h3 id="<%s Utils.slugify category.name %>">
<a class="anchor" href="#<%s Utils.slugify category.name %>"></a>
<h3 id="<%s category.slug %>">
<a class="anchor" href="#<%s category.slug %>"></a>
<span class="text-base"><%s category.status %></span>
<%s category.name %>
</h3>
Expand Down
6 changes: 0 additions & 6 deletions src/ocamlorg_frontend/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,3 @@ let human_date_of_timestamp t =
let host_of_uri uri =
let uri = Uri.of_string uri in
Uri.host_with_default uri

let slugify value =
value
|> Str.global_replace (Str.regexp " ") "-"
|> String.lowercase_ascii
|> Str.global_replace (Str.regexp "[^a-z0-9\\-]") ""
51 changes: 29 additions & 22 deletions tool/ood-gen/lib/is_ocaml_yet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@ type external_package = { url : string; synopsis : string }
type package = { name : string; extern : external_package option }
[@@deriving of_yaml, show { with_path = false }]

type category = {
type category_meta = {
name : string;
status : string;
description : string;
packages : package list;
}
[@@deriving of_yaml, show { with_path = false }]
[@@deriving of_yaml]

type metadata = {
id : string;
question : string;
answer : string;
categories : category list;
categories : category_meta list;
}
[@@deriving of_yaml]

type category = {
name : string;
status : string;
description : string;
packages : package list;
slug : string;
}
[@@deriving
stable_record ~version:category_meta ~remove:[ slug ] ~modify:[ description ],
show { with_path = false }]

type t = {
id : string;
question : string;
Expand All @@ -28,7 +39,7 @@ type t = {
body_html : string;
}
[@@deriving
stable_record ~version:metadata ~remove:[ body_html ],
stable_record ~version:metadata ~remove:[ body_html ] ~modify:[ categories ],
show { with_path = false }]

let decode (fpath, (head, body_md)) =
Expand All @@ -38,24 +49,19 @@ let decode (fpath, (head, body_md)) =
let body_html =
Cmarkit.Doc.of_string ~strict:true body_md |> Cmarkit_html.of_doc ~safe:true
in
Result.map
(fun (metadata : metadata) ->
let categories =
List.map
(fun category ->
{
category with
description =
Cmarkit.Doc.of_string ~strict:true
(String.trim category.description)
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false;
})
metadata.categories
in
let metadata : metadata = { metadata with categories } in
of_metadata ~body_html metadata)
metadata
let modify_categories u =
let modify_description description =
Cmarkit.Doc.of_string ~strict:true (String.trim description)
|> Hilite.Md.transform
|> Cmarkit_html.of_doc ~safe:false
in
List.map
(fun cat ->
category_of_category_meta ~slug:(Utils.slugify cat.name)
~modify_description cat)
u
in
Result.map (of_metadata ~body_html ~modify_categories) metadata

let all () = Utils.map_files decode "is_ocaml_yet/*.md"

Expand All @@ -70,6 +76,7 @@ type category = {
status : string;
description : string;
packages : package list;
slug : string;
}

type t = {
Expand Down