@@ -2,6 +2,7 @@ import { debounce, qs, qsAll } from './helpers'
2
2
import { openModal } from './modal'
3
3
4
4
const HEX_DOCS_ENDPOINT = 'https://hexdocs.pm/%%'
5
+ const OTP_DOCS_ENDPOINT = 'https://www.erlang.org/doc/apps/%%'
5
6
const HEX_SEARCH_ENDPOINT = 'https://hex.pm/api/packages?search=name:%%*'
6
7
const QUICK_SWITCH_LINK_SELECTOR = '.display-quick-switch'
7
8
const QUICK_SWITCH_INPUT_SELECTOR = '#quick-switch-input'
@@ -10,7 +11,46 @@ const QUICK_SWITCH_RESULT_SELECTOR = '.quick-switch-result'
10
11
const DEBOUNCE_KEYPRESS_TIMEOUT = 300
11
12
const NUMBER_OF_SUGGESTIONS = 9
12
13
13
- // Core elixir packages to include in the autocomplete results
14
+ const OTP_APPS = [
15
+ 'erts' ,
16
+ 'asn1' ,
17
+ 'common_test' ,
18
+ 'compiler' ,
19
+ 'crypto' ,
20
+ 'debugger' ,
21
+ 'dialyzer' ,
22
+ 'diameter' ,
23
+ 'edoc' ,
24
+ 'eldap' ,
25
+ 'erl_interface' ,
26
+ 'et' ,
27
+ 'eunit' ,
28
+ 'ftp' ,
29
+ 'inets' ,
30
+ 'jinterface' ,
31
+ 'kernel' ,
32
+ 'megaco' ,
33
+ 'mnesia' ,
34
+ 'observer' ,
35
+ 'odbc' ,
36
+ 'os_mon' ,
37
+ 'parsetools' ,
38
+ 'public_key' ,
39
+ 'reltool' ,
40
+ 'runtime_tools' ,
41
+ 'sasl' ,
42
+ 'snmp' ,
43
+ 'ssh' ,
44
+ 'ssl' ,
45
+ 'stdlib' ,
46
+ 'syntax_tools' ,
47
+ 'tftp' ,
48
+ 'tools' ,
49
+ 'wx' ,
50
+ 'xmerl'
51
+ ]
52
+
53
+ // Core Elixir/OTP packages to include in the autocomplete results
14
54
const STATIC_SEARCH_RESULTS = [
15
55
'elixir' ,
16
56
'eex' ,
@@ -19,7 +59,7 @@ const STATIC_SEARCH_RESULTS = [
19
59
'iex' ,
20
60
'logger' ,
21
61
'mix'
22
- ] . map ( name => ( { name } ) )
62
+ ] . concat ( OTP_APPS ) . map ( name => ( { name } ) )
23
63
24
64
const MIN_SEARCH_LENGTH = 2
25
65
@@ -47,7 +87,7 @@ function handleKeyDown (event) {
47
87
if ( event . key === 'Enter' ) {
48
88
const packageSlug = event . target . value
49
89
50
- quickSwitchToPackage ( packageSlug )
90
+ quickSwitchToAppDocs ( packageSlug )
51
91
event . preventDefault ( )
52
92
} else if ( event . key === 'ArrowUp' ) {
53
93
moveAutocompleteSelection ( - 1 )
@@ -74,7 +114,7 @@ function handleInput (event) {
74
114
*/
75
115
export function openQuickSwitchModal ( ) {
76
116
openModal ( {
77
- title : 'Search HexDocs package' ,
117
+ title : 'Go to package docs ' ,
78
118
body : Handlebars . templates [ 'quick-switch-modal-body' ] ( )
79
119
} )
80
120
@@ -89,27 +129,34 @@ export function openQuickSwitchModal () {
89
129
}
90
130
91
131
/**
92
- * Navigate to a package on HexDocs.
132
+ * Navigate to application docs.
133
+ *
93
134
* If an autocomplete entry is selected, it will be used instead of the input text.
94
135
*
95
- * @param {String } packageSlug The searched package name
136
+ * @param {String } name The searched application name
96
137
*/
97
- function quickSwitchToPackage ( packageSlug ) {
138
+ function quickSwitchToAppDocs ( name ) {
98
139
if ( state . selectedIdx === null ) {
99
- navigateToHexDocPackage ( packageSlug )
140
+ navigateToAppDocs ( name )
100
141
} else {
101
142
const selectedResult = state . autocompleteResults [ state . selectedIdx ]
102
- navigateToHexDocPackage ( selectedResult . name )
143
+ navigateToAppDocs ( selectedResult . name )
103
144
}
104
145
}
105
146
106
147
/**
107
- * Navigates to HexDocs of a specific package.
148
+ * Navigates to app docs.
149
+ *
150
+ * For Hex packages and Elixir apps go to hexdocs.pm. For OTP apps, erlang.org/doc.
108
151
*
109
- * @param {String } packageSlug The package name to navigate to
152
+ * @param {String } app The application name to navigate to
110
153
*/
111
- function navigateToHexDocPackage ( packageSlug ) {
112
- window . location = HEX_DOCS_ENDPOINT . replace ( '%%' , packageSlug . toLowerCase ( ) )
154
+ function navigateToAppDocs ( app ) {
155
+ if ( OTP_APPS . includes ( app . toLowerCase ( ) ) ) {
156
+ window . location = OTP_DOCS_ENDPOINT . replace ( '%%' , app . toLowerCase ( ) )
157
+ } else {
158
+ window . location = HEX_DOCS_ENDPOINT . replace ( '%%' , app . toLowerCase ( ) )
159
+ }
113
160
}
114
161
115
162
const debouncedQueryForAutocomplete = debounce ( queryForAutocomplete , DEBOUNCE_KEYPRESS_TIMEOUT )
@@ -145,7 +192,7 @@ function renderResults ({ results }) {
145
192
result . addEventListener ( 'click' , event => {
146
193
const index = result . getAttribute ( 'data-index' )
147
194
const selectedResult = state . autocompleteResults [ index ]
148
- navigateToHexDocPackage ( selectedResult . name )
195
+ navigateToAppDocs ( selectedResult . name )
149
196
} )
150
197
} )
151
198
}
0 commit comments