From b6dd004753520dfc6ff2d3dd8e389b5bd2908068 Mon Sep 17 00:00:00 2001 From: Menci Date: Thu, 16 May 2019 18:56:19 +0800 Subject: [PATCH] Use jsDelivr as default CDN for ALL static files --- config-example.json | 8 ++++---- views/header.ejs | 9 +++++++-- views/util.ejs | 6 ++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/config-example.json b/config-example.json index 6bc6935..6447968 100644 --- a/config-example.json +++ b/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, diff --git a/views/header.ejs b/views/header.ejs index a8e8179..aee00e3 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -11,7 +11,7 @@ - <% 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)) { %> @@ -21,11 +21,16 @@ - <% } else { %> + <% } else if (syzoj.config.google_fonts.type === 'like-google-fonts') { %> + <% } else if (syzoj.config.google_fonts.type === 'built-in') { %> + + + + <% } %> <% if (syzoj.config.google_analytics && syzoj.config.google_analytics !== 'UA-XXXXXXXX-X') { %> diff --git a/views/util.ejs b/views/util.ejs index ba26610..9ac14e2 100644 --- a/views/util.ejs +++ b/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; }