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

Library page #1569

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ script/generate_opam_update_list
opam_update_list
*.bz2
*.ai
*.json
last10_updates.json
library_repos_gql.json
9 changes: 7 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ endif
pre-build: template/main.mpp template/footer.mpp \
template/front_code_snippet.html template/learn_code_snippet.html \
script/breadcrumb script/translations \
script/code_top script/ocamltohtml script/rss2html script/weekly_news \
script/code_top script/ocamltohtml script/rss2html script/libraries script/weekly_news \
script/lang_of_filename script/translate script/link_of_lang \
opam_update_list $(OMD_PP)

Expand Down Expand Up @@ -72,6 +72,11 @@ script/rss2html: script/rss2html.ml script/http.ml $(UTILS_DEP)
$(OCAMLOPT) -package cohttp-lwt-unix,netstring,syndic \
-thread -linkpkg utils.cmx http.ml rss2html.ml -o ../"$@"

script/libraries: script/libraries.ml script/http.ml $(UTILS_DEP)
cd script && \
$(OCAMLOPT) -package cohttp-lwt-unix,netstring,ezjsonm, \
-thread -linkpkg utils.cmx http.ml libraries.ml -o ../"$@"

script/weekly_news: script/weekly_news.ml script/http.ml $(UTILS_DEP)
cd script && \
$(OCAMLOPT) -package cohttp-lwt-unix,netstring,syndic \
Expand Down Expand Up @@ -120,7 +125,7 @@ script/%.cmi script/%.cmo: script/%.ml

TRASH += template/front_code_snippet.html opam_update_list \
$(addprefix script/, generate_opam_update_list lang_of_filename translate \
link_of_lang breadcrumb rss2html ocamltohtml md_preprocess \
link_of_lang breadcrumb rss2html libraries ocamltohtml md_preprocess \
code_top relative_urls translations )

.PHONY: pre-build
5 changes: 5 additions & 0 deletions library_repos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{"link": "https://api.github.com/repos/ocaml/ocaml"},
{"link": "https://api.github.com/repos/ocaml/dune"},
{"link": "https://api.github.com/repos/ocaml/merlin"}
]
Binary file added script/libraries
Binary file not shown.
128 changes: 128 additions & 0 deletions script/libraries.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
open Nethtml
open Ezjsonm

type html = Nethtml.document list

let get_string key l =
match List.assoc key l with
| `String s -> s
| _ ->
raise Not_found

let library_html (link) =
try
let repo_data = Http.get link in
let json = Ezjsonm.value_from_string repo_data in
match json with
| `O link ->
let name = Ezjsonm.get_string (find json ["name"]) in
let html_url = Ezjsonm.get_string (find json ["html_url"]) in
let updated_at = Ezjsonm.get_string (find json ["updated_at"]) in
let description = Ezjsonm.get_string (find json ["description"]) in
let stargazers_count = Ezjsonm.get_int (find json ["stargazers_count"]) in
let stargazers_count = string_of_int stargazers_count in
let forks_count = Ezjsonm.get_int (find json ["forks_count"]) in
let forks_count = string_of_int forks_count in
let open_issues_count = Ezjsonm.get_int (find json ["open_issues_count"]) in
let open_issues_count = string_of_int open_issues_count in
let elem =
[Data "\n";
Element("section", ["class", "lib"],
[Element("div", ["class", "lib-details"],
[Element("h2", [], [Data name]);
Element("p", [], [Data description]);
Element("div", ["class", "lib-details2"],
[Element("a", ["href", html_url; "target", "_BLANK"],
[Element("i", ["class", "fa fa-github"], []);
Element("span", [], [Data "Github"])]
);
Element("span", ["class", "last-updated"], [Data updated_at])]
)]
);

Element("div", ["class", "lib-data"],
[Element("div", ["class", "lib-stat"],
[Element("i", ["class", "fa fa-star"],
[Element("span", [], [Data stargazers_count])]
);
Element("i", ["class", "fa fa-exclamation-circle"],
[Element("span", [], [Data open_issues_count])]
);
Element("i", ["class", "fa fa-code-fork"],
[Element("span", [], [Data forks_count])]
)]
);
Element("div", ["class", "active-prs"],
[Element("button", ["id", "openModal"],
[Element("span", ["class", "view-prs"], [Data "View Active PRs"]);
Element("i", ["class", "fa fa-expand"], [])]
)]
)];
)];
);
Data "\n"] in
elem
| _ -> []
with
| Http.Error s ->
let elem2 = [Data "\n";
Element("h2", [], [Data s]);
Data "\n"] in
elem2

let get_repo_links =
let fh = open_in "library_repos.json" in
let json = Ezjsonm.value_from_channel fh in
close_in fh;
match json with
| `A links ->
let add_link l = function
| `O link ->
let link = get_string "link" link in
(link) :: l
| _ -> l in
List.rev(List.fold_left add_link [] links)
| _ -> []

