// A local search script with the help of [hexo-generator-search](https://github.com/PaicHyperionDev/hexo-generator-search) // Copyright (C) 2017 // Liam Huang var searchFunc = function (path, search_id, content_id) { // 0x00. environment initialization 'use strict'; var BTN = "×"; var $input = document.getElementById(search_id); var $resultContent = document.getElementById(content_id); $resultContent.innerHTML = BTN + ""; $.ajax({ // 0x01. load xml file url: path, dataType: "xml", success: function (xmlResponse) { // 0x02. parse xml file var datas = $("entry", xmlResponse).map(function () { return { title: $("title", this).text(), content: $("content", this).text(), url: $("url", this).text() }; }).get(); $resultContent.innerHTML = ""; $input.addEventListener('input', function () { // 0x03. parse query to keywords list var str = '"; if (str.indexOf('
  • ') === -1) { return $resultContent.innerHTML = BTN + ""; } $resultContent.innerHTML = BTN + str; }); } }); $(document).on('click', '#local-search-close', function() { $('#local-search-input').val(''); $('#local-search-result').html(''); }); } var getSearchFile = function(path){ // var path = "/search.xml"; searchFunc(path, 'local-search-input', 'local-search-result'); }