Incorporating Algolia Docsearch with MadCap Flare has been my current challenge. MadCap Flare, a technical documentation tool that generates HTML output, is proving to be tricky when it comes to integrating the Docsearch feature. While the underlying crawler of Docsearch functions correctly in codepen, I am encountering difficulties merging it with Flare. Unfortunately, Flare comes equipped with a range of built-in scripts that are inaccessible for modification, including require.js. This restriction is resulting in a string of errors, such as Uncaught Error: Mismatched anonymous define() module.., during the build process.
To tackle this issue, I attempted to load the Docsearch javascript using require.js
, but my limited understanding of JavaScript led me down the wrong path.
The search input in HTML looks like this:
<div class="input-group">
<input id="<YOUR_CSS_SELECTOR>" type="text" class="form-control" placeholder="Search" aria-label="Search Field" aria-describedby="infoSearch" />
</div>
The original Algolia Docsearch CDN script and snippet typically appear as follows:
<!-- Before the closing </body> -->
<script src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js">
</script>
<script>
docsearch({
apiKey: '<API_KEY>',
indexName: '<INDEX_NAME>',
inputSelector: '<YOUR_CSS_SELECTOR>',
debug: false
});
</script>
My attempt at loading these scripts using require.js
involves the following steps:
<script type="text/javascript">
require.config({
enforceDefine: true,
paths: {
"docSearch": "https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"
},
waitSeconds: 40
});
require(['docSearch']);//This is probably not doing anything.
</script>
<script>
docsearch({
apiKey: '<API_KEY>',
indexName: '<INDEX_NAME>',
inputSelector: '<YOUR_CSS_SELECTOR>',
debug: false
}); //This throws "Uncaught Reference Error docsearch is not defined" error
</script>
Despite consulting various threads and require.js documentation, I have yet to find a solution. Any assistance or guidance would be greatly appreciated!