Fixed a substition blunder

This commit is contained in:
Piotr Janosz
2019-08-17 12:40:14 +02:00
committed by fabioberger
parent d4c771dc7d
commit 0d71ec93e7
4 changed files with 18 additions and 16 deletions

View File

@@ -96,11 +96,13 @@ const CustomAutoComplete: React.FC<IAutoCompleteProps> = ({
const renderSuggestion = (hit: IHit): React.ReactNode => { const renderSuggestion = (hit: IHit): React.ReactNode => {
const { externalUrl, urlWithHash } = hit; const { externalUrl, urlWithHash } = hit;
const to = externalUrl ? externalUrl : urlWithHash; const to = externalUrl ? externalUrl : urlWithHash;
// The atrributes to snippet are set in algolia_constants
const attributeToSnippet = externalUrl ? 'description' : 'textContent';
return ( return (
<Link shouldOpenInNewTab={externalUrl ? true : false} to={to}> <Link shouldOpenInNewTab={externalUrl ? true : false} to={to}>
<Highlight attribute="title" hit={hit} nonHighlightedTagName="h6" /> <Highlight attribute="title" hit={hit} nonHighlightedTagName="h6" />
<Snippet attribute="textContent" hit={hit} nonHighlightedTagName="p" tagName="span" /> <Snippet attribute={attributeToSnippet} hit={hit} nonHighlightedTagName="p" tagName="span" />
</Link> </Link>
); );
}; };

View File

@@ -21,7 +21,7 @@ export const FeatureLink: React.FC<IFeatureLinkProps> = ({ description, external
const to = externalUrl ? externalUrl : url; const to = externalUrl ? externalUrl : url;
return ( return (
<FeatureLinkWrapper to={to}> <FeatureLinkWrapper shouldOpenInNewTab={externalUrl ? true : false} to={to}>
<StyledIcon color={colors.brandLight} name="flexibleIntegration" size={60} /> <StyledIcon color={colors.brandLight} name="flexibleIntegration" size={60} />
<Content> <Content>
<div> <div>

View File

@@ -30,7 +30,7 @@ const sharedSettings = {
distinct: true, distinct: true,
attributeForDistinct: 'id', attributeForDistinct: 'id',
attributesForFaceting: [''], attributesForFaceting: [''],
attributesToSnippet: ['textContent:20'], // attribute:nbWords (number of words to show in a snippet) attributesToSnippet: ['description:20', 'textContent:20'], // attribute:nbWords (number of words to show in a snippet)
searchableAttributes: ['title', 'textContent'], searchableAttributes: ['title', 'textContent'],
snippetEllipsisText: '…', snippetEllipsisText: '…',
}; };

View File

@@ -58,11 +58,11 @@ function getNameToFile(dirName: string): ObjectMap<File> {
if (dirName === 'tools') { if (dirName === 'tools') {
const name = path.basename(path.join(p, '../../')); const name = path.basename(path.join(p, '../../'));
const version = path.basename(path.dirname(p)); const version = path.basename(path.dirname(p));
const externalUrl = `/docs/tools/${name}/${version}`; const url = `/docs/tools/${name}/${version}`;
const fileIfExists = nameToFile[name]; const fileIfExists = nameToFile[name];
const fileObject = { name, path: p, version, versions: [version], externalUrl }; const fileObject = { name, path: p, version, versions: [version], url };
if (fileIfExists !== undefined) { if (fileIfExists !== undefined) {
if (compareVersions.compare(version, fileIfExists.version, '>')) { if (compareVersions.compare(version, fileIfExists.version, '>')) {
@@ -76,13 +76,13 @@ function getNameToFile(dirName: string): ObjectMap<File> {
if (dirName === 'guides') { if (dirName === 'guides') {
const { name } = path.parse(p); const { name } = path.parse(p);
const externalUrl = `/docs/guides/${name}`; const url = `/docs/guides/${name}`;
nameToFile[name] = { name, path: p, externalUrl }; nameToFile[name] = { name, path: p, url };
} }
if (dirName === 'core-concepts' || dirName === 'api-explorer') { if (dirName === 'core-concepts' || dirName === 'api-explorer') {
const externalUrl = `/docs/${dirName}`; const url = `/docs/${dirName}`;
nameToFile[dirName] = { name: dirName, path: p, externalUrl }; nameToFile[dirName] = { name: dirName, path: p, url };
} }
} }
@@ -141,7 +141,7 @@ function modifier(node: Node, index: number, parent: Node): void {
const endIndex = parent.children.indexOf(end); const endIndex = parent.children.indexOf(end);
// Find all nodes between and including the heading and all nodes before the next heading // Find all nodes between and including the heading and all nodes before the next heading
const between = parent.children.slice(startIndex, endIndex > 0 ? endIndex : undefined); const between = parent.children.slice(startIndex, endIndex > 0 ? endIndex : undefined);
// We add the id of the heading as hash part of the externalUrl to all text nodes // We add the id of the heading as hash part of the url to all text nodes
for (const item of between) { for (const item of between) {
addHashToChildren(item, start); addHashToChildren(item, start);
} }
@@ -190,7 +190,7 @@ async function clearIndexAsync(algoliaIndex: any): Promise<void> {
} }
function getContent(file: File, formattedTextNodes: FormattedNode[], indexName: string): Content[] { function getContent(file: File, formattedTextNodes: FormattedNode[], indexName: string): Content[] {
const { name, externalUrl } = file; const { name, url } = file;
const metaData: Meta = meta[indexName][name]; const metaData: Meta = meta[indexName][name];
const content: Content[] = []; const content: Content[] = [];
@@ -199,8 +199,8 @@ function getContent(file: File, formattedTextNodes: FormattedNode[], indexName:
content.push({ content.push({
...metaData, ...metaData,
externalUrl, url,
urlWithHash: externalUrl + node.hash, urlWithHash: url + node.hash,
hash: node.hash, hash: node.hash,
textContent: node.textContent, textContent: node.textContent,
id: titleSlug, id: titleSlug,
@@ -227,7 +227,7 @@ function formatTextNodes(textNodes: Node[]): FormattedNode[] {
if (isIndexPresent) { if (isIndexPresent) {
formattedTextNodes[nodeIndex].textContent += value; // Merge value with existing text at the given line formattedTextNodes[nodeIndex].textContent += value; // Merge value with existing text at the given line
} else { } else {
formattedTextNodes.push({ line, hash, textContent: value }); // Create text, hash part of the externalUrl, and its start line formattedTextNodes.push({ line, hash, textContent: value }); // Create text, hash part of the url, and its start line
} }
}); });
@@ -239,7 +239,7 @@ interface File {
path: string; path: string;
version?: string; version?: string;
versions?: string[]; versions?: string[];
externalUrl: string; url: string;
} }
interface Meta { interface Meta {
@@ -256,7 +256,7 @@ interface Meta {
} }
interface Content extends Meta { interface Content extends Meta {
externalUrl: string; url: string;
urlWithHash: string; urlWithHash: string;
hash: string; hash: string;
textContent: string; textContent: string;