--- regenerate: true --- {% capture cache %} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/themes/j1/core/js/adapter/algolia.js # Liquid template to create the Template Adapter for Algolia # # Product/Info: # https://jekyll.one # https://community.algolia.com/instantsearch.js/v2/getting-started.html # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # # ----------------------------------------------------------------------------- {% endcomment %} /* # ----------------------------------------------------------------------------- # ~/assets/themes/j1/core/js/adapter/algolia.js # J1 Adapter for Algolia # # Product/Info: # https://jekyll.one # # Copyright (C) 2019 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see https://jekyll.one # # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ 'use strict'; {% comment %} Load YML config data -------------------------------------------------------------------------------- {% endcomment %} {% assign algolia_config = site.algolia %} j1.Algolia = (function (j1, window) { var environment = '{{environment}}'; // Set environment var state = 'not_started'; var logger; var logText; return { // ------------------------------------------------------------------------- // Initialize InstantSearch // ------------------------------------------------------------------------- init: function () { // Config settings object var algoliaConfig = {}; {% comment %} Set global variables -------------------------------------------------------------------------- {% endcomment %} logger = log4javascript.getLogger("j1.Algolia.adapter"); // Setup logger // Set|Log status state = 'initialize'; logger.info('state: ' + state); {% comment %} Load module config from yml data -------------------------------------------------------------------------- {% endcomment %} // Load module DEFAULTS|CONFIG algoliaConfig = $.extend({}, {{algolia_config | replace: '=>', ':' }}); var search = instantsearch({ appId: algoliaConfig.application_id, apiKey: algoliaConfig.search_only_api_key, indexName: algoliaConfig.index_name, routing: true }); var hitTemplate = function(hit) { // state = 'start search'; // logger.info('state: ' + state); // var re = new RegExp("^\/posts"); // var re = new RegExp("^\/pages"); var re = new RegExp("^\/pages|^\/posts|^\/collections"); if ( re.test(hit.url) ) { let date = ''; if (hit.date) { date = moment.unix(hit.date).format('MMM D, YYYY'); } // let url = `/jekyll-algolia-example${hit.url}#${hit.anchor}`; let url = `${hit.url}`; const title = hit._highlightResult.title.value; let breadcrumbs = ''; if (hit._highlightResult.headings) { breadcrumbs = hit._highlightResult.headings.map(match => { return `
` }).join(' > ') } var content = hit._highlightResult.html.value; return `Algolia Search DISABLED
' ); state = 'finished'; logger.info('state: ' + state); logger.info("J1 Algolia Seach NOT enabled"); } return; }, // end init // ------------------------------------------------------------------------- // returns the current (processing) state of the module // ------------------------------------------------------------------------- state: function () { return state; } // end state }; // end return })(j1, window); {% endcapture %} {{ cache | strip_empty_lines }} {% assign cache = nil %}