Skip to content

Commit

Permalink
ui: add hexdocs link
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Hivert <[email protected]>
  • Loading branch information
ghivert committed May 13, 2024
1 parent 6c23337 commit c27ef89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
14 changes: 14 additions & 0 deletions apps/frontend/src/data/search_result.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import data/kind.{type Kind}
import data/metadata.{type Metadata}
import data/signature.{type Signature}
import gleam/dynamic
import gleam/function
import gleam/string

pub type SearchResult {
SearchResult(
Expand Down Expand Up @@ -48,3 +50,15 @@ pub fn decode_search_results(dyn) {
),
])(dyn)
}

pub fn hexdocs_link(search_result: SearchResult) {
let join = function.flip(string.join)
let base =
join("/", [
"https://hexdocs.pm",
search_result.package_name,
search_result.version,
search_result.module_name,
])
base <> ".html#" <> search_result.name
}
23 changes: 15 additions & 8 deletions apps/frontend/src/frontend/view/body/body.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import data/model.{type Index, type Model}
import data/msg
import data/search_result
import frontend/colors/palette
import frontend/documentation
import frontend/images
import frontend/strings as frontend_strings
import frontend/view/body/signature
import frontend/view/body/styles as s
import frontend/view/documentation
import frontend/view/types as t
import gleam/bool
import gleam/list
Expand Down Expand Up @@ -49,13 +49,20 @@ fn view_search_results(search_results: List(search_result.SearchResult)) {
|> option.map(implementations_pill)
|> option.unwrap(el.none()),
]),
s.qualified_name([], [
t.dark_white(package_id),
t.dark_white("."),
t.keyword(item.module_name),
t.dark_white("#"),
t.fun(item.name),
]),
s.qualified_name(
[
a.target("_blank"),
a.rel("noreferrer"),
a.href(search_result.hexdocs_link(item)),
],
[
t.dark_white(package_id),
t.dark_white("."),
t.keyword(item.module_name),
t.dark_white("#"),
t.fun(item.name),
],
),
]),
s.search_body([], [
s.signature([], signature.view_signature(item)),
Expand Down
3 changes: 2 additions & 1 deletion apps/frontend/src/frontend/view/body/styles.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ pub fn qualified_name(attributes, children) {
s.overflow("hidden"),
s.text_overflow("ellipsis"),
s.direction("rtl"),
s.text_decoration("none"),
])
|> s.to_lustre()
|> list.prepend(attributes, _)
|> element.element("div", _, children)
|> element.element("a", _, children)
}

pub fn search_body(attributes, children) {
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/frontend/view/documentation.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gleam/string
import lustre/attribute as a
import lustre/element/html as h

@external(javascript, "../markdown.ffi.mjs", "convert")
@external(javascript, "../../markdown.ffi.mjs", "convert")
fn converter(content: String) -> String

fn remove_leading_space(str: String) {
Expand Down

0 comments on commit c27ef89

Please sign in to comment.