// A local search script with the help of [hexo-generator-search](https://github.com/PaicHyperionDev/hexo-generator-search) // Copyright (C) 2015 // Joseph Pan // Shuhao Mao // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // 02110-1301 USA // var searchFunc = function (path, search_id, content_id) { 'use strict'; var BTN = ""; $.ajax({ url: path, dataType: "xml", success: function (xmlResponse) { // get the contents from search data var datas = $("entry", xmlResponse).map(function () { return { title: $("title", this).text(), content: $("content", this).text(), url: $("url", this).text() }; }).get(); var $input = document.getElementById(search_id); var $resultContent = document.getElementById(content_id); $input.addEventListener('input', function () { 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(''); }); };