Skip to content

Commit

Permalink
Merge pull request kitian616#160 from Krinkle/json-search
Browse files Browse the repository at this point in the history
Use 'jsonify' instead of 'url_encode' for JavaScript data export
  • Loading branch information
kitian616 authored Jun 11, 2019
2 parents fc48554 + c9abb29 commit 7530913
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 23 deletions.
2 changes: 1 addition & 1 deletion _includes/pageview-providers/leancloud/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
appClass: '{{ _LEANCLOUD_APP_CLASS }}'
});
var key = '{{ page.key }}';
var title = window.decodeUrl('{{ page.title | url_encode }}');
var title = {{ page.title | jsonify }};
pageview.increase(key, title, function(view) {
$("[data-page-key='{{ page.key }}']").text(view);
});
Expand Down
4 changes: 0 additions & 4 deletions _includes/scripts/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
return typeof val === 'string';
};

window.decodeUrl = function(str) {
return str ? decodeURIComponent(str.replace(/\+/g, '%20')) : '';
};

window.hasEvent = function(event) {
return 'on'.concat(event) in window.document;
};
Expand Down
4 changes: 2 additions & 2 deletions _includes/search-providers/default/search-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ window.TEXT_SEARCH_DATA={
'{{ _collection.label }}':[
{%- for _article in _collection.docs -%}
{%- unless forloop.first -%},{%- endunless -%}
{'title':'{{ _article.title | url_encode }}',
{'title':{{ _article.title | jsonify }},
{%- include snippets/prepend-baseurl.html path=_article.url -%}
{%- assign _url = __return -%}
'url':'{{ _url | url_encode }}'}
'url':{{ _url | jsonify }}}
{%- endfor -%}
]
{%- endfor -%}
Expand Down
17 changes: 1 addition & 16 deletions _includes/search-providers/default/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var SOURCES = window.TEXT_VARIABLES.sources;
var PAHTS = window.TEXT_VARIABLES.paths;
window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
var search = (window.search || (window.search = {}));
var searchData = window.TEXT_SEARCH_DATA ? initData(window.TEXT_SEARCH_DATA) : {};
var searchData = window.TEXT_SEARCH_DATA || {};

function memorize(f) {
var cache = {};
Expand All @@ -13,21 +13,6 @@ window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
};
}

function initData(data) {
var _data = [], i, j, key, keys, cur;
keys = Object.keys(data);
for (i = 0; i < keys.length; i++) {
key = keys[i], _data[key] = [];
for (j = 0; j < data[key].length; j++) {
cur = data[key][j];
cur.title = window.decodeUrl(cur.title);
cur.url = window.decodeUrl(cur.url);
_data[key].push(cur);
}
}
return _data;
}

/// search
function searchByQuery(query) {
var i, j, key, keys, cur, _title, result = {};
Expand Down

0 comments on commit 7530913

Please sign in to comment.