Skip to content

Commit

Permalink
Add a link to the opam file on the package overview page (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmattio authored Jan 6, 2023
1 parent 9f90518 commit 966e1b6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
76 changes: 45 additions & 31 deletions src/ocamlorg_frontend/pages/package_overview.eml
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@ Package_layout.render
</button>
</div>
</div>
<div class="mt-4">
<% homepages |> List.iter (fun homepage -> %>
<a href="<%s homepage %>" class="text-primary-600 hover:underline">
<%s homepage %>
<svg
xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 ml-2 inline-block -mt-1" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
</svg>
</a>
<br />
<% ); %>
</div>
<% (match documentation_status with
| `Success -> %>
<div class="mt-4"><a class="btn btn-sm" href="<%s Url.package_doc package.name package.version %>">Documentation</a></div>
<% | `Unknown -> ( %><a href="<%s Url.package_doc package.name package.version %>" class="p-4 mt-4 flex gap-x-2 bg-background-default text-gray-600 font-semibold text-base">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#4b5563"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M15.32 3H8.68c-.26 0-.52.11-.7.29L3.29 7.98c-.18.18-.29.44-.29.7v6.63c0 .27.11.52.29.71l4.68 4.68c.19.19.45.3.71.3h6.63c.27 0 .52-.11.71-.29l4.68-4.68c.19-.19.29-.44.29-.71V8.68c0-.27-.11-.52-.29-.71l-4.68-4.68c-.18-.18-.44-.29-.7-.29zM12 17.3c-.72 0-1.3-.58-1.3-1.3s.58-1.3 1.3-1.3 1.3.58 1.3 1.3-.58 1.3-1.3 1.3zm0-4.3c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1s1 .45 1 1v4c0 .55-.45 1-1 1z"/></svg>
Documentation status is unknown. Sorry about that.</a><% )
| `Failure -> ( %><a href="<%s Url.package_doc package.name package.version %>" class="p-4 mt-4 flex gap-x-2 bg-background-default text-gray-600 font-semibold text-base">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#4b5563"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M15.32 3H8.68c-.26 0-.52.11-.7.29L3.29 7.98c-.18.18-.29.44-.29.7v6.63c0 .27.11.52.29.71l4.68 4.68c.19.19.45.3.71.3h6.63c.27 0 .52-.11.71-.29l4.68-4.68c.19-.19.29-.44.29-.71V8.68c0-.27-.11-.52-.29-.71l-4.68-4.68c-.18-.18-.44-.29-.7-.29zM12 17.3c-.72 0-1.3-.58-1.3-1.3s.58-1.3 1.3-1.3 1.3.58 1.3 1.3-.58 1.3-1.3 1.3zm0-4.3c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1s1 .45 1 1v4c0 .55-.45 1-1 1z"/></svg>
Documentation failed to build! Sorry about that.</a><% ));%>
<% (match package.tags with [] -> () | _ -> %>
<div class="mt-4">
<div class="flex mt-5 flex-wrap">
Expand All @@ -87,17 +64,42 @@ Package_layout.render
</div>
</div>
<% ); %>
<div class="mt-8">
<dt class="font-semibold text-base text-body-400">Published</dt>
<dd class="mt-3 text-sm text-gray-900">
<%s Utils.human_date_of_timestamp package.publication %>
</dd>
</div>
<div class="flex flex-col mt-9 space-y-4 text-body-400">
<% (match documentation_status with
| `Success -> %>
<a href="<%s Url.package_doc package.name package.version %>" class="flex items-center text-primary-600 font-bold hover:underline mb-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2 inline-block" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 6.042A8.967 8.967 0 006 3.75c-1.052 0-2.062.18-3 .512v14.25A8.987 8.987 0 016 18c2.305 0 4.408.867 6 2.292m0-14.25a8.966 8.966 0 016-2.292c1.052 0 2.062.18 3 .512v14.25A8.987 8.987 0 0018 18a8.967 8.967 0 00-6 2.292m0-14.25v14.25" />
</svg>
Documentation
</a>
<% | `Unknown -> ( %>
<a href="<%s Url.package_doc package.name package.version %>" class="p-4 flex gap-x-2 bg-background-default text-gray-600 font-semibold text-base">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#4b5563">
<path d="M0 0h24v24H0V0z" fill="none"/>
<path d="M15.32 3H8.68c-.26 0-.52.11-.7.29L3.29 7.98c-.18.18-.29.44-.29.7v6.63c0 .27.11.52.29.71l4.68 4.68c.19.19.45.3.71.3h6.63c.27 0 .52-.11.71-.29l4.68-4.68c.19-.19.29-.44.29-.71V8.68c0-.27-.11-.52-.29-.71l-4.68-4.68c-.18-.18-.44-.29-.7-.29zM12 17.3c-.72 0-1.3-.58-1.3-1.3s.58-1.3 1.3-1.3 1.3.58 1.3 1.3-.58 1.3-1.3 1.3zm0-4.3c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1s1 .45 1 1v4c0 .55-.45 1-1 1z"/>
</svg>
Documentation status is unknown.
</a><% )
| `Failure -> ( %>
<a href="<%s Url.package_doc package.name package.version %>" class="p-4 flex gap-x-2 bg-background-default text-gray-600 font-semibold text-base">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#4b5563">
<path d="M0 0h24v24H0V0z" fill="none"/>
<path d="M15.32 3H8.68c-.26 0-.52.11-.7.29L3.29 7.98c-.18.18-.29.44-.29.7v6.63c0 .27.11.52.29.71l4.68 4.68c.19.19.45.3.71.3h6.63c.27 0 .52-.11.71-.29l4.68-4.68c.19-.19.29-.44.29-.71V8.68c0-.27-.11-.52-.29-.71l-4.68-4.68c-.18-.18-.44-.29-.7-.29zM12 17.3c-.72 0-1.3-.58-1.3-1.3s.58-1.3 1.3-1.3 1.3.58 1.3 1.3-.58 1.3-1.3 1.3zm0-4.3c-.55 0-1-.45-1-1V8c0-.55.45-1 1-1s1 .45 1 1v4c0 .55-.45 1-1 1z"/>
</svg>
Documentation failed to build.
</a><% ));%>
<% homepages |> List.iter (fun homepage -> %>
<a href="<%s homepage %>" class="flex items-center hover:text-primary-600">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2 inline-block" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244" />
</svg>
<%s Utils.host_of_uri homepage %>
</a>
<% ); %>
<% (match changes_filename with Some changes_filename -> %>
<a href="<%s Url.package_doc package.name package.version ~page:(changes_filename ^ ".html") %>" class="flex items-center hover:text-primary-600">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2 inline-block" fill="none" viewBox="0 0 24 24"
stroke="currentColor">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2 inline-block" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
Expand All @@ -114,6 +116,18 @@ Package_layout.render
<%s package.license %> License
</a>
<% | _ -> ()); %>
<a href="<%s Url.github_opam_file package.name package.version %>" class="flex items-center hover:text-primary-600">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-2 inline-block" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10" />
</svg>
Edit opam file
</a>
</div>
<div class="mt-8">
<dt class="font-semibold text-base text-body-400">Published</dt>
<dd class="mt-3 text-sm text-gray-900">
<%s Utils.human_date_of_timestamp package.publication %>
</dd>
</div>
<div class="mt-8">
<dt class="font-semibold text-base text-body-400">Authors</dt>
Expand Down
5 changes: 5 additions & 0 deletions src/ocamlorg_frontend/url.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ let installer = "/install-platform.sh"

let github_installer =
"https://github.com/tarides/ocaml-platform-installer/releases/latest/download/installer.sh"

let github_opam_file package_name package_version =
Printf.sprintf
"https://github.com/ocaml/opam-repository/blob/master/packages/%s/%s.%s/opam"
package_name package_name package_version
4 changes: 4 additions & 0 deletions src/ocamlorg_frontend/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ let human_date_of_timestamp t =
let open Timedesc in
let ts = Timestamp.of_float_s t in
Format.asprintf "%a" (Timestamp.pp ~format:"{day:0X} {mon:Xxx} {year}" ()) ts

let host_of_uri uri =
let uri = Uri.of_string uri in
Uri.host_with_default uri

0 comments on commit 966e1b6

Please sign in to comment.