fix: improvements to Algolia DocSearch (#357)

What

Changes selectors of API references to improve DocSearch results
Implements custom navigation for DocSearch in both API ref and docs. (Uses goTo method for in page navigation, Gatsby navigate for navigation within Gatsby site, changes URL's to API reference to make use of methods implemented to provide better metadata etc.)
Implements a new way to make all HTML available in API reference without need the crawler to have Javascript enabled which should allow Algolia to crawl our site faster.
Why

To provide users with a good search experience within our docs and API reference
Testing

Tested using a local setup of the Algolia crawler
This commit is contained in:
Kasper Fabricius Kristensen
2021-08-27 14:38:35 +02:00
committed by GitHub
parent 15161bb0e9
commit d89332b91a
8 changed files with 295 additions and 49 deletions

View File

@@ -1,4 +1,5 @@
import React, { useReducer } from "react"
import { checkDisplay } from "../utils/check-display"
import scrollParent from "../utils/scroll-parent"
import types from "./types"
@@ -79,10 +80,16 @@ const scrollNav = id => {
const scrollToElement = async id => {
const element = document.querySelector(`#${id}`)
if (element) {
element.scrollIntoView({
block: "start",
inline: "nearest",
})
if (checkDisplay(element)) {
element.scrollIntoView({
block: "start",
inline: "nearest",
})
} else {
setTimeout(() => {
scrollToElement(id)
}, 100)
}
} else {
setTimeout(() => {
scrollToElement(id)