Browse Source

Use jsDelivr as default CDN for ALL static files

pull/6/head
Menci 6 years ago
parent
commit
b6dd004753
  1. 8
      config-example.json
  2. 9
      views/header.ejs
  3. 6
      views/util.ejs

8
config-example.json

@ -117,11 +117,11 @@
"email_jwt_secret": "@EMAIL_JWT_SECRET@",
"google_analytics": "UA-XXXXXXXX-X",
"gravatar_url": "https://cdn.v2ex.com/gravatar",
"cdnjs_url": "https://cdnjs.loli.net/ajax/libs",
"self_cdn_url": "",
"cdnjs_url": "built-in",
"self_cdn_url": "built-in",
"google_fonts": {
"type": "like-google-fonts",
"url": "https://fonts.loli.net"
"type": "built-in",
"url": ""
},
"no_cdn": false,
"submissions_page_fast_pagination": false,

9
views/header.ejs

@ -11,7 +11,7 @@
<link href="<%- selfLib('math.css') %>" rel="stylesheet">
<link href="<%- selfLib('style.css') %>?20181212" rel="stylesheet">
<link href="<%- lib('morris.js/0.5.1/morris.css') %>" rel="stylesheet">
<% if (useLocalLibs || !syzoj.config.google_fonts || !syzoj.config.google_fonts.url || !['like-google-fonts', 'like-local'].includes(syzoj.config.google_fonts.type)) { %>
<% if (useLocalLibs || !syzoj.config.google_fonts || !['like-google-fonts', 'like-local', 'built-in'].includes(syzoj.config.google_fonts.type)) { %>
<link href="<%- syzoj.utils.makeUrl(['google-fonts', 'fira-mono.css']) %>" rel="stylesheet">
<link href="<%- syzoj.utils.makeUrl(['google-fonts', 'lato.css']) %>" rel="stylesheet">
<link href="<%- syzoj.utils.makeUrl(['google-fonts', 'open-sans.css']) %>" rel="stylesheet">
@ -21,11 +21,16 @@
<link href="<%- syzoj.config.google_fonts.url %>/google-fonts/lato.css" rel="stylesheet">
<link href="<%- syzoj.config.google_fonts.url %>/google-fonts/open-sans.css" rel="stylesheet">
<link href="<%- syzoj.config.google_fonts.url %>/google-fonts/exo-2.css" rel="stylesheet">
<% } else { %>
<% } else if (syzoj.config.google_fonts.type === 'like-google-fonts') { %>
<link href="<%- syzoj.config.google_fonts.url %>/css?family=Fira+Mono" rel="stylesheet">
<link href="<%- syzoj.config.google_fonts.url %>/css?family=Lato:400,700,400italic,700italic&subset=latin" rel="stylesheet">
<link href="<%- syzoj.config.google_fonts.url %>/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i&amp;subset=latin-ext" rel="stylesheet">
<link href="<%- syzoj.config.google_fonts.url %>/css?family=Exo+2:600" rel="stylesheet">
<% } else if (syzoj.config.google_fonts.type === 'built-in') { %>
<link href="<%- this.builtInCdnUrl %>/google-fonts/fira-mono.css" rel="stylesheet">
<link href="<%- this.builtInCdnUrl %>/google-fonts/lato.css" rel="stylesheet">
<link href="<%- this.builtInCdnUrl %>/google-fonts/open-sans.css" rel="stylesheet">
<link href="<%- this.builtInCdnUrl %>/google-fonts/exo-2.css" rel="stylesheet">
<% } %>
<script src="<%- lib('jquery/3.3.1/jquery.min.js') %>"></script>
<% if (syzoj.config.google_analytics && syzoj.config.google_analytics !== 'UA-XXXXXXXX-X') { %>

6
views/util.ejs

@ -66,9 +66,13 @@ this.iconHidden = [
'Skipped'
];
this.builtInCdnUrl = 'https://cdn.jsdelivr.net/npm/syzoj-public-cdn@1.0.5';
this.lib = uri => {
if (useLocalLibs || !syzoj.config.cdnjs_url) {
return syzoj.utils.makeUrl(['cdnjs', uri]);
} else if (syzoj.config.cdnjs_url === 'built-in') {
return builtInCdnUrl + '/cdnjs/' + uri;
} else {
return syzoj.config.cdnjs_url + '/' + uri;
}
@ -77,6 +81,8 @@ this.lib = uri => {
this.selfLib = uri => {
if (useLocalLibs || !syzoj.config.self_cdn_url) {
return syzoj.utils.makeUrl(['self', uri]);
} else if (syzoj.config.self_cdn_url === 'built-in') {
return builtInCdnUrl + '/self/' + uri;
} else {
return syzoj.config.self_cdn_url + '/' + uri;
}

Loading…
Cancel
Save