docs: add algolia to 404

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6655
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
GitOrigin-RevId: b174efd44e4e50517ef4c3d4d023c00cb4d674f1
This commit is contained in:
Rob Dominguez 2022-11-03 14:44:52 -05:00 committed by hasura-bot
parent 1f4a54347c
commit 79b58d4e7e
6 changed files with 277 additions and 34 deletions

View File

@ -20,6 +20,7 @@
"@docusaurus/core": "^2.0.0-beta.18",
"@docusaurus/preset-classic": "^2.0.0-beta.18",
"@mdx-js/react": "^1.6.21",
"algoliasearch": "^4.14.2",
"algoliasearch-helper": "^3.7.4",
"clsx": "^1.1.1",
"docusaurus-plugin-sass": "^0.2.2",

View File

@ -1,14 +1,54 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React from 'react';
import React, { useEffect, useState } from 'react';
import Layout from '@theme/Layout';
import Translate, {translate} from '@docusaurus/Translate';
import {PageMetadata} from '@docusaurus/theme-common';
import Translate, { translate } from '@docusaurus/Translate';
import { PageMetadata } from '@docusaurus/theme-common';
import ThemedImage from '@theme/ThemedImage';
import { useLocation } from '@docusaurus/router';
import algoliasearch from 'algoliasearch';
import styles from './styles.module.scss';
import Light404 from '@site/static/img/light-404.png';
import Dark404 from '@site/static/img/dark-404.png';
export default function NotFound() {
// State for handling search results
const [searchResults, setSearchResults] = useState([]);
const [loading, setLoading] = useState(true);
// Algolia search initialization
const client = algoliasearch('NS6GBGYACO', '8f0f11e3241b59574c5dd32af09acdc8');
const index = client.initIndex('hasura-graphql');
// Get the current location
const location = useLocation();
// useEffect to handle search
useEffect(() => {
// Get the search query from the URL
const query = location.pathname;
// No-no words
const removeList = ['docs', 'latest', 'index'];
// Remove the no-no words from the query
const parsedQuery = query
.split('/')
.filter((word) => !removeList.includes(word))
.join(' ');
// Search
index
.search(parsedQuery, {
hitsPerPage: 5,
})
.then(({ hits }) => {
setSearchResults(hits);
setLoading(false);
})
.catch((error) => {
console.error(error);
});
}, []);
return (
<>
<PageMetadata
@ -18,31 +58,40 @@ export default function NotFound() {
})}
/>
<Layout>
<main className="container margin-vert--xl">
<div className="row">
<div className="col col--6 col--offset-3">
<h1 className="hero__title">
<Translate
id="theme.NotFound.title"
description="The title of the 404 page">
Page Not Found
</Translate>
</h1>
<p>
<Translate
id="theme.NotFound.p1"
description="The first paragraph of the 404 page">
We could not find what you were looking for.
</Translate>
</p>
<p>
<Translate
id="theme.NotFound.p2"
description="The 2nd paragraph of the 404 page">
Please contact the owner of the site that linked you to the
original URL and let them know their link is broken.
</Translate>
</p>
<main className='container margin-vert--xl'>
<div className='row'>
<div className={styles['content']}>
<ThemedImage
sources={{
light: Light404,
dark: Dark404,
}}
alt='404'
/>
<div>
<h1>
<Translate id='theme.NotFound.title' description='The title of the 404 page'>
We have a broken link or the URL entered doesn't exist in our docs.
</Translate>
</h1>
<p>
<Translate id='theme.NotFound.p2' description='The 2nd paragraph of the 404 page'>
{!loading && searchResults.length > 0
? `Our team has been notified and they're on it. Is there a chance one of these links will help?`
: ``}
</Translate>
</p>
<ul className={styles['results']}>
{searchResults &&
searchResults.map((result) => (
<li key={result.objectID}>
<div>
<a href={result.url}>{result.hierarchy.lvl1}</a>
</div>
</li>
))}
</ul>
</div>
</div>
</div>
</main>

View File

