mirror of
https://github.com/ash-project/ash_hq.git
synced 2024-09-20 05:13:23 +12:00
4e36a93e07
improvement: search now searches hexdocs
40 lines
1.4 KiB
Elixir
40 lines
1.4 KiB
Elixir
defmodule AshHqWeb.Helpers do
|
|
@moduledoc "Simple helpers for doc liveviews"
|
|
|
|
require Logger
|
|
|
|
def latest_version(library) do
|
|
case library.versions do
|
|
[] ->
|
|
nil
|
|
|
|
versions ->
|
|
Enum.min(versions, &(Version.compare(&1.version, &2.version) != :lt))
|
|
end
|
|
end
|
|
|
|
def source_link(%AshHq.Docs.Module{file: file}, library, library_version) do
|
|
"https://github.com/#{library.repo_org}/#{library.name}/tree/v#{library_version.version}/#{file}"
|
|
end
|
|
|
|
def source_link(%AshHq.Docs.MixTask{file: file}, library, library_version) do
|
|
"https://github.com/#{library.repo_org}/#{library.name}/tree/v#{library_version.version}/#{file}"
|
|
end
|
|
|
|
def source_link(%AshHq.Docs.Function{file: file, line: line}, library, library_version) do
|
|
if line do
|
|
"https://github.com/#{library.repo_org}/#{library.name}/tree/v#{library_version.version}/#{file}#L#{line}"
|
|
else
|
|
"https://github.com/#{library.repo_org}/#{library.name}/tree/v#{library_version.version}/#{file}"
|
|
end
|
|
end
|
|
|
|
def source_link(%AshHq.Docs.Guide{route: route}, library, library_version) do
|
|
"https://github.com/#{library.repo_org}/#{library.name}/tree/v#{library_version.version}/documentation/#{route}.md"
|
|
end
|
|
|
|
def hex_link(%AshHq.Docs.Guide{route: route}, library, _library_version) do
|
|
name = route |> Path.split() |> List.last()
|
|
"https://hexdocs.pm/#{library.name}/#{name}.html"
|
|
end
|
|
end
|