Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/hexdocs/config.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ pub fn hexdocs_package_url(package: String) -> String {
"https://" <> hexdocs_package_host(package)
}

/// Documentation URL for a package at a specific version. When the version is
/// empty the version segment is omitted, linking to the latest documentation.
pub fn hexdocs_package_version_url(package: String, version: String) -> String {
case version {
"" -> hexdocs_package_url(package)
_ -> hexdocs_package_url(package) <> "/" <> version
}
}

pub fn hexpm_url() -> String {
"https://hex.pm"
}
Expand Down
8 changes: 4 additions & 4 deletions src/hexdocs/view/search.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ pub fn search(model: Model) {
case filter.status {
version.Found(ver) ->
attribute.href(
config.hexdocs_package_url(filter.name)
<> "/"
<> ver
<> "/",
config.hexdocs_package_version_url(
filter.name,
ver,
),
)
_ -> class("")
},
Expand Down
18 changes: 14 additions & 4 deletions test/hexdocs_test.gleam
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import gleeunit
import gleeunit/should
import hexdocs/config

pub fn main() {
gleeunit.main()
}

// gleeunit test functions end in `_test`
pub fn hello_world_test() {
1
|> should.equal(1)
pub fn hexdocs_package_version_url_with_version_test() {
config.hexdocs_package_version_url("phoenix", "1.7.0")
|> should.equal("https://phoenix.hexdocs.pm/1.7.0")
}

pub fn hexdocs_package_version_url_without_version_test() {
config.hexdocs_package_version_url("mix", "")
|> should.equal("https://mix.hexdocs.pm")
}

pub fn hexdocs_package_version_url_replaces_underscores_test() {
config.hexdocs_package_version_url("ex_unit", "")
|> should.equal("https://ex-unit.hexdocs.pm")
}
Loading