82
82
{% endfor %}
83
83
{% endif %}
84
84
{% block extrahead %}{% endblock %}
85
-
86
-
87
-
85
+ {% if config.algolia %}
86
+ < link rel ="stylesheet " href ="https://cdn.jsdelivr.net/npm/@docsearch/css@3 " />
87
+ < link rel ="preconnect " href ="https://{{ config.algolia.app_id }}-dsn.algolia.net " crossorigin />
88
+ {% endif %}
88
89
</ head >
89
90
{% set direction = config.theme.direction or lang.t("direction") %}
90
91
{% if config.theme.palette %}
396
397
{% endblock %}
397
398
{% block scripts %}
398
399
< script src ="{{ 'assets/javascripts/bundle.83f73b43.min.js' | url }} "> </ script >
399
-
400
- < script type ="module " src ="{{ 'javascripts/main.js' | url }} "> </ script >
401
- {% for script in config.extra_javascript %}
402
- {{ script | script_tag }}
403
- {% endfor %}
400
+ < script type ="module " src ="{{ 'javascripts/main.js' | url }} "> </ script >
401
+ {% for script in config.extra_javascript %}
402
+ {{ script | script_tag }}
403
+ {% endfor %}
404
404
{% endblock %}
405
-
406
- </ body >
405
+ {% if config.algolia %}
406
+ < script src ="https://cdn.jsdelivr.net/npm/@docsearch/js@3 "> </ script >
407
+ < script type ="text/javascript ">
408
+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
409
+ const searchInput = document . querySelector ( '.md-search' ) ;
410
+ const algoliaContainer = document . createElement ( 'div' ) ;
411
+ algoliaContainer . className = 'algolia-container' ;
412
+ document . body . appendChild ( algoliaContainer ) ;
413
+
414
+ if ( searchInput ) {
415
+ // Remove existing event listeners by replacing the element
416
+ const newSearchInput = searchInput . cloneNode ( true ) ;
417
+ searchInput . parentNode . replaceChild ( newSearchInput , searchInput ) ;
418
+
419
+ docsearch ( {
420
+ appId : '{{ config.algolia.app_id }}' ,
421
+ apiKey : '{{ config.algolia.api_key }}' ,
422
+ indexName : '{{ config.algolia.index_name }}' ,
423
+ container : algoliaContainer ,
424
+ transformItems ( items ) {
425
+ return items . map ( ( item ) => ( {
426
+ ...item ,
427
+ hierarchy : Object . entries ( item . hierarchy ) . reduce ( ( acc , [ key , value ] ) => {
428
+ if ( value ) {
429
+ acc [ key ] = value . trim ( ) . replace ( '¶' , '' ) ;
430
+ } else {
431
+ acc [ key ] = value ;
432
+ }
433
+ return acc ;
434
+ } , { } ) ,
435
+ }
436
+ ) ) ;
437
+ }
438
+ } ) ;
439
+
440
+ newSearchInput . addEventListener ( 'click' , function ( ) {
441
+ const algoliaButton = document . querySelector ( '.algolia-container button' ) ;
442
+ if ( algoliaButton ) algoliaButton . click ( ) ;
443
+ } ) ;
444
+ }
445
+ } ) ;
446
+ </ script >
447
+ {% endif %}
407
448
</ body >
408
449
</ html >
0 commit comments