Skip to content

Commit

Permalink
Add meta tag configuration, closes #1874
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Mar 5, 2024
1 parent 0cacf00 commit 91d9000
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion assets/js/search-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export function focusSearchInput () {
function addEventListeners () {
const searchInput = qs(SEARCH_INPUT_SELECTOR)

if (document.querySelector('meta[name="exdoc:autocomplete"][content="off"]')) {
searchInput.addEventListener('keydown', event => {
if (event.key === 'Enter') {
handleAutocompleteFormSubmission(event)
}
})

return true
}

searchInput.addEventListener('keydown', event => {
const macOS = isMacOS()

Expand Down Expand Up @@ -117,7 +127,9 @@ function handleAutocompleteFormSubmission (event) {
if (autocompleteSuggestion) {
anchor.setAttribute('href', autocompleteSuggestion.link)
} else {
anchor.setAttribute('href', `search.html?q=${encodeURIComponent(searchInput.value)}`)
const meta = document.querySelector('meta[name="exdoc:full-text-search-url"]')
const url = meta ? meta.getAttribute('content') : 'search.html?q='
anchor.setAttribute('href', `${url}${encodeURIComponent(searchInput.value)}`)
}

anchor.click()
Expand Down

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions lib/mix/tasks/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,17 @@ defmodule Mix.Tasks.Docs do
custom group will be listed under the default "Functions" and "Callbacks"
group respectively.
## Meta-tags configuration
It is also possible to configure some of ExDoc behaviour using meta tags.
These meta tags can be inserted using `before_closing_head_tag`.
* `exdoc:autocomplete` - when set to "off", it disables autocompletion.
* `exdoc:full-text-search-url` - the URL to use when performing full text
search. The search string will be prepended to the URL as a parameter.
It defaults to ExDoc's auto-generated search page.
## Nesting
ExDoc also allows module names in the sidebar to appear nested under a given
Expand Down

0 comments on commit 91d9000

Please sign in to comment.