Skip to content

Commit 97edc48

Browse files
authored
Revert "feat: allow configuring custom_autocompletions list" (#2014)
1 parent 383d53a commit 97edc48

File tree

6 files changed

+14
-115
lines changed

6 files changed

+14
-115
lines changed

assets/js/autocomplete/suggestions.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ const SUGGESTION_CATEGORY = {
1818
moduleChild: 'module-child',
1919
mixTask: 'mix-task',
2020
extra: 'extra',
21-
section: 'section',
22-
custom: 'custom'
21+
section: 'section'
2322
}
2423

2524
/**
@@ -43,8 +42,7 @@ export function getSuggestions (query, limit = 8) {
4342
...findSuggestionsInTopLevelNodes(nodes.extras, query, SUGGESTION_CATEGORY.extra, 'page'),
4443
...findSuggestionsInSectionsOfNodes(nodes.modules, query, SUGGESTION_CATEGORY.section, 'module'),
4544
...findSuggestionsInSectionsOfNodes(nodes.tasks, query, SUGGESTION_CATEGORY.section, 'mix task'),
46-
...findSuggestionsInSectionsOfNodes(nodes.extras, query, SUGGESTION_CATEGORY.section, 'page'),
47-
...findSuggestionsInCustomSidebarNodes(nodes.custom || [], query, SUGGESTION_CATEGORY.custom, 'custom')
45+
...findSuggestionsInSectionsOfNodes(nodes.extras, query, SUGGESTION_CATEGORY.section, 'page')
4846
].filter(suggestion => suggestion !== null)
4947

5048
return sort(suggestions).slice(0, limit)
@@ -57,13 +55,6 @@ function findSuggestionsInTopLevelNodes (nodes, query, category, label) {
5755
return nodes.map(node => nodeSuggestion(node, query, category, label))
5856
}
5957

60-
/**
61-
* Finds suggestions in custom sidebar nodes.
62-
*/
63-
function findSuggestionsInCustomSidebarNodes (nodes, query, category, label) {
64-
return nodes.map(node => customNodeSuggestion(node, query, category, label))
65-
}
66-
6758
/**
6859
* Finds suggestions in node groups of the given parent nodes.
6960
*/
@@ -113,25 +104,7 @@ function nodeSuggestion (node, query, category, label) {
113104
description: null,
114105
matchQuality: matchQuality(node.title, query),
115106
deprecated: node.deprecated,
116-
labels: node.labels || [label],
117-
category
118-
}
119-
}
120-
121-
/**
122-
* Builds a suggestion for a custom top level node.
123-
* Returns null if the node doesn't match the query.
124-
*/
125-
function customNodeSuggestion (node, query, category, label) {
126-
if (!matchesAll(node.title, query)) { return null }
127-
128-
return {
129-
link: node.link,
130-
title: highlightMatches(node.title, query),
131-
description: node.description,
132-
matchQuality: matchQuality(node.title, query),
133-
deprecated: node.deprecated,
134-
labels: node.labels || [label],
107+
labels: [label],
135108
category
136109
}
137110
}
@@ -238,8 +211,7 @@ function categoryPriority (category) {
238211
case SUGGESTION_CATEGORY.module: return 1
239212
case SUGGESTION_CATEGORY.moduleChild: return 2
240213
case SUGGESTION_CATEGORY.mixTask: return 3
241-
case SUGGESTION_CATEGORY.custom: return 4
242-
default: return 5
214+
default: return 4
243215
}
244216
}
245217

lib/ex_doc/config.ex

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ defmodule ExDoc.Config do
1212
def skip_undefined_reference_warnings_on(_string), do: false
1313
def skip_code_autolink_to(_string), do: false
1414