@ -0,0 +1,69 @@
.content {
display: flex;
gap: 40px;
align-items: center;
padding: 2rem;
animation: fadeIn 0.5s ease-in-out;
@media (max-width: 900px) {
flex-direction: column;
}
}
.results {
display: flex;
flex-direction: column;
height: 100%;
width: 100%;
text-align: start;
padding-left: 0;
// loop to delay animation for each list item
@for $i from 1 through 10 {
li:nth-child(#{$i}) {
animation-delay: 0.15s * $i;
}
}
li {
list-style: none;
margin-bottom: 1rem;
animation-delay: 0.5s;
animation: fadeInAndShift 0.5s ease-in-out;
animation-fill-mode: both;
&:hover {
a::after {
transform: translateX(5px);
}
}
a::after {
display: inline-block;
content: '>';
margin-left: 0.5rem;
text-decoration: none;
transition: all 0.3s ease-in-out;
}
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes fadeInAndShift {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0px);
}
}
}

BIN
docs/static/img/dark-404.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
docs/static/img/light-404.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -35,6 +35,13 @@
dependencies:
"@algolia/cache-common" "4.13.0"
"@algolia/cache-browser-local-storage@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.14.2.tgz#d5b1b90130ca87c6321de876e167df9ec6524936"
integrity sha512-FRweBkK/ywO+GKYfAWbrepewQsPTIEirhi1BdykX9mxvBPtGNKccYAxvGdDCumU1jL4r3cayio4psfzKMejBlA==
dependencies:
"@algolia/cache-common" "4.14.2"
"@algolia/cache-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.12.1.tgz#d3f1676ca9c404adce0f78d68f6381bedb44cd9c"
@ -45,6 +52,11 @@
resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.13.0.tgz#27b83fd3939d08d72261b36a07eeafc4cb4d2113"
integrity sha512-f9mdZjskCui/dA/fA/5a+6hZ7xnHaaZI5tM/Rw9X8rRB39SUlF/+o3P47onZ33n/AwkpSbi5QOyhs16wHd55kA==
"@algolia/cache-common@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.14.2.tgz#b946b6103c922f0c06006fb6929163ed2c67d598"
integrity sha512-SbvAlG9VqNanCErr44q6lEKD2qoK4XtFNx9Qn8FK26ePCI8I9yU7pYB+eM/cZdS9SzQCRJBbHUumVr4bsQ4uxg==
"@algolia/cache-in-memory@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.12.1.tgz#0ef6aac2f8feab5b46fc130beb682bbd21b55244"
@ -59,6 +71,13 @@
dependencies:
"@algolia/cache-common" "4.13.0"
"@algolia/cache-in-memory@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.14.2.tgz#88e4a21474f9ac05331c2fa3ceb929684a395a24"
integrity sha512-HrOukWoop9XB/VFojPv1R5SVXowgI56T9pmezd/djh2JnVN/vXswhXV51RKy4nCpqxyHt/aGFSq2qkDvj6KiuQ==
dependencies:
"@algolia/cache-common" "4.14.2"
"@algolia/client-account@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.12.1.tgz#e838c9283db2fab32a425dd13c77da321d48fd8b"
@ -77,6 +96,15 @@
"@algolia/client-search" "4.13.0"
"@algolia/transporter" "4.13.0"
"@algolia/client-account@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.14.2.tgz#b76ac1ba9ea71e8c3f77a1805b48350dc0728a16"
integrity sha512-WHtriQqGyibbb/Rx71YY43T0cXqyelEU0lB2QMBRXvD2X0iyeGl4qMxocgEIcbHyK7uqE7hKgjT8aBrHqhgc1w==
dependencies:
"@algolia/client-common" "4.14.2"
"@algolia/client-search" "4.14.2"
"@algolia/transporter" "4.14.2"
"@algolia/client-analytics@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.12.1.tgz#2976d658655a1590cf84cfb596aa75a204f6dec4"
@ -97,6 +125,16 @@
"@algolia/requester-common" "4.13.0"
"@algolia/transporter" "4.13.0"
"@algolia/client-analytics@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.14.2.tgz#ca04dcaf9a78ee5c92c5cb5e9c74cf031eb2f1fb"
integrity sha512-yBvBv2mw+HX5a+aeR0dkvUbFZsiC4FKSnfqk9rrfX+QrlNOKEhCG0tJzjiOggRW4EcNqRmaTULIYvIzQVL2KYQ==
dependencies:
"@algolia/client-common" "4.14.2"
"@algolia/client-search" "4.14.2"
"@algolia/requester-common" "4.14.2"
"@algolia/transporter" "4.14.2"
"@algolia/client-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.12.1.tgz#104ccefe96bda3ff926bc70c31ff6d17c41b6107"
@ -113,6 +151,14 @@
"@algolia/requester-common" "4.13.0"
"@algolia/transporter" "4.13.0"
"@algolia/client-common@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.14.2.tgz#e1324e167ffa8af60f3e8bcd122110fd0bfd1300"
integrity sha512-43o4fslNLcktgtDMVaT5XwlzsDPzlqvqesRi4MjQz2x4/Sxm7zYg5LRYFol1BIhG6EwxKvSUq8HcC/KxJu3J0Q==
dependencies:
"@algolia/requester-common" "4.14.2"
"@algolia/transporter" "4.14.2"
"@algolia/client-personalization@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-personalization/-/client-personalization-4.12.1.tgz#f63d1890f95de850e1c8e41c1d57adda521d9e7f"
@ -131,6 +177,15 @@
"@algolia/requester-common" "4.13.0"
"@algolia/transporter" "4.13.0"
"@algolia/client-personalization@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/client-personalization/-/client-personalization-4.14.2.tgz#656bbb6157a3dd1a4be7de65e457fda136c404ec"
integrity sha512-ACCoLi0cL8CBZ1W/2juehSltrw2iqsQBnfiu/Rbl9W2yE6o2ZUb97+sqN/jBqYNQBS+o0ekTMKNkQjHHAcEXNw==
dependencies:
"@algolia/client-common" "4.14.2"
"@algolia/requester-common" "4.14.2"
"@algolia/transporter" "4.14.2"
"@algolia/client-search@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.12.1.tgz#fcd7a974be5d39d5c336d7f2e89577ffa66aefdd"
@ -149,6 +204,15 @@
"@algolia/requester-common" "4.13.0"
"@algolia/transporter" "4.13.0"
"@algolia/client-search@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.14.2.tgz#357bdb7e640163f0e33bad231dfcc21f67dc2e92"
integrity sha512-L5zScdOmcZ6NGiVbLKTvP02UbxZ0njd5Vq9nJAmPFtjffUSOGEp11BmD2oMJ5QvARgx2XbX4KzTTNS5ECYIMWw==
dependencies:
"@algolia/client-common" "4.14.2"
"@algolia/requester-common" "4.14.2"
"@algolia/transporter" "4.14.2"
"@algolia/events@^4.0.1":
version "4.0.1"
resolved "https://registry.yarnpkg.com/@algolia/events/-/events-4.0.1.tgz#fd39e7477e7bc703d7f893b556f676c032af3950"
@ -164,6 +228,11 @@
resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.13.0.tgz#be2606e71aae618a1ff1ea9a1b5f5a74284b35a8"
integrity sha512-8yqXk7rMtmQJ9wZiHOt/6d4/JDEg5VCk83gJ39I+X/pwUPzIsbKy9QiK4uJ3aJELKyoIiDT1hpYVt+5ia+94IA==
"@algolia/logger-common@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.14.2.tgz#b74b3a92431f92665519d95942c246793ec390ee"
integrity sha512-/JGlYvdV++IcMHBnVFsqEisTiOeEr6cUJtpjz8zc0A9c31JrtLm318Njc72p14Pnkw3A/5lHHh+QxpJ6WFTmsA==
"@algolia/logger-console@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.12.1.tgz#841edd39dd5c5530a69fc66084bfee3254dd0807"
@ -178,6 +247,13 @@
dependencies:
"@algolia/logger-common" "4.13.0"
"@algolia/logger-console@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.14.2.tgz#ec49cb47408f5811d4792598683923a800abce7b"
integrity sha512-8S2PlpdshbkwlLCSAB5f8c91xyc84VM9Ar9EdfE9UmX+NrKNYnWR1maXXVDQQoto07G1Ol/tYFnFVhUZq0xV/g==
dependencies:
"@algolia/logger-common" "4.14.2"
"@algolia/requester-browser-xhr@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.12.1.tgz#2d0c18ee188d7cae0e4a930e5e89989e3c4a816b"
@ -192,6 +268,13 @@
dependencies:
"@algolia/requester-common" "4.13.0"
"@algolia/requester-browser-xhr@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.14.2.tgz#a2cd4d9d8d90d53109cc7f3682dc6ebf20f798f2"
integrity sha512-CEh//xYz/WfxHFh7pcMjQNWgpl4wFB85lUMRyVwaDPibNzQRVcV33YS+63fShFWc2+42YEipFGH2iPzlpszmDw==
dependencies:
"@algolia/requester-common" "4.14.2"
"@algolia/requester-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.12.1.tgz#95bb6539da7199da3e205341cea8f27267f7af29"
@ -202,6 +285,11 @@
resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.13.0.tgz#47fb3464cfb26b55ba43676d13f295d812830596"
integrity sha512-BRTDj53ecK+gn7ugukDWOOcBRul59C4NblCHqj4Zm5msd5UnHFjd/sGX+RLOEoFMhetILAnmg6wMrRrQVac9vw==
"@algolia/requester-common@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.14.2.tgz#bc4e9e5ee16c953c0ecacbfb334a33c30c28b1a1"
integrity sha512-73YQsBOKa5fvVV3My7iZHu1sUqmjjfs9TteFWwPwDmnad7T0VTCopttcsM3OjLxZFtBnX61Xxl2T2gmG2O4ehg==
"@algolia/requester-node-http@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.12.1.tgz#c9df97ff1daa7e58c5c2b1f28cf7163005edccb0"
@ -216,6 +304,13 @@
dependencies:
"@algolia/requester-common" "4.13.0"
"@algolia/requester-node-http@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.14.2.tgz#7c1223a1785decaab1def64c83dade6bea45e115"
integrity sha512-oDbb02kd1o5GTEld4pETlPZLY0e+gOSWjWMJHWTgDXbv9rm/o2cF7japO6Vj1ENnrqWvLBmW1OzV9g6FUFhFXg==
dependencies:
"@algolia/requester-common" "4.14.2"
"@algolia/transporter@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.12.1.tgz#61b9829916c474f42e2d4a6eada0d6c138379945"
@ -234,6 +329,15 @@
"@algolia/logger-common" "4.13.0"
"@algolia/requester-common" "4.13.0"
"@algolia/transporter@4.14.2":
version "4.14.2"
resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.14.2.tgz#77c069047fb1a4359ee6a51f51829508e44a1e3d"
integrity sha512-t89dfQb2T9MFQHidjHcfhh6iGMNwvuKUvojAj+JsrHAGbuSy7yE4BylhLX6R0Q1xYRoC4Vvv+O5qIw/LdnQfsQ==
dependencies:
"@algolia/cache-common" "4.14.2"
"@algolia/logger-common" "4.14.2"
"@algolia/requester-common" "4.14.2"
"@ampproject/remapping@^2.0.0":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.1.1.tgz#7922fb0817bf3166d8d9e258c57477e3fd1c3610"
@ -2755,6 +2859,26 @@ algoliasearch@^4.13.0:
"@algolia/requester-node-http" "4.13.0"
"@algolia/transporter" "4.13.0"
algoliasearch@^4.14.2:
version "4.14.2"
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.14.2.tgz#63f142583bfc3a9bd3cd4a1b098bf6fe58e56f6c"
integrity sha512-ngbEQonGEmf8dyEh5f+uOIihv4176dgbuOZspiuhmTTBRBuzWu3KCGHre6uHj5YyuC7pNvQGzB6ZNJyZi0z+Sg==
dependencies:
"@algolia/cache-browser-local-storage" "4.14.2"
"@algolia/cache-common" "4.14.2"
"@algolia/cache-in-memory" "4.14.2"
"@algolia/client-account" "4.14.2"
"@algolia/client-analytics" "4.14.2"
"@algolia/client-common" "4.14.2"
"@algolia/client-personalization" "4.14.2"
"@algolia/client-search" "4.14.2"
"@algolia/logger-common" "4.14.2"
"@algolia/logger-console" "4.14.2"
"@algolia/requester-browser-xhr" "4.14.2"
"@algolia/requester-common" "4.14.2"
"@algolia/requester-node-http" "4.14.2"
"@algolia/transporter" "4.14.2"
ansi-align@^3.0.0, ansi-align@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-3.0.1.tgz#0cdf12e111ace773a86e9a1fad1225c43cb19a59"