Skip to content

Commit

Permalink
Version 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
{{ouyangyanhuo}} committed Aug 19, 2021
1 parent 4d25a5e commit 85fdf64
Show file tree
Hide file tree
Showing 7 changed files with 1,762 additions and 10 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
一个为typecho移植的主题,源自于[hugo-tania](https://github.com/WingLim/hugo-tania)主题,原本是Hugo的主题,被移植到Typecho上

[![AdminMD](https://img.shields.io/badge/Magneto-SmileTheme-brightgreen?style=for-the-badge&logo=github)](https://www.symbk.cn/technology/523/)
![Version](https://img.shields.io/badge/Version-1.0-critical?style=for-the-badge&logo=gitee)
![Version](https://img.shields.io/badge/Version-1.2-critical?style=for-the-badge&logo=gitee)
![Repo-size](https://img.shields.io/github/repo-size/ouyangyanhuo/SmileTheme?style=for-the-badge&logo=google)
![License](https://img.shields.io/github/license/ouyangyanhuo/SmileTheme?style=for-the-badge&logo=twitter)
![Stars](https://img.shields.io/github/stars/ouyangyanhuo/SmileTheme?style=for-the-badge&logo=Instagram)
Expand All @@ -13,16 +13,14 @@

## 最近版本更新日志

1.修改开源协议(GPL V3.0)
1.✨新增了代码压缩功能。

2.修复首页版权链接指向问题

3.完善了 `README.md` 文档
2.优化了代码构成

## 功能与特性
- 简洁风格

- 适配黑暗模式
- 适配深色模式

- HTML 原生自响应式布局

Expand Down
51 changes: 51 additions & 0 deletions core/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;

function compressHtml($html_source)
{
$chunks = preg_split('/(<!--<nocompress>-->.*?<!--<\/nocompress>-->|<nocompress>.*?<\/nocompress>|<pre.*?\/pre>|<textarea.*?\/textarea>|<script.*?\/script>)/msi', $html_source, -1, PREG_SPLIT_DELIM_CAPTURE);
$compress = '';
foreach ($chunks as $c) {
if (strtolower(substr($c, 0, 19)) == '<!--<nocompress>-->') {
$c = substr($c, 19, strlen($c) - 19 - 20);
$compress .= $c;
continue;
} else if (strtolower(substr($c, 0, 12)) == '<nocompress>') {
$c = substr($c, 12, strlen($c) - 12 - 13);
$compress .= $c;
continue;
} else if (strtolower(substr($c, 0, 4)) == '<pre' || strtolower(substr($c, 0, 9)) == '<textarea') {
$compress .= $c;
continue;
} else if (strtolower(substr($c, 0, 7)) == '<script' && strpos($c, '//') != false && (strpos($c, "\r") !== false || strpos($c, "\n") !== false)) {
$tmps = preg_split('/(\r|\n)/ms', $c, -1, PREG_SPLIT_NO_EMPTY);
$c = '';
foreach ($tmps as $tmp) {
if (strpos($tmp, '//') !== false) {
if (substr(trim($tmp), 0, 2) == '//') {
continue;
}
$chars = preg_split('//', $tmp, -1, PREG_SPLIT_NO_EMPTY);
$is_quot = $is_apos = false;
foreach ($chars as $key => $char) {
if ($char == '"' && $chars[$key - 1] != '\\' && !$is_apos) {
$is_quot = !$is_quot;
} else if ($char == '\'' && $chars[$key - 1] != '\\' && !$is_quot) {
$is_apos = !$is_apos;
} else if ($char == '/' && $chars[$key + 1] == '/' && !$is_quot && !$is_apos) {
$tmp = substr($tmp, 0, $key);
break;
}
}
}
$c .= $tmp;
}
}
$c = preg_replace('/[\\n\\r\\t]+/', ' ', $c);
$c = preg_replace('/\\s{2,}/', ' ', $c);
$c = preg_replace('/>\\s</', '> <', $c);
$c = preg_replace('/\\/\\*.*?\\*\\//i', '', $c);
$c = preg_replace('/<!--[^!]*-->/', '', $c);
$compress .= $c;
}
return $compress;
}
12 changes: 11 additions & 1 deletion footer.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
</body>
<footer class="footer flex">
<section class="container">
<nav class="footer-links">
Expand All @@ -10,4 +11,13 @@
<?php if ($this->options->The_Dark_Mode): ?>
<script async="" src="<?php $this->options->themeUrl('/main/features.js'); ?>" data-enable-footnotes="true"></script>
<?php endif; ?>
</footer>
</footer>
</html>
<?php /* 来自 MDr | HTML 压缩 */
if ($this->options->compressHtml) {
$html_source = ob_get_contents();
ob_clean();
print compressHtml($html_source);
ob_end_flush();
}
?>
17 changes: 17 additions & 0 deletions functions.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
define('INITIAL_VERSION_NUMBER', '1.0');
if (Helper::options()->GravatarUrl) define('__TYPECHO_GRAVATAR_PREFIX__', Helper::options()->GravatarUrl);
require_once __DIR__ . '/core/functions.php';
function themeConfig($form) {

/* favicon */
Expand Down Expand Up @@ -81,6 +82,22 @@ function themeConfig($form) {
);
$form->addInput($The_Dark_Mode);

/* 代码压缩 */
$TheNotice = new Typecho_Widget_Helper_Form_Element_Text('TheNotice', NULL, NULL, _t('<h2 id="mdr-nav">代码压缩</h2>'));
$TheNotice->input->setAttribute('style', 'display:none');
$form->addInput($TheNotice);
$compressHtml = new Typecho_Widget_Helper_Form_Element_Radio(
'compressHtml',
array(
1 => _t('启用'),
0 => _t('关闭')
),
0,
_t('HTML压缩'),
_t('默认关闭,启用则会对HTML代码进行压缩,可能与部分插件存在兼容问题,请酌情选择开启或者关闭')
);
$form->addInput($compressHtml);

/* 图标 */
$TheNotice = new Typecho_Widget_Helper_Form_Element_Text('TheNotice', NULL, NULL, _t('<h2 id="mdr-nav">图标 <small>Icon</small></h2>'));
$TheNotice->input->setAttribute('style', 'display:none');
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package Smile Theme
* @author Magneto
* @version 1.1
* @version 1.2
* @link https://www.symbk.cn
*/

Expand Down
1,678 changes: 1,677 additions & 1 deletion main/main.all.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion post.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
</header>
</article>
<div class="article-post">
<div id="post" class="article-post">
<?php $this->content(); ?>
</div>
</div>
Expand Down

0 comments on commit 85fdf64

Please sign in to comment.