15-
@type custom_autocompletion :: %{
16-
required(:link) => String.t(),
17-
required(:title) => String.t(),
18-
required(:description) => String.t(),
19-
optional(:labels) => [String.t()]
20-
}
21-
2215
defstruct annotations_for_docs: &__MODULE__.annotations_for_docs/1,
2316
api_reference: true,
2417
apps: [],
@@ -39,7 +32,6 @@ defmodule ExDoc.Config do
3932
groups_for_extras: [],
4033
groups_for_docs: [],
4134
groups_for_modules: [],
42-
custom_autocompletions: [],
4335
homepage_url: nil,
4436
language: "en",
4537
logo: nil,
@@ -71,7 +63,6 @@ defmodule ExDoc.Config do
7163
before_closing_body_tag: (atom() -> String.t()) | mfa() | map(),
7264
before_closing_footer_tag: (atom() -> String.t()) | mfa() | map(),
7365
before_closing_head_tag: (atom() -> String.t()) | mfa() | map(),
74-
custom_autocompletions: [custom_autocompletion],
7566
canonical: nil | String.t(),
7667
cover: nil | Path.t(),
7768
default_group_for_doc: (keyword() -> String.t() | nil),
@@ -123,7 +114,6 @@ defmodule ExDoc.Config do
123114
{groups_for_docs, options} = Keyword.pop(options, :groups_for_docs, [])
124115
{groups_for_extras, options} = Keyword.pop(options, :groups_for_extras, [])
125116
{groups_for_modules, options} = Keyword.pop(options, :groups_for_modules, [])
126-
{custom_autocompletions, options} = Keyword.pop(options, :custom_autocompletions, [])
127117

128118
{skip_undefined_reference_warnings_on, options} =
129119
Keyword.pop(
@@ -141,7 +131,6 @@ defmodule ExDoc.Config do
141131
end)
142132

