summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--functions.php2
-rw-r--r--index.php2
-rw-r--r--libs/Contents.php10
-rwxr-xr-xlibs/Options.php1
-rw-r--r--libs/Utils.php35
6 files changed, 44 insertions, 8 deletions
diff --git a/README.md b/README.md
index 21e4e76..c780513 100644
--- a/README.md
+++ b/README.md
@@ -177,6 +177,7 @@ $ git clone https://github.com/BigCoke233/miracles.git
- [x] 新增:添加语言包功能,通过 php 数组储存各个语言版本的文字
- [x] 优化:文章缩略图自动剪裁
- [x] 优化:页面/文章评论列表隐藏时,不显示评论数
+- [x] 优化:支持用 jsDelivr 加速主题内置图片的速度
- [ ] 增加:内置站点缓存规则
- [ ] 优化:「说说页面」的样式
- [ ] 新增:图片横向排版「相册功能」(参考:https://blog.imalan.cn/archives/282/)
@@ -190,7 +191,6 @@ $ git clone https://github.com/BigCoke233/miracles.git
- [ ] 优化:对日间模式/日落模式/夜间模式的切换通过下拉面板操作,并支持禁用主题跟随系统设置
- [ ] 新增:导航支持下拉面板
- [ ] 优化:优化夜间模式的切换机制
-- [ ] 优化:支持用 jsDelivr 加速主题内置图片的速度
## 💖 鸣谢
diff --git a/functions.php b/functions.php
index 3a61c87..3903fc3 100644
--- a/functions.php
+++ b/functions.php
@@ -35,6 +35,8 @@ function themeInit($archive) {
Helper::options()->commentsCheckReferer = false;//关闭检查评论来源URL与文章链接是否一致判断(否则会无法评论)
//将设置储存到全局变量以便使用
$GLOBALS['miraclesOptions_randomBanner'] = Helper::options()->randomBanner;
+ $GLOBALS['miraclesOptions_CDN'] = Helper::options()->CDN;
+ $GLOBALS['miraclesOptions_loading_image'] = Helper::options()->loading_image;
}
/**
diff --git a/index.php b/index.php
index b432a4e..f811747 100644
--- a/index.php
+++ b/index.php
@@ -22,7 +22,7 @@ $this->need('includes/header.php');
<div class="col-md-6 post-banner-box">
<a href="<?php $this->permalink(); ?>" class="post-link">
<div class="post-banner">
- <img src="<?php Utils::indexTheme('images/loading/'.$this->options->loading_image.'.gif') ?>" data-gisrc="<?php Utils::postBanner($this); ?>">
+ <img src="<?php echo Utils::addLoadingImages($this->options->CDN, $this->options->loading_image, 'normal'); ?>" data-gisrc="<?php Utils::postBanner($this); ?>">
</div>
</a>
</div>
diff --git a/libs/Contents.php b/libs/Contents.php
index 567c3b2..d821b72 100644
--- a/libs/Contents.php
+++ b/libs/Contents.php
@@ -26,7 +26,7 @@ class Contents
//ParseOther
$text = Contents::parseDetails(Contents::parsePicShadow(Contents::parseNotice(Contents::parseKbd(Contents::parseCode(Contents::parseImages(Contents::parseHeadings(Contents::parseTextColor(Contents::parseRuby(Contents::parseTip($text))))))))));
//LazyLoad
- $text = preg_replace('/<img (.*?)src(.*?)(\/)?>/','<img $1src="/usr/themes/Miracles/images/loading/'.$load_image.'.gif" data-gisrc$2 data-gazeimg />',$text);
+ $text = preg_replace('/<img (.*?)src(.*?)(\/)?>/','<img $1src="'.Utils::addLoadingImages($GLOBALS['miraclesOptions_CDN'], $GLOBALS['miraclesOptions_loading_image'], 'normal').'" data-gisrc$2 data-gazeimg />',$text);
//owo
$text = Contents::parseEmo($text);
//Links
@@ -110,7 +110,7 @@ class Contents
$rp = '<div class="col-lg-2 col-6 col-md-3 links-container">
<a href="${2}" title="${4}" target="_blank" class="links-link">
<div class="links-item">
- <div class="links-img"><img src="/usr/themes/Miracles/images/loading/avatar.jpg" data-gisrc=\'${3}\'></div>
+ <div class="links-img"><img src="'.Utils::addLoadingImages($GLOBALS['miraclesOptions_CDN'], $GLOBALS['miraclesOptions_loading_image'], 'link').'" data-gisrc=\'${3}\'></div>
<div class="links-title">
<h4>${1}</h4>
</div>
@@ -185,7 +185,7 @@ class Contents
*/
private static function parsePaopaoBiaoqingCallback($match)
{
- return '<img class="owo-img" src="/usr/themes/Miracles/images/loading/owo.png" data-gisrc="/usr/themes/Miracles/images/biaoqing/paopao/'. str_replace('%', '', urlencode($match[1])) . '_2x.png">';
+ return '<img class="owo-img" src="'.Utils::addLoadingImages($GLOBALS['miraclesOptions_CDN'], $GLOBALS['miraclesOptions_loading_image'], 'owo').'" data-gisrc="/usr/themes/Miracles/images/biaoqing/paopao/'. str_replace('%', '', urlencode($match[1])) . '_2x.png">';
}
/**
@@ -195,7 +195,7 @@ class Contents
*/
private static function parseAruBiaoqingCallback($match)
{
- return '<img class="owo-img" src="/usr/themes/Miracles/images/loading/owo.png" data-gisrc="/usr/themes/Miracles/images/biaoqing/aru/'. str_replace('%', '', urlencode($match[1])) . '_2x.png">';
+ return '<img class="owo-img" src="'.Utils::addLoadingImages($GLOBALS['miraclesOptions_CDN'], $GLOBALS['miraclesOptions_loading_image'], 'owo').'" data-gisrc="/usr/themes/Miracles/images/biaoqing/aru/'. str_replace('%', '', urlencode($match[1])) . '_2x.png">';
}
/**
@@ -205,7 +205,7 @@ class Contents
*/
private static function parseTweBiaoqingCallback($match)
{
- return '<img class="owo-img" src="/usr/themes/Miracles/images/loading/owo.png" data-gisrc="/usr/themes/Miracles/images/biaoqing/twemoji/'. str_replace('%', '', $match[1]) . '.png">';
+ return '<img class="owo-img" src="'.Utils::addLoadingImages($GLOBALS['miraclesOptions_CDN'], $GLOBALS['miraclesOptions_loading_image'], 'owo').'" data-gisrc="/usr/themes/Miracles/images/biaoqing/twemoji/'. str_replace('%', '', $match[1]) . '.png">';
}
/**
diff --git a/libs/Options.php b/libs/Options.php
index 96721cd..d1b5f13 100755
--- a/libs/Options.php
+++ b/libs/Options.php
@@ -153,6 +153,7 @@ function themeConfig($form) {
$CDN = new Typecho_Widget_Helper_Form_Element_Select('CDN',array(
'0'=>'关闭',
'1'=>'jsDelivr',
+ '6'=>'jsDelivr(仅图片)',
'5'=>'9jojo CDN',
'2'=>'GitHack(实时更新)',
'4'=>'GitHack CDN(较慢)',
diff --git a/libs/Utils.php b/libs/Utils.php
index 27d7658..397448c 100644
--- a/libs/Utils.php
+++ b/libs/Utils.php
@@ -135,7 +135,7 @@ class Utils
$path = 'https://cdn.9jojo.cn/Miracles/'.themeVersion().'/';
}
elseif ($cdn=='3'){
- $path = $custom;
+ $path = $custom;
}else{
$path = Helper::options()->themeUrl("","Miracles/assets");
}
@@ -150,6 +150,39 @@ class Utils
}
/**
+ * 自动生成懒加载图片 url
+ */
+ public static function addLoadingImages($cdn, $loading_image, $type){
+ if ($type=='normal'):
+ $loading = $loading_image;
+ elseif($type=='link'):
+ $loading = 'avatar';
+ elseif($type=='owo'):
+ $loading = 'owo';
+ endif;
+
+ if ($cdn=='1' || $cdn=='6'){
+ $path = 'https://cdn.jsdelivr.net/gh/BigCoke233/miracles@'.themeVersion()."/images/loading/".$loading.'.gif';
+ }
+ elseif ($cdn=='2'){
+ $path = 'https://raw.githack.com/BigCoke233/miracles/master/images/loading/'.$loading.'.gif';
+ }
+ elseif ($cdn=='4'){
+ $path = 'https://rawcdn.githack.com/BigCoke233/miracles/master/images/loading/'.$loading.'.gif';
+ }
+ elseif ($cdn=='5'){
+ //9jojo CDN 并未提供图片缓存 则换用 jsDelivr
+ $path = 'https://cdn.jsdelivr.net/gh/BigCoke233/miracles@'.themeVersion()."/images/loading/".$loading.'.gif';
+ }
+ elseif ($cdn=='3'){
+ $path = $custom;
+ }else{
+ $path = Helper::options()->themeUrl("","Miracles/images/loading").$loading.'.gif';
+ }
+ return $path;
+ }
+
+ /**
* 缩略图
*/
public static function postBanner($post){