-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow listing outside URLs in extras #2103
base: main
Are you sure you want to change the base?
Changes from all commits
639afcc
7d56189
c18894d
b873af5
a9be4ab
861d451
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,36 +18,8 @@ defmodule ExDoc.Formatter.HTML.SearchData do | |
["searchData=" | ExDoc.Utils.to_json(data)] | ||
end | ||
|
||
defp extra(map) do | ||
if custom_search_data = map[:search_data] do | ||
extra_search_data(map, custom_search_data) | ||
else | ||
Comment on lines
-22
to
-24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a clause for this rather than a conditional in the function body. |
||
{intro, sections} = extract_sections_from_markdown(map.source) | ||
|
||
intro_json_item = | ||
encode( | ||
"#{map.id}.html", | ||
map.title, | ||
:extras, | ||
intro | ||
) | ||
|
||
section_json_items = | ||
for {header, body} <- sections do | ||
encode( | ||
"#{map.id}.html##{Utils.text_to_id(header)}", | ||
header <> " - #{map.title}", | ||
:extras, | ||
body | ||
) | ||
end | ||
|
||
[intro_json_item | section_json_items] | ||
end | ||
end | ||
|
||
defp extra_search_data(map, custom_search_data) do | ||
Enum.map(custom_search_data, fn item -> | ||
defp extra(%{search_data: search_data} = map) when is_list(search_data) do | ||
Enum.map(search_data, fn item -> | ||
link = | ||
if item.anchor === "" do | ||
"#{map.id}.html" | ||
|
@@ -59,6 +31,34 @@ defmodule ExDoc.Formatter.HTML.SearchData do | |
end) | ||
end | ||
|
||
defp extra(%{url: url} = map) do | ||
[encode("#{map.id}", map.title, :extras, url)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I should have caught it the first time around, but I am thinking this likely should not show up on search? I.e. we should skip URLs here too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And let's add a test for whatever decision we pick here. :) |
||
end | ||
|
||
defp extra(map) do | ||
{intro, sections} = extract_sections_from_markdown(map.source) | ||
|
||
intro_json_item = | ||
encode( | ||
"#{map.id}.html", | ||
map.title, | ||
:extras, | ||
intro | ||
) | ||
|
||
section_json_items = | ||
for {header, body} <- sections do | ||
encode( | ||
"#{map.id}.html##{Utils.text_to_id(header)}", | ||
header <> " - #{map.title}", | ||
:extras, | ||
body | ||
) | ||
end | ||
|
||
[intro_json_item | section_json_items] | ||
end | ||
|
||
defp module(%ExDoc.ModuleNode{} = node) do | ||
{intro, sections} = extract_sections(node.doc_format, node) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,11 +111,12 @@ defmodule Mix.Tasks.Docs do | |
Markdown and plain text pages; default: "PAGES". Example: "GUIDES" | ||
|
||
* `:extras` - List of paths to additional Markdown (`.md` extension), Live Markdown | ||
(`.livemd` extension), Cheatsheets (`.cheatmd` extension) and plain text pages to | ||
add to the documentation. You can also specify keyword pairs to customize the | ||
generated filename, title and source file, and search content of each extra page; default: `[]`. Example: | ||
`["README.md", "LICENSE", "CONTRIBUTING.md": [filename: "contributing", title: "Contributing", source: "CONTRIBUTING.mdx"]]` | ||
See the Customizing Extras section for more. | ||
(`.livemd` extension), Cheatsheets (`.cheatmd` extension), external urls (`:url` option), | ||
and plain text pages to add to the documentation. You can also specify keyword pairs to | ||
customize the generated filename, title and source file, and search content of each extra page; | ||
default: `[]`. Example: `["README.md", "LICENSE", "CONTRIBUTING.md": [filename: "contributing", | ||
title: "Contributing", source: "CONTRIBUTING.mdx"]]` See the Customizing Extras section for | ||
more. | ||
|
||
* `:favicon` - Path to a favicon image file for the project. Must be PNG, JPEG or SVG. When | ||
specified, the image file will be placed in the output "assets" directory, named | ||
|
@@ -378,6 +379,7 @@ defmodule Mix.Tasks.Docs do | |
title but keep the source file unchanged. | ||
* `:search_data` - A list of terms to be indexed for autocomplete and search. If not provided, the content | ||
of the extra page will be indexed for search. See the section below for more. | ||
* `:url` - An external url to link to from the sidebar. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am thinking we could break it apart like this:
|
||
|
||
### Customizing Search Data | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,24 @@ defmodule ExDoc.Formatter.HTMLTest do | |
assert LazyHTML.text(bar_content["h1"]) == "README bar" | ||
end | ||
|
||
test "extras defined as external urls", %{tmp_dir: tmp_dir} = context do | ||
config = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add a test that shows grouping work. Imagine you want all URLs in a section in the sidebar called Important Links. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems groups expect the filename but there is none here, so we probably have to pass the filename or the url (and update its docs accordingly). |
||
doc_config(context, | ||
extras: [ | ||
"README.md", | ||
"Elixir": [url: "https://elixir-lang.org"] | ||
] | ||
) | ||
|
||
File.write!("#{tmp_dir}/README.md", "README") | ||
|
||
generate_docs(config) | ||
|
||
content = File.read!(tmp_dir <> "/html/README.html") | ||
|
||
assert content =~ "https://elixir-lang.org" | ||
end | ||
|
||
test "warns when generating an index.html file with an invalid redirect", | ||
%{tmp_dir: tmp_dir} = context do | ||
output = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add an icon, such as this one, for URLs?
If so, you can upload this bundle to remixicon.com, add external link, and get the new font back: https://github.com/elixir-lang/ex_doc/blob/main/assets/fonts/RemixIconCollection.remixicon