Skip to content

Commit

Permalink
Algolia docs (robusta-dev#1082)
Browse files Browse the repository at this point in the history
* Switch search to Algolia doc search
  • Loading branch information
LeaveMyYard authored and pavangudiwada committed Nov 6, 2023
1 parent 7039d7e commit 60a166e
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 10 deletions.
23 changes: 13 additions & 10 deletions docs/_templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,25 @@
{{ alt.name }}
</a>
</li>
{% endfor %}
{% endfor %}
</ul>
</div>
</div>
</div>
{% endif %}

<!-- Button to open search modal -->
{% if "search" in config["plugins"] %}
<label class="md-header__button md-icon" for="__search">
{% include ".icons/material/magnify.svg" %}
</label>

<!-- Search interface -->
{% include "partials/search.html" %}
{% endif %}
<!-- Algolia search -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@docsearch/css@3" />
<div id="docsearch"></div>
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
<script>
docsearch({
container: '#docsearch',
appId: 'EEWU58CJVX',
indexName: 'robusta',
apiKey: 'e77d73e819e13d5b207909ee81891826',
});
</script>

<!-- Repository information -->
{% if config.repo_url %}
Expand Down
112 changes: 112 additions & 0 deletions docs/crawler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// This is the code example for the crawler configuration file for https://crawler.algolia.com/
new Crawler({
rateLimit: 8,
maxDepth: 10,
maxUrls: 5000,
startUrls: ["https://docs.robusta.dev/master/"],
renderJavaScript: false,
sitemaps: [],
ignoreCanonicalTo: false,
discoveryPatterns: ["https://docs.robusta.dev/master/**"],
schedule: "at 13:11 on Thursday",
actions: [
{
indexName: "robusta",
pathsToMatch: ["https://docs.robusta.dev/master/**"],
recordExtractor: ({ helpers, url }) => {
return helpers.docsearch(
url.pathname.includes("/triggers/")
? {
recordProps: url.pathname.includes("/triggers/")
? {
lvl0: {
selectors: [],
defaultValue: "Triggers",
},
lvl1: ["article h1", "head > title"],
lvl2: ["details summary"],
content: ["details *:not(summary)"],
pageRank: 9,
} : url.pathname.includes("/actions/") ? {
lvl0: {
selectors: [],
defaultValue: "Actions",
},
lvl1: ["article h1", "head > title"],
lvl2: [".admonition .admonition-title"],
content: [".admonition *:not(.admonition-title)"],
pageRank: 8,
} : url.pathname.includes("/sinks/") ? {
lvl0: {
selectors: [],
defaultValue: "Sinks",
},
lvl1: ["article h1", "head > title"],
lvl2: ["article h2", "h2"],
lvl3: ["article h3", "h3"],
lvl4: ["article h4", "h4"],
lvl5: ["article h5", "h5"],
content: ["article p, article li, article code"],
pageRank: 7,
} : {
lvl0: {
selectors: ["article h1", "head > title"],
defaultValue: "Documentation",
},
lvl1: ["article h2", "h2"],
lvl2: ["article h3", "h3"],
lvl3: ["article h4", "h4"],
lvl4: ["article h5", "h5"],
lvl5: ["article h6", "h6"],
content: ["article p, article li, article code"],
pageRank: (() => {
if (url.pathname.includes("/installation/index.html")) {
return 10;
}
return 1;
})(),
},
aggregateContent: true,
recordVersion: "v3",
}
);
},
},
],
safetyChecks: { beforeIndexPublishing: { maxLostRecordsPercentage: 30 } },
initialIndexSettings: {
robusta: {
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: '<span class="algolia-docsearch-suggestion--highlight">',
highlightPostTag: "</span>",
minWordSizefor1Typo: 3,
minWordSizefor2Typos: 7,
allowTyposOnNumericTokens: false,
minProximity: 1,
ignorePlurals: true,
advancedSyntax: true,
attributeCriteriaComputedByMinProximity: true,
removeWordsIfNoResults: "allOptional",
},
},
appId: "EEWU58CJVX",
apiKey: "...",
});

0 comments on commit 60a166e

Please sign in to comment.