Skip to content

Commit 38e907f

Browse files
committed
✨ 支持使用CDN加速本主题内的静态文件.
1 parent a89af7e commit 38e907f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

footer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
</p>
1111
</footer>
1212
</section>
13-
<script src="<?php $this->options->themeUrl('highlight.js'); ?>"></script>
13+
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
14+
<script src="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.js"></script>
15+
<?php else : ?>
16+
<script src="<?php $this->options->themeUrl('highlight.js'); ?>?v=<?php echo CACTUS_VERSION; ?>"></script>
17+
<?php endif; ?>
1418
<script>hljs.initHighlightingOnLoad();</script>
1519
<?php $this->footer(); ?>
1620
<?php $this->options->footer(); ?>

functions.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
33

4+
define('CACTUS_VERSION', '1.0.3');
5+
46
function themeConfig($form) {
57
$avatarUrl = new Typecho_Widget_Helper_Form_Element_Text('avatarUrl', NULL, NULL, _t('头像 URL 地址'), _t('在这里填入一个图片 URL 地址, 留空则返回 Gravatar, 不建议留空.'));
68
$form->addInput($avatarUrl);
@@ -11,6 +13,13 @@ function themeConfig($form) {
1113
$icpNumber = new Typecho_Widget_Helper_Form_Element_Text('icpNumber', NULL, NULL, _t('ICP 备案许可证号'), _t('在这里填入一个 ICP 备案许可证号, 留空则不显示.'));
1214
$form->addInput($icpNumber);
1315

16+
$optimizeOptions = new Typecho_Widget_Helper_Form_Element_Checkbox('optimizeOptions', array(
17+
'EnableCdn' => _t('使用 CDN 加速本主题内的 CSS & JS 文件')
18+
), array(
19+
'EnableCdn'
20+
), _t('优化选项'));
21+
$form->addInput($optimizeOptions->multiMode());
22+
1423
$header = new Typecho_Widget_Helper_Form_Element_Textarea('header', NULL, NULL, _t('自定义 Header'), _t('在这里填入自定义 Header, 如自定义 CSS 样式等.'));
1524
$form->addInput($header);
1625

header.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@
1515
<?php if ($this->options->themeColor) : ?>
1616
<meta name="theme-color" content="<?php $this->options->themeColor(); ?>" />
1717
<?php endif; ?>
18-
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>">
19-
<link rel="stylesheet" href="<?php $this->options->themeUrl('highlight.css'); ?>">
18+
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
19+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/style.min.css">
20+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.css">
21+
<?php else : ?>
22+
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
23+
<link rel="stylesheet" href="<?php $this->options->themeUrl('highlight.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
24+
<?php endif; ?>
2025
<?php $this->header(); ?>
2126
<?php $this->options->header(); ?>
2227

0 commit comments

Comments
 (0)