let libraries () =
let elem = [Element("div", ["class", "libraries"], List.concat(List.map library_html get_repo_links))] in
elem

(* let modal_script =
let script =
"const openModalE = document.getElementById(openModal);
const closeModalE = document.getElementById(closeModal);
const pullRequestModalE = document.getElementById(pullRequestModal);
openModalE.addEventListener('click', () => {
pullRequestModalE.style.display = \"block\";
})
closeModalE.addEventListener('click', () => {
pullRequestModalE.style.display = \"none\";
})
window.addEventListener('click', () => {
if(event.target == pullRequestModalE) {
pullRequestModalE.style.display = \"none\";
}
})
\n" in
[Element("script", ["type", "text/javascript"], [Data script])]; *)

let () =
let action = ref `Libraries in
let specs = [
("--libraries", Arg.Unit(fun () -> action := `Libraries), " output the details of all OCaml libraries");
] in
let usage = "libraries <option>" in
Arg.parse (Arg.align specs) (fun _ -> raise(Arg.Bad "no anomynous argument")) usage;
if (!action == `Libraries) then
let out = new Netchannels.output_channel stdout in
Nethtml.write out (libraries());
out#close_out()
else (
Arg.usage specs usage;
exit 1
)

(* Local Variables: *)
(* compile-command: "make -k --no-print-directory -C .. -f Makefile.common script/libraries" *)
(* End: *)
161 changes: 161 additions & 0 deletions site/css/ocamlorg.css
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,164 @@ html.svg img.svg { display: inline; }
html.svg img.png { display: none; }

.brand img.svg { width: 131px; height: 36px; }

/* Libraries Page Styles
***********************************************************************/
/* Libraries Page Styles */
.lib {
box-shadow: 0 2.8px 2.2px rgb(0 0 0 / 3%), 0 6.7px 5.3px rgb(0 0 0 / 5%), 0 25px 50px -12px rgb(0 0 0 / 15%);
margin: 50px 0;
padding: 20px;
background-color: #f0f0f0;
display: grid;
grid-template-columns: 1fr;
grid-gap: 20px;
}
.lib-wrapper a {
text-decoration: none;
color: #000;
}
.lib-data {
display: flex;
flex-direction: column;
text-align: center;
justify-content: space-between;
align-items: center;
}
.lib-stat {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-end;
text-align: center;
}
.active-prs {
width: 100%;
display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-end;
text-align: center;
margin-top: 20px;
}
.active-prs button {
display: flex;
align-items: center;
cursor: pointer;
}
.active-prs i {
margin-left: 7px;
color: #b15b01;
font-size: 1rem;
}
.lib-stat i {
display: block;
font-size: 2rem;
color: #b15b01;
box-shadow: 0 2.8px 2.2px rgb(0 0 0 / 3%), 0 6.7px 5.3px rgb(0 0 0 / 5%), 0 25px 50px -12px rgb(0 0 0 / 15%);
margin: 0 15px;
padding: 10px 15px;
background-color: #fff;
}
.lib-stat i:first-child {
margin-left: 0;
}
.lib-stat i:last-child {
margin-right: 0;
}
.lib-stat span {
display: block;
font-size: .8rem;
font-weight: 700;
color: #000;
margin-top: 5px
}
.lib-details h2 {
font-size: 2rem;
margin: 0;
margin-bottom: 20px;
}
.lib-details p {
font-size: 1.3rem;
line-height: 1.8;
}
.lib-details2 {
display: flex;
align-items: center;
}
.lib-details2 a {
margin-right: 25px;
background-color: #b15b01;
padding: 8px 12px;
color: #fff;
border-radius: 7px;
}
.lib-details2 i {
margin-right: 10px;
color: #ccc;
font-size: 1.5rem;
}

/* Modal Styles */
.pullRequestModal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
.closeModal {
color: #aaaaaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.closeModal:hover,
.closeModal:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}

@media (min-width: 600px) {
.lib-data {
flex-direction: row;
text-align: center;
justify-content: space-between;
align-items: flex-end;
}
.lib-stat span {
font-size: 1.3rem;
}
}
@media (min-width: 980px) {
.lib {
grid-template-columns: 70% 28%;
}
.lib-data {
flex-direction: column;
}
.lib-stat,
.active-prs {
justify-content: flex-end;
align-items: flex-end;
margin-top: 0;
}
.lib-stat span {
font-size: 1.8rem;
}
}
12 changes: 12 additions & 0 deletions site/libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- ((! set title OCaml Libraries !)) ((! set packages !)) ((! set nobreadcrumb !)) -->

#OCaml Libraries

A list of the most popular and frequently updated OCaml libraries.

<div class="container">
<div class="row">

((! cmd script/libraries --libraries !))
</div>
</div>
Loading