From 806e7798d915d4e63231d7046d32d978306be417 Mon Sep 17 00:00:00 2001 From: Sarah German Date: Wed, 24 Aug 2022 02:29:16 -0500 Subject: [PATCH] docs: add Default DocSearch template to documentation (#1522) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Vannicatte --- packages/website/docs/templates.mdx | 99 +++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/packages/website/docs/templates.mdx b/packages/website/docs/templates.mdx index b00453f83..bb9abae3d 100644 --- a/packages/website/docs/templates.mdx +++ b/packages/website/docs/templates.mdx @@ -17,6 +17,105 @@ Templates are available when you [create a new Crawler](https://crawler.algolia. /> +## Default template + +
default.js +
+ +```js +new Crawler({ + appId: 'YOUR_APP_ID', + apiKey: 'YOUR_API_KEY', + indexPrefix: 'crawler_', + rateLimit: 8, + startUrls: ['https://YOUR_WEBSITE_URL'], + renderJavaScript: false, + sitemaps: [], + ignoreCanonicalTo: false, + discoveryPatterns: ['https://YOUR_WEBSITE_URL/**'], + actions: [ + { + indexName: 'YOUR_INDEX_NAME', + pathsToMatch: ['https://YOUR_WEBSITE_URL/**'], + recordExtractor: ({ helpers }) => { + return helpers.docsearch({ + recordProps: { + lvl1: ['header h1', 'article h1', 'main h1', 'h1', 'head > title'], + content: ['article p, article li', 'main p, main li', 'p, li'], + lvl0: { + selectors: '', + defaultValue: 'Documentation', + }, + lvl2: ['article h2', 'main h2', 'h2'], + lvl3: ['article h3', 'main h3', 'h3'], + lvl4: ['article h4', 'main h4', 'h4'], + lvl5: ['article h5', 'main h5', 'h5'], + lvl6: ['article h6', 'main h6', 'h6'], + }, + aggregateContent: true, + recordVersion: 'v3', + }); + }, + }, + ], + initialIndexSettings: { + YOUR_INDEX_NAME: { + attributesForFaceting: ['type', 'lang'], + attributesToRetrieve: [ + 'hierarchy', + 'content', + 'anchor', + 'url', + 'url_without_anchor', + 'type', + ], + attributesToHighlight: ['hierarchy', 'content'], + attributesToSnippet: ['content:10'], + camelCaseAttributes: ['hierarchy', 'content'], + searchableAttributes: [ + 'unordered(hierarchy.lvl0)', + 'unordered(hierarchy.lvl1)', + 'unordered(hierarchy.lvl2)', + 'unordered(hierarchy.lvl3)', + 'unordered(hierarchy.lvl4)', + 'unordered(hierarchy.lvl5)', + 'unordered(hierarchy.lvl6)', + 'content', + ], + distinct: true, + attributeForDistinct: 'url', + customRanking: [ + 'desc(weight.pageRank)', + 'desc(weight.level)', + 'asc(weight.position)', + ], + ranking: [ + 'words', + 'filters', + 'typo', + 'attribute', + 'proximity', + 'exact', + 'custom', + ], + highlightPreTag: '', + highlightPostTag: '', + minWordSizefor1Typo: 3, + minWordSizefor2Typos: 7, + allowTyposOnNumericTokens: false, + minProximity: 1, + ignorePlurals: true, + advancedSyntax: true, + attributeCriteriaComputedByMinProximity: true, + removeWordsIfNoResults: 'allOptional', + }, + }, +}); +``` + +
+
+ ## Docusaurus v1 template
docusaurus-v1.js