143133
preconfig = %__MODULE__{
144-
custom_autocompletions: normalize_custom_autocompletions(custom_autocompletions),
145134
filter_modules: normalize_filter_modules(filter_modules),
146135
groups_for_docs: normalize_groups(groups_for_docs),
147136
groups_for_extras: normalize_groups(groups_for_extras),
@@ -166,12 +155,6 @@ defmodule ExDoc.Config do
166155
struct(preconfig, options)
167156
end
168157

169-
defp normalize_custom_autocompletions(custom_autocompletions) do
170-
Enum.map(custom_autocompletions, fn autocompletion ->
171-
Map.new(autocompletion)
172-
end)
173-
end
174-
175158
defp normalize_output(output) do
176159
String.trim_trailing(output, "/")
177160
end

lib/ex_doc/formatter/html.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ defmodule ExDoc.Formatter.HTML do
183183
end
184184

185185
defp generate_sidebar_items(nodes_map, extras, config) do
186-
content =
187-
Templates.create_sidebar_items(nodes_map, extras, config.custom_autocompletions || [])
188-
186+
content = Templates.create_sidebar_items(nodes_map, extras)
189187
path = "dist/sidebar_items-#{digest(content)}.js"
190188
File.write!(Path.join(config.output, path), content)
191189
[path]

lib/ex_doc/formatter/html/templates.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,12 @@ defmodule ExDoc.Formatter.HTML.Templates do
7070
@doc """
7171
Create a JS object which holds all the items displayed in the sidebar area
7272
"""
73-
def create_sidebar_items(nodes_map, extras, custom_autocompletions \\ []) do
73+
def create_sidebar_items(nodes_map, extras) do
7474
nodes =
7575
nodes_map
7676
|> Enum.map(&sidebar_module/1)
7777
|> Map.new()
7878
|> Map.put(:extras, sidebar_extras(extras))
79-
|> Map.put(:custom, custom_autocompletions)
8079

8180
["sidebarNodes=" | ExDoc.Utils.to_json(nodes)]
8281
end

lib/mix/tasks/docs.ex

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ defmodule Mix.Tasks.Docs do
102102
the "assets" directory in the output path under the name "cover" and the
103103
appropriate extension. This option has no effect when using the "html" formatter.
104104
105-
* `:custom_autocompletions` - A list of maps or keywords representing custom autocomplete
106-
results that will appear in the search. See the "Customizing Search" section below for more.
107-
108105
* `:deps` - A keyword list application names and their documentation URL.
109106
ExDoc will by default include all dependencies and assume they are hosted on
110107
HexDocs. This can be overridden by your own values. Example: `[plug: "https://myserver/plug/"]`
@@ -156,8 +153,7 @@ defmodule Mix.Tasks.Docs do
156153
May be overridden by command line argument.
157154
158155
* `:redirects` - A map or list of tuples, where the key is the path to redirect from and the
159-
value is the path to redirect to. The extension is omitted in both cases, i.e `%{"old-readme" => "readme"}`.
160-
See the "Changing documentation over time" section below for more.
156+
value is the path to redirect to. The extension is omitted in both cases, i.e `%{"old-readme" => "readme"}`
161157
162158
* `:skip_undefined_reference_warnings_on` - ExDoc warns when it can't create a `Mod.fun/arity`
163159
reference in the current project docs e.g. because of a typo. This list controls where to
@@ -343,12 +339,14 @@ defmodule Mix.Tasks.Docs do
343339
344340
## Changing documentation over time
345341
346-
As your project grows, your documentation may very likely change, even structurally. There are a few important things to consider in this regard:
342+
As your project grows, your documentation may very likely change, even structurally.
343+
There are a few important things to consider in this regard:
347344
348-
- Links to your *extras* will break if you change or move file names.
349-
- Links to your *modules, and mix tasks* will change if you change their name.
350-
- Links to *functions* are actually links to modules with anchor links. If you change the function name, the link does
351-
not break but will leave users at the top of the module's documentation.
345+
* Links to your *extras* will break if you change or move file names.
346+
* Links to your *modules, and mix tasks* will change if you change their name.
347+
* Links to *functions* are actually links to modules with anchor links.
348+
If you change the function name, the link does not break but will leave users
349+
at the top of the module's documentation.
352350
353351
Because these docs are static files, the behavior of a missing page will depend on where they are hosted.
354352
In particular, [hexdocs.pm](https://hexdocs.pm) will show a 404 page.
@@ -363,29 +361,6 @@ defmodule Mix.Tasks.Docs do
363361
"get-started" => "quickstart"
364362
}
365363
366-
## Customizing Search
367-
368-
In ExDoc, there are two kinds of searches. There is the "autocomplete", which is what shows up when you type in the top search bar,
369-
and "search" which is the separate page with results that you arrive at if you submit the search bar without selecting an autocompleted
370-
item. Currently, only the autocompletions are customizable.
371-
372-
You can add to the available autocompletions by specifying the `custom_autocompletions` option. This must be a list of
373-
maps or keyword lists with the following shape:
374-
375-
custom_autocompletions: [
376-
%{
377-
link: "a-page.html#anchor",
378-
title: "custom-text",
379-
description: "Some Custom Text",
380-
labels: ["Text"]
381-
}
382-
]
383-
384-
- `link` is expected to be a relative link to a page in your documentation. You may user anchor links.
385-
- `title` is the term that will be searched, and what will be shown as the primary text in the search result.
386-
- `description` is text that will be shown below the search result
387-
- `labels` will be shown as badges next to that content.
388-
389364
## Umbrella project
390365
391366
ExDoc can be used in an umbrella project and generates a single documentation

test/ex_doc/formatter/html_test.exs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -592,34 +592,6 @@ defmodule ExDoc.Formatter.HTMLTest do
592592
] = Jason.decode!(content)["extras"]
593593
end
594594

595-
test "custom autocompletions can be added", %{tmp_dir: tmp_dir} = context do
596-
generate_docs(
597-
doc_config(context,
598-
source_beam: "unknown",
599-
extras: [],
600-
custom_autocompletions: [
601-
%{
602-
link: "a-page.html#anchor",
603-
title: "custom-text",
604-
description: "Some Custom Text",
605-
labels: ["Text"]
606-
}
607-
]
608-
)
609-
)
610-
611-
"sidebarNodes=" <> content = read_wildcard!(tmp_dir <> "/html/dist/sidebar_items-*.js")
612-
613-
assert [
614-
%{
615-
"link" => "a-page.html#anchor",
616-
"title" => "custom-text",
617-
"description" => "Some Custom Text",
618-
"labels" => ["Text"]
619-
}
620-
] = Jason.decode!(content)["custom"]
621-
end
622-
623595
test "containing settext headers while discarding links on header",
624596
%{tmp_dir: tmp_dir} = context do
625597
generate_docs(

0 commit comments

Comments
 (0)