Skip to content

Commit ad4a9b9

Browse files
committed
Feature: JavaScript Vendors Customization. iissnan#783
1 parent 4b45189 commit ad4a9b9

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

_config.yml

+33-2
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,39 @@ use_motion: true
261261
# Fancybox
262262
fancybox: true
263263

264-
# Static files
265-
vendors: vendors
264+
265+
# Script Vendors.
266+
# Set a CDN address for the vendor you want to customize.
267+
# For example
268+
# jquery: https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js
269+
# Be aware that you should use the same version as internal ones to avoid potential problems.
270+
vendors:
271+
# Internal path prefix. Please do not edit it.
272+
_internal: vendors
273+
274+
# Internal version: 2.1.3
275+
jquery:
276+
277+
# Internal version: 2.1.5
278+
fancybox:
279+
280+
# Internal version: 1.0.6
281+
fastclick:
282+
283+
# Internal version: 1.9.7
284+
lazyload:
285+
286+
# Internal version: 1.2.1
287+
velocity:
288+
289+
# Internal version: 1.2.1
290+
velocity_ui:
291+
292+
# Internal version: 0.7.9
293+
ua_parser:
294+
295+
296+
# Assets
266297
css: css
267298
js: js
268299
images: images

layout/_partials/head.swig

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@
2424

2525

2626
{% if theme.fancybox %}
27-
<link href="{{ url_for(theme.vendors) }}/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>
27+
<link href="{{ url_for(theme.vendors._internal) }}/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>
2828
{% endif %}
2929

3030

3131
{% if theme.use_font_lato %}
3232
<link href="//fonts.googleapis.com/css?family=Lato:300,400,700,400italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
3333
{% endif %}
3434

35-
36-
<link href="{{ url_for(theme.vendors) }}/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />
35+
<link href="{{ url_for(theme.vendors._internal) }}/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />
3736

3837
<link href="{{ url_for(theme.css) }}/main.css?v={{ theme.version }}" rel="stylesheet" type="text/css" />
3938

layout/_scripts/third-party/comments/duoshuo.swig

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
{% if theme.duoshuo_info.ua_enable %}
2323
{% if theme.duoshuo_info.admin_enable %}
24-
<script src="{{ url_for(theme.vendors) }}/ua-parser-js/dist/ua-parser.min.js"></script>
24+
{% set ua_parser_internal = url_for(theme.vendors._internal) + '/ua-parser-js/dist/ua-parser.min.js?v=0.7.9' %}
25+
<script src="{{ theme.vendors.ua_parser | default(ua_parser_internal) }}"></script>
2526
<script src="{{ url_for(theme.js) }}/src/hook-duoshuo.js"></script>
2627
{% endif %}
2728
{% endif %}

layout/_scripts/vendors.swig

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
{%
2-
set js_vendors = [
3-
'jquery/index.js?v=2.1.3',
4-
'fastclick/lib/fastclick.min.js?v=1.0.6',
5-
'jquery_lazyload/jquery.lazyload.js?v=1.9.7',
6-
'velocity/velocity.min.js',
7-
'velocity/velocity.ui.min.js'
8-
]
9-
%}
10-
11-
{% if theme.fancybox %}
12-
{% set js_vendors[js_vendors.length] = 'fancybox/source/jquery.fancybox.pack.js' %}
13-
{% endif %}
14-
151
{# Reset `window.Promise` when it was not a function. #}
162
{# IE refers the element whose id is `Promise` as `window.Promise`, this causes Velocity throwing an exception #}
173
<script type="text/javascript">
@@ -20,6 +6,18 @@
206
}
217
</script>
228

23-
{% for vendor in js_vendors %}
24-
<script type="text/javascript" src="{{ url_for(theme.vendors) }}/{{ vendor }}"></script>
9+
{% set js_vendors = {} %}
10+
{% set js_vendors.jquery = '/jquery/index.js?v=2.1.3' %}
11+
{% set js_vendors.fastclick = '/fastclick/lib/fastclick.min.js?v=1.0.6' %}
12+
{% set js_vendors.lazyload = '/jquery_lazyload/jquery.lazyload.js?v=1.9.7' %}
13+
{% set js_vendors.velocity = '/velocity/velocity.min.js?v=1.2.1' %}
14+
{% set js_vendors.velocity_ui = '/velocity/velocity.ui.min.js?v=1.2.1' %}
15+
16+
{% if theme.fancybox %}
17+
{% set js_vendors.fancybox = 'fancybox/source/jquery.fancybox.pack.js?v=2.1.5' %}
18+
{% endif %}
19+
20+
{% for name, internal in js_vendors %}
21+
{% set internal_script = url_for(theme.vendors._internal) + internal %}
22+
<script type="text/javascript" src="{{ theme.vendors[name] | default(internal_script) }}"></script>
2523
{% endfor %}

0 commit comments

Comments
 (0)