Skip to content

Commit c3b47a4

Browse files
committed
Fix package links with dashes in them
1 parent 8fab5e0 commit c3b47a4

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/hexdocs/data/model/route.gleam

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,7 @@ fn search_from_uri(location: Uri) {
7373
list.key_find(query, "packages")
7474
|> result.unwrap("")
7575
|> string.split(on: ",")
76-
|> list.filter_map(fn(package) {
77-
case string.split(package, ":") {
78-
[name, version] -> Ok(#(name, version))
79-
_ -> Error(Nil)
80-
}
81-
})
76+
|> list.filter_map(fn(package) { string.split_once(package, ":") })
8277
})
8378
}
8479
}

src/hexdocs/services/hexdocs.gleam

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import gleam/bool
21
import gleam/dynamic/decode
32
import gleam/fetch
43
import gleam/http
@@ -57,6 +56,13 @@ pub fn typesense_search(
5756
|> promise.map(result.map_error(_, loss.FetchError))
5857
}
5958

59+
pub fn package_path(document: Document) {
60+
case string.split_once(document.package, "-") {
61+
Ok(#(package, version)) -> package <> "/" <> version
62+
Error(Nil) -> document.package
63+
}
64+
}
65+
6066
pub fn typesense_decoder() {
6167
use results <- decode.field(
6268
"results",

src/hexdocs/view/search.gleam

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,7 @@ fn trash_button(filter: version.Package) {
506506
}
507507

508508
fn result_card(model: Model, document: hexdocs.Document) {
509-
let display_url =
510-
"/" <> string.replace(document.package, "-", "/") <> "/" <> document.ref
509+
let display_url = hexdocs.package_path(document) <> "/" <> document.ref
511510
let link_url = config.hexdocs_url() <> display_url
512511

513512
html.div([class("w-full bg-slate-100 dark:bg-slate-800 rounded-2xl p-4")], [
@@ -546,10 +545,7 @@ fn result_card(model: Model, document: hexdocs.Document) {
546545
html.ul([class("space-y-1")], {
547546
list.map(document.headers, fn(header: hexdocs.Header) {
548547
let header_display_url =
549-
"/"
550-
<> string.replace(document.package, "-", "/")
551-
<> "/"
552-
<> header.ref
548+
hexdocs.package_path(document) <> "/" <> header.ref
553549
let header_link_url = config.hexdocs_url() <> header_display_url
554550

555551
html.li(

0 commit comments

Comments
 (0)