diff options
| author | BigCoke233 <hi@guhub.cn> | 2020-04-12 15:34:50 +0800 |
|---|---|---|
| committer | BigCoke233 <hi@guhub.cn> | 2020-04-12 15:34:50 +0800 |
| commit | 8a03995d72a9afe999c243cffd1fae05b441c172 (patch) | |
| tree | 527fc1e6b1961d93b1d7b4ef6ecb8bd896fb6731 | |
| parent | 6ea3d1d34ace40447f5505eb13f132d5876b4c70 (diff) | |
:books: Add: 支持自定义静态资源 CDN
| -rw-r--r-- | functions.php | 16 | ||||
| -rw-r--r-- | includes/footer.php | 3 | ||||
| -rw-r--r-- | includes/head.php | 3 | ||||
| -rwxr-xr-x | libs/Options.php | 6 |
4 files changed, 20 insertions, 8 deletions
diff --git a/functions.php b/functions.php index 552454b..be3fccc 100644 --- a/functions.php +++ b/functions.php @@ -80,10 +80,18 @@ array_push($views, $cid); /** * 自动生成引用 */ -function generate_require($files,$type,$cdn = NULL) { - if ($cdn) - $path = $cdn.themeVersion()."/"; - else $path = Helper::options()->themeUrl("","Miracles"); +function generate_require($files,$type,$cdn,$custom) { + if ($cdn=='1'){ + $path = 'https://cdn.jsdelivr.net/gh/BigCoke233/miracles@'.themeVersion()."/"; + } + elseif ($cdn=='2'){ + $path = 'http://raw.githack.com/BigCoke233/miracles/master/'; + } + elseif ($cdn=='3'){ + $path = $custom; + }else{ + $path = Helper::options()->themeUrl("","Miracles"); + } foreach ($files as $file) { if ($type == "js") echo "<script src=".$path."assets/".$type."/".$file.".".$type."></script>"; diff --git a/includes/footer.php b/includes/footer.php index 6c82d26..94c9d48 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -23,7 +23,8 @@ <!-- JavaScript Require--> <?php $js_files=array("jquery","pjax.jquery","jquery.fancybox","jquery.lazyload.min","nprogress","OwO.min","highlight","highlight-line-number","pangu","qrcode.min"); - generate_require($js_files,"js",$this->options->CDN?"https://cdn.jsdelivr.net/gh/BigCoke233/miracles@":""); + if($this->options->customCDN): $custom=$this->options->customCDN; else: $custom=Helper::options()->themeUrl("","Miracles"); endif; + generate_require($js_files,"js",$this->options->CDN,$custom); ?> <!-- Varribles and Functions --> <script> diff --git a/includes/head.php b/includes/head.php index 7d65937..404f6c2 100644 --- a/includes/head.php +++ b/includes/head.php @@ -45,7 +45,8 @@ <!-- css --> <?php $css_files=array("codestyle","owo.min","nprogress","fancybox","main/miracles.min"); - generate_require($css_files,"css",$this->options->CDN?"https://cdn.jsdelivr.net/gh/BigCoke233/miracles@":""); + if($this->options->customCDN): $custom=$this->options->customCDN; else: $custom=Helper::options()->themeUrl("","Miracles"); endif; + generate_require($css_files,"css",$this->options->CDN,$custom); ?> <!-- icon font --> <link rel="stylesheet" href="//at.alicdn.com/t/font_1165190_1djdjjwge4m.css" /> diff --git a/libs/Options.php b/libs/Options.php index d16d2d4..226e0fc 100755 --- a/libs/Options.php +++ b/libs/Options.php @@ -134,9 +134,11 @@ function themeConfig($form) { $form->addInput($pjax_complete);
//improve
- $CDN = new Typecho_Widget_Helper_Form_Element_Select('CDN',array('0'=>'关闭','1'=>'开启'),'0','<h2>优化</h2>CDN 加速加载静态资源(Beta)','开启后静态资源文件调用 JSdelivr 的 CDN 公用库,加快网页加载速度。本身有 CDN 的就不用了,不然反而可能会拖慢速度。');
+ $CDN = new Typecho_Widget_Helper_Form_Element_Select('CDN',array('0'=>'关闭','1'=>'jsDelivr','2'=>'GitHack(国内较慢)','3'=>'自定义'),'0','<h2>优化</h2>CDN 加速加载静态资源(Beta)','开启后静态资源文件通过选择的 CDN 进行调用,加快网页加载速度。如果选择自定义则需要填写下一个设置项。<br>*如果你使用开发版,请不要选择 jsDelivr 作为 CDN');
$form->addInput($CDN);
- $ifShowRTA = new Typecho_Widget_Helper_Form_Element_Select('ifShowRTA',array('0'=>'不显示','1'=>'显示'),'0','阅读时长提示 RTA','在文章前加入阅读时长提示,增进用户体验');
+ $customCDN = new Typecho_Widget_Helper_Form_Element_Text('customCDN', NULL, '', _t('自定义 CDN'), _t('输入 CDN 的链接,要保证写入的路径下,目录结构和主题的 assets 目录下一致'));
+ $form->addInput($customCDN);
+ $ifShowRTA = new Typecho_Widget_Helper_Form_Element_Select('ifShowRTA',array('0'=>'不显示','1'=>'显示'),'0','阅读时长提示 RTA','在文章前加入阅读时长提示,增进用户体验<hr>');
$form->addInput($ifShowRTA);
//custom style
|
