Skip to content

Commit

Permalink
✨ 支持使用CDN加速本主题内的静态文件.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoharWang committed Apr 4, 2018
1 parent a89af7e commit 38e907f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
</p>
</footer>
</section>
<script src="<?php $this->options->themeUrl('highlight.js'); ?>"></script>
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
<script src="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.js"></script>
<?php else : ?>
<script src="<?php $this->options->themeUrl('highlight.js'); ?>?v=<?php echo CACTUS_VERSION; ?>"></script>
<?php endif; ?>
<script>hljs.initHighlightingOnLoad();</script>
<?php $this->footer(); ?>
<?php $this->options->footer(); ?>
Expand Down
9 changes: 9 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

define('CACTUS_VERSION', '1.0.3');

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

$optimizeOptions = new Typecho_Widget_Helper_Form_Element_Checkbox('optimizeOptions', array(
'EnableCdn' => _t('使用 CDN 加速本主题内的 CSS & JS 文件')
), array(
'EnableCdn'
), _t('优化选项'));
$form->addInput($optimizeOptions->multiMode());

$header = new Typecho_Widget_Helper_Form_Element_Textarea('header', NULL, NULL, _t('自定义 Header'), _t('在这里填入自定义 Header, 如自定义 CSS 样式等.'));
$form->addInput($header);

Expand Down
9 changes: 7 additions & 2 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
<?php if ($this->options->themeColor) : ?>
<meta name="theme-color" content="<?php $this->options->themeColor(); ?>" />
<?php endif; ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('highlight.css'); ?>">
<?php if (!empty($this->options->optimizeOptions) && in_array('EnableCdn', $this->options->optimizeOptions)) : ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/style.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ZoharWang/typecho-theme-Cactus@<?php echo CACTUS_VERSION; ?>/highlight.min.css">
<?php else : ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('style.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
<link rel="stylesheet" href="<?php $this->options->themeUrl('highlight.css'); ?>?v=<?php echo CACTUS_VERSION; ?>">
<?php endif; ?>
<?php $this->header(); ?>
<?php $this->options->header(); ?>

Expand Down

0 comments on commit 38e907f

Please sign in to comment.