From 94281dad539a0fadae7f9f9918d24ae01ec02962 Mon Sep 17 00:00:00 2001 From: Menci Date: Wed, 12 Dec 2018 22:53:59 +0800 Subject: [PATCH] Allow use CDN for static resources of syzoj itself --- config-example.json | 6 +++++- static/{ => self}/mathjax.css | 0 static/{ => self}/script.js | 0 static/{ => self}/style.css | 0 static/{ => self}/syzoj.svg | 0 static/{ => self}/tomorrow.css | 0 views/footer.ejs | 2 +- views/header.ejs | 21 +++++++++++++-------- views/util.ejs | 8 ++++++++ 9 files changed, 27 insertions(+), 10 deletions(-) rename static/{ => self}/mathjax.css (100%) rename static/{ => self}/script.js (100%) rename static/{ => self}/style.css (100%) rename static/{ => self}/syzoj.svg (100%) rename static/{ => self}/tomorrow.css (100%) diff --git a/config-example.json b/config-example.json index 53ebe0a..6166a87 100644 --- a/config-example.json +++ b/config-example.json @@ -114,5 +114,9 @@ "email_jwt_secret": "@EMAIL_JWT_SECRET@", "google_analytics": "UA-XXXXXXXX-X", "cdnjs_url": "https://cdnjs.loli.net/ajax/libs", - "google_fonts_url": "https://fonts.loli.net" + "self_cdn_url": "", + "google_fonts": { + "type": "like-google-fonts", + "url": "https://fonts.loli.net" + } } diff --git a/static/mathjax.css b/static/self/mathjax.css similarity index 100% rename from static/mathjax.css rename to static/self/mathjax.css diff --git a/static/script.js b/static/self/script.js similarity index 100% rename from static/script.js rename to static/self/script.js diff --git a/static/style.css b/static/self/style.css similarity index 100% rename from static/style.css rename to static/self/style.css diff --git a/static/syzoj.svg b/static/self/syzoj.svg similarity index 100% rename from static/syzoj.svg rename to static/self/syzoj.svg diff --git a/static/tomorrow.css b/static/self/tomorrow.css similarity index 100% rename from static/tomorrow.css rename to static/self/tomorrow.css diff --git a/views/footer.ejs b/views/footer.ejs index 99fe28f..8b70b7e 100644 --- a/views/footer.ejs +++ b/views/footer.ejs @@ -7,6 +7,6 @@ - + diff --git a/views/header.ejs b/views/header.ejs index c026729..5d7acdf 100644 --- a/views/header.ejs +++ b/views/header.ejs @@ -7,21 +7,26 @@ <%= title %> - <%= syzoj.config.title %> - - + + + - - <% if (useLocalLibs || !syzoj.config.google_fonts_url) { %> + <% if (useLocalLibs || !syzoj.config.google_fonts || !syzoj.config.google_fonts.url || !['like-google-fonts', 'like-local'].includes(syzoj.config.google_fonts.type)) { %> + <% } else if (syzoj.config.google_fonts.type === 'like-local') { %> + + + + <% } else { %> - - - - + + + + <% } %> <% if (syzoj.config.google_analytics && syzoj.config.google_analytics !== 'UA-XXXXXXXX-X') { %> diff --git a/views/util.ejs b/views/util.ejs index d1cfe65..ba26610 100644 --- a/views/util.ejs +++ b/views/util.ejs @@ -74,4 +74,12 @@ this.lib = uri => { } } +this.selfLib = uri => { + if (useLocalLibs || !syzoj.config.self_cdn_url) { + return syzoj.utils.makeUrl(['self', uri]); + } else { + return syzoj.config.self_cdn_url + '/' + uri; + } +} + %>