Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9abb29

Browse files
committed
Use 'jsonify' instead of 'url_encode' for JavaScript data export
The JSON data format is natively compatible with the parsing of JavaScript code. It can be used as the literal value of any JavaScript variable or JavaScript object property value. Previously: > window.DATA = {'title':'Foo%20%22Bar%22'}; > title = decodeUrl(DATE.title) Now: > window.DATA = {'title':"Foo \"Bar\""}; > title = DATE.title
1 parent d6b4053 commit c9abb29

File tree

4 files changed

+4
-23
lines changed

4 files changed

+4
-23
lines changed

_includes/pageview-providers/leancloud/post.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
appClass: '{{ _LEANCLOUD_APP_CLASS }}'
2222
});
2323
var key = '{{ page.key }}';
24-
var title = window.decodeUrl('{{ page.title | url_encode }}');
24+
var title = {{ page.title | jsonify }};
2525
pageview.increase(key, title, function(view) {
2626
$("[data-page-key='{{ page.key }}']").text(view);
2727
});

_includes/scripts/utils/utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
return typeof val === 'string';
77
};
88

9-
window.decodeUrl = function(str) {
10-
return str ? decodeURIComponent(str.replace(/\+/g, '%20')) : '';
11-
};
12-
139
window.hasEvent = function(event) {
1410
return 'on'.concat(event) in window.document;
1511
};

_includes/search-providers/default/search-data.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ window.TEXT_SEARCH_DATA={
44
'{{ _collection.label }}':[
55
{%- for _article in _collection.docs -%}
66
{%- unless forloop.first -%},{%- endunless -%}
7-
{'title':'{{ _article.title | url_encode }}',
7+
{'title':{{ _article.title | jsonify }},
88
{%- include snippets/prepend-baseurl.html path=_article.url -%}
99
{%- assign _url = __return -%}
10-
'url':'{{ _url | url_encode }}'}
10+
'url':{{ _url | jsonify }}}
1111
{%- endfor -%}
1212
]
1313
{%- endfor -%}

_includes/search-providers/default/search.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var SOURCES = window.TEXT_VARIABLES.sources;
22
var PAHTS = window.TEXT_VARIABLES.paths;
33
window.Lazyload.js([SOURCES.jquery, PAHTS.search_js], function() {
44
var search = (window.search || (window.search = {}));
5-
var searchData = window.TEXT_SEARCH_DATA ? initData(window.TEXT_SEARCH_DATA) : {};
5+
var searchData = window.TEXT_SEARCH_DATA || {};
66

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

16-
function initData(data) {
17-
var _data = [], i, j, key, keys, cur;
18-
keys = Object.keys(data);
19-
for (i = 0; i < keys.length; i++) {
20-
key = keys[i], _data[key] = [];
21-
for (j = 0; j < data[key].length; j++) {
22-
cur = data[key][j];
23-
cur.title = window.decodeUrl(cur.title);
24-
cur.url = window.decodeUrl(cur.url);
25-
_data[key].push(cur);
26-
}
27-
}
28-
return _data;
29-
}
30-
3116
/// search
3217
function searchByQuery(query) {
3318
var i, j, key, keys, cur, _title, result = {};

0 commit comments

Comments
 (0)