-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a custom Algolia search for docs (#4100)
* Update algolia search to use custom index * Update naming of SearchItem * sourceId is products * Change sitemap domain back to docs.amplify.aws * Remove old docsearch * Remove default options if query is empty * Increase hits per page * Revert "Increase hits per page" This reverts commit b48b318. * Fix content error in headless.mdx * Fix content error in workflows.mdx * Fix content issues in cli/graphql/overview.mdx * Fix url in cli/restapi/testing.mdx * Fix content issues in commands.mdx * Fix angle brackets in files.mdx * Remove comment in export-to-cdk * Fix files.mdx * Fix example url to be code string in cli/usage/containers.mdx * Use html entity characters in cli/teams/commands.mdx * Remove comments from cli/function/build-options.mdx * Fix transformer-migration.mdx * Use html entity characters in cli/start/workflows.mdx Co-authored-by: Tim Nguyen <timngyn@amazon.com>
- Loading branch information
1 parent
857b165
commit b296f22
Showing
42 changed files
with
5,527 additions
and
4,399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
interface AdobeS { | ||
// Configuration properties | ||
trackExternalLinks: boolean; | ||
|
||
// Variables to set when tracking | ||
linkTrackVars: string; | ||
linkTrackEvents: string; | ||
events: string; | ||
pageURL: string; | ||
eVar26: string; | ||
eVar27: string; | ||
|
||
// Tracking functions | ||
t: () => void; | ||
tl: ( | ||
linkObject: true | undefined, | ||
linkType: string, | ||
linkName: string | ||
) => void; | ||
} | ||
|
||
interface AWSCShortbreadObject { | ||
checkForCookieConsent: () => void; | ||
} | ||
|
||
declare const s: AdobeS; | ||
declare const docsearch: (obj: object) => void; | ||
declare const AWSCShortbread: (obj: object) => AWSCShortbreadObject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
interface AdobeS { | ||
// Configuration properties | ||
trackExternalLinks: boolean; | ||
|
||
// Variables to set when tracking | ||
linkTrackVars: string; | ||
linkTrackEvents: string; | ||
events: string; | ||
pageURL: string; | ||
eVar26: string; | ||
eVar27: string; | ||
|
||
// Tracking functions | ||
t: () => void; | ||
tl: ( | ||
linkObject: true | undefined, | ||
linkType: string, | ||
linkName: string, | ||
) => void; | ||
} | ||
|
||
interface AWSCShortbreadObject { | ||
checkForCookieConsent: () => void; | ||
} | ||
|
||
declare const s: AdobeS; | ||
declare const docsearch: (obj: object) => void; | ||
declare const AWSCShortbread: (obj: object) => AWSCShortbreadObject; | ||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,64 @@ | ||
const withTM = require('next-transpile-modules')([ | ||
'@algolia/autocomplete-shared' | ||
]); // pass the modules you would like to see transpiled | ||
|
||
const mdxRenderer = ` | ||
import { mdx } from "@mdx-js/react"; | ||
`; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const directory = require("./src/directory/directory.js"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const headingLinkPlugin = require("./src/plugins/headings.tsx"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const pagePlugin = require("./src/plugins/page.tsx"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const importPlugin = require("./src/plugins/import.tsx"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const codeBlockPlugin = require("./src/plugins/code-block.tsx"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const internalLinkPlugin = require("./src/plugins/internal-link.tsx"); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const withMDX = require("@next/mdx")({ | ||
extension: /\.mdx$/, | ||
options: { | ||
remarkPlugins: [ | ||
importPlugin, | ||
headingLinkPlugin, | ||
pagePlugin, | ||
internalLinkPlugin, | ||
], | ||
rehypePlugins: [codeBlockPlugin], | ||
renderer: mdxRenderer, | ||
}, | ||
}); | ||
|
||
module.exports = withMDX({ | ||
pageExtensions: ["js", "jsx", "mdx", "tsx", "ts"], | ||
typescript: { | ||
// !! WARN !! | ||
// Dangerously allow production builds to successfully complete even if | ||
// your project has type errors. | ||
// !! WARN !! | ||
ignoreBuildErrors: true, | ||
}, | ||
future: { | ||
webpack5: true, | ||
}, | ||
exportPathMap, | ||
trailingSlash: true, | ||
}); | ||
const directory = require('./src/directory/directory.js'); | ||
|
||
module.exports = async (phase, { defaultConfig }) => { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const headingLinkPlugin = await require('./src/plugins/headings.tsx'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const pagePlugin = await require('./src/plugins/page.tsx'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const internalLinkPlugin = await require('./src/plugins/internal-link.tsx'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const codeBlockPlugin = await require('./src/plugins/code-block.tsx'); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const importPlugin = await require('./src/plugins/import.tsx'); | ||
|
||
const withMDX = require('@next/mdx')({ | ||
extension: /\.mdx$/, | ||
options: { | ||
remarkPlugins: [ | ||
importPlugin, | ||
headingLinkPlugin, | ||
pagePlugin, | ||
internalLinkPlugin | ||
], | ||
rehypePlugins: [codeBlockPlugin], | ||
renderer: mdxRenderer | ||
} | ||
}); | ||
|
||
const nextConfig = withTM( | ||
withMDX({ | ||
pageExtensions: ['js', 'jsx', 'mdx', 'tsx', 'ts'], | ||
typescript: { | ||
// !! WARN !! | ||
// Dangerously allow production builds to successfully complete even if | ||
// your project has type errors. | ||
// !! WARN !! | ||
ignoreBuildErrors: true | ||
}, | ||
future: { | ||
webpack5: true | ||
}, | ||
exportPathMap, | ||
trailingSlash: true | ||
}) | ||
); | ||
|
||
return nextConfig; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const generatePathMap = require("./generatePathMap.cjs"); | ||
const generatePathMap = require('./generatePathMap.cjs'); | ||
function exportPathMap(defaultPathMap, props) { | ||
return generatePathMap(directory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { autocomplete } from '@algolia/autocomplete-js'; | ||
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions'; | ||
import { createLocalStorageRecentSearchesPlugin } from '@algolia/autocomplete-plugin-recent-searches'; | ||
import algoliasearch from 'algoliasearch'; | ||
|
||
import React, { createElement, Fragment, useEffect, useRef } from 'react'; | ||
import { render } from 'react-dom'; | ||
|
||
import { pipe } from 'ramda'; | ||
|
||
import { groupBy, limit, uniqBy } from './functions/index'; | ||
|
||
const appId = 'W6Q5N5WUDV'; | ||
const apiKey = 'a82ff7ed9cd894525d84229ba4a886db'; | ||
const searchClient = algoliasearch(appId, apiKey); | ||
|
||
const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin({ | ||
key: 'search', | ||
limit: 20 | ||
}); | ||
const querySuggestionsPlugin = createQuerySuggestionsPlugin({ | ||
searchClient, | ||
indexName: 'custom_search_staging', | ||
getSearchParams() { | ||
return { | ||
hitsPerPage: 20 | ||
}; | ||
} | ||
}); | ||
|
||
const dedupeAndLimitSuggestions = pipe( | ||
uniqBy(({ source, item }) => | ||
source.sourceId === 'querySuggestionsPlugin' ? item.query : item.title | ||
), | ||
limit(10) | ||
); | ||
|
||
const groupByCategory = groupBy((hit) => hit.category, { | ||
getSource({ name, items }) { | ||
return { | ||
getItems() { | ||
return items; | ||
}, | ||
templates: { | ||
header() { | ||
return ( | ||
<> | ||
<span className="aa-SourceHeaderTitle">{name}</span> | ||
<div className="aa-SourceHeaderLine" /> | ||
</> | ||
); | ||
} | ||
} | ||
}; | ||
} | ||
}); | ||
|
||
export function Autocomplete(props) { | ||
const containerRef = useRef(null); | ||
|
||
useEffect(() => { | ||
if (!containerRef.current) { | ||
return undefined; | ||
} | ||
|
||
const search = autocomplete({ | ||
container: containerRef.current, | ||
renderer: { createElement, Fragment }, | ||
plugins: [recentSearchesPlugin, querySuggestionsPlugin], | ||
getSources({ query }) { | ||
if (!query) { | ||
return []; | ||
} | ||
}, | ||
reshape({ sourcesBySourceId }) { | ||
const { | ||
recentSearchesPlugin, | ||
querySuggestionsPlugin, | ||
products, | ||
...rest | ||
} = sourcesBySourceId; | ||
|
||
return [ | ||
dedupeAndLimitSuggestions(), | ||
groupByCategory(products), | ||
Object.values(rest) | ||
]; | ||
}, | ||
render({ children }, root) { | ||
render(children, root); | ||
}, | ||
...props | ||
}); | ||
|
||
return () => { | ||
search.destroy(); | ||
}; | ||
}, [props]); | ||
|
||
return <div ref={containerRef} />; | ||
} |
Oops, something went wrong.