Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json search engine support #1635

Merged
merged 2 commits into from
Apr 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions layout/_third-party/search/localsearch.swig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
<script type="text/javascript">
// Popup Window;
var isfetched = false;
var isXml = true;
// Search DB path;
var search_path = "{{ config.search.path }}";
if (search_path.length === 0) {
search_path = "search.xml";
} else if (search_path.endsWith("json")) {
isXml = false;
}
var path = "{{ config.root }}" + search_path;
// monitor main search box;
Expand Down Expand Up @@ -33,19 +36,19 @@
'use strict';
$.ajax({
url: path,
dataType: "xml",
dataType: isXml ? "xml" : "json",
async: true,
success: function( xmlResponse ) {
success: function(res) {
// get the contents from search data
isfetched = true;
$('.popup').detach().appendTo('.header-inner');
var datas = $( "entry", xmlResponse ).map(function() {
var datas = isXml ? $("entry", res).map(function() {
return {
title: $( "title", this ).text(),
title: $("title", this).text(),
content: $("content",this).text(),
url: $( "url" , this).text()
url: $("url" , this).text()
};
}).get();
}).get() : res;
var input = document.getElementById(search_id);
var resultContent = document.getElementById(content_id);
var inputEventFunction = function() {
Expand Down