mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
improvement: replace doc links in sidebar also
This commit is contained in:
parent
f21428ce4d
commit
ce64fda1e9
1 changed files with 42 additions and 0 deletions
|
@ -162,6 +162,13 @@ defmodule Mix.Tasks.Ash.ReplaceDocLinks do
|
|||
:link, %{type: "module", item: item, name_override: name, library: library}, _ ->
|
||||
~s(<a href="https://hexdocs.pm/#{library}/#{item}.html" class="no-underline">#{name || item}</a>)
|
||||
|
||||
:link, %{type: "function", item: item, name_override: name, library: library}, _ ->
|
||||
parts = String.split(item, ".")
|
||||
function = List.last(parts)
|
||||
module = parts |> :lists.droplast() |> Enum.join(".")
|
||||
|
||||
~s(<a href="https://hexdocs.pm/#{library}/#{module}.html#{function}" class="no-underline">#{name || item}</a>)
|
||||
|
||||
:link, %{type: "library", name_override: name, library: library}, _ ->
|
||||
~s(<a href="https://hexdocs.pm/#{library}">#{name || library}</a>)
|
||||
|
||||
|
@ -171,6 +178,41 @@ defmodule Mix.Tasks.Ash.ReplaceDocLinks do
|
|||
|
||||
File.write!(file, new_contents)
|
||||
end)
|
||||
|
||||
"doc/dist/*.js"
|
||||
|> Path.wildcard()
|
||||
|> Enum.filter(&String.contains?(&1, "sidebar"))
|
||||
|> Enum.each(fn file ->
|
||||
current_project = to_string(Mix.Project.config()[:app])
|
||||
|
||||
new_contents =
|
||||
file
|
||||
|> File.read!()
|
||||
|> Spark.DocIndex.render_replacements(fn
|
||||
:mix_dep, %{library: ^current_project}, _context ->
|
||||
case Version.parse(Mix.Project.config()[:version]) do
|
||||
{:ok, %Version{pre: pre, build: build}} when pre != [] or not is_nil(build) ->
|
||||
~s({:#{current_project}, "~> #{Mix.Project.config()[:version]}"})
|
||||
|
||||
{:ok, %Version{major: major, minor: minor}} ->
|
||||
~s({:#{current_project}, "~> #{major}.#{minor}"})
|
||||
|
||||
_ ->
|
||||
~s({:#{current_project}, "~> x.y.z"})
|
||||
end
|
||||
|
||||
:mix_dep, %{library: library}, _context ->
|
||||
library
|
||||
|
||||
:link, %{name_override: name, item: item}, _context ->
|
||||
name || item
|
||||
|
||||
_, %{text: text}, _ ->
|
||||
text
|
||||
end)
|
||||
|
||||
File.write!(file, new_contents)
|
||||
end)
|
||||
end
|
||||
|
||||
def doc_indexes do
|
||||
|
|
Loading…
Reference in a new issue