Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
remove HTML compression, change pangu processing range
Browse files Browse the repository at this point in the history
  • Loading branch information
EAimTY committed Sep 13, 2020
1 parent 0dea708 commit 891edcb
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 68 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.5
- 移除 HTML 压缩
- 更改 pangu 的处理范围,现在只有文章内容中的中文与西文、中文与数字间会自动插入空格
- 完善对<nopangu>标签的处理
## 4.4
- 为 Pjax 加入开关
- 优化在窄屏幕设备上 footer 的显示
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ https://github.com/EAimTY/materiality-typecho-theme
- 支持图片懒加载
- 可自由切换主题颜色
- 可手动或根据时间(20:00~7:00)自动切换暗色模式
- 可在中文、西文、数字间自动插入空格
- 可开启 HTML 压缩
- 可在文章内容中的中文与西文、中文与数字间自动插入空格
- 自动创建文章目录,并且可为每篇文章与页面分别设置其是否显示
- 可自定义应用栏、侧边栏、文章信息、页脚中显示的内容
- 主题选项中可直接设置友情链接
Expand All @@ -30,10 +29,11 @@ https://github.com/EAimTY/materiality-typecho-theme
2. 在保证浏览文字内容时体验良好的情况下,本主题会保证整体的简洁性,不会加入任何与提升文字阅读体验无关的功能
3. `显示暗色模式切换按钮``自动切换暗色模式`互不依赖,可同时开启、关闭或分别开启
4. 在文章中不需要于列表、归档中显示的部分前加入分割符`<!--more-->`即可将其后内容隐藏
5. 由于 Pjax 与评论反垃圾不兼容,本主题默认关闭了评论反垃圾保护,如有需求可使用插件替代
6. 如果您从本主题的较低版本升级到了最新版本,由于新版本对函数、变量和 cookies 的命名做了更改,主题设置可能会丢失,并且请清除浏览器缓存、CDN 缓存与网站 Cookies 以免旧缓存产生未知问题
7. 本主题已日渐完善,今后的更新将以修复漏洞为主,不再会非常频繁地加入新功能
8. 如果您对本主题有任何建议或有问题需要反馈,可以提交 Issue、PR,或通过其它方式联系我
5. 对于不需要在中文与西文、中文与数字间插入空格的内容,可将其放入`<nopangu></nopangu>`标签内,pangu将不处理`<nopangu>`标签中的内容
6. 由于 Pjax 与评论反垃圾不兼容,本主题默认关闭了评论反垃圾保护,如有需求可使用插件替代
7. 如果您从本主题的较低版本升级到了最新版本,由于新版本对函数、变量和 cookies 的命名做了更改,主题设置可能会丢失,并且请清除浏览器缓存、CDN 缓存与网站 Cookies 以免旧缓存产生未知问题
8. 本主题已日渐完善,今后的更新将以修复漏洞为主,不再会非常频繁地加入新功能
9. 如果您对本主题有任何建议或有问题需要反馈,可以提交 Issue、PR,或通过其它方式联系我

# 使用
1. 前往 [Releases页](https://github.com/EAimTY/materiality-typecho-theme/releases) 下载或使用 Git 克隆主题至`usr/themes/`
Expand All @@ -42,7 +42,7 @@ https://github.com/EAimTY/materiality-typecho-theme
4. 清除浏览器缓存、CDN 缓存与网站 Cookies 以免与之前使用的主题发生冲突

# 版本
4.4
4.5

# 更新日志
[CHANGELOG](https://github.com/EAimTY/materiality-typecho-theme/blob/master/CHANGELOG.md)
Expand Down
4 changes: 2 additions & 2 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
<div class="mdui-card-primary-subtitle mdui-text-color-theme-text">
<?php $this->date(); ?>
<?php if (in_array('author', $this->options->article)): ?>
<span> |</span><i class="mdui-icon materiality-icons">&#xe904;</i><a href="<?php $this->author->permalink(); ?>"><?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?><?php $this->author(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?></a>
<span> |</span><i class="mdui-icon materiality-icons">&#xe904;</i><a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a>
<?php endif; ?>
<?php if ($this->category && in_array('categories', $this->options->article)): ?>
<span> | </span><i class="mdui-icon materiality-icons">&#xe907;</i><?php $this->category(', '); ?>
<?php endif; ?>
</div>
</div>
<div class="mdui-card-content mdui-typo"><?php $this->content(); ?></div>
<div class="mdui-card-content mdui-typo"><?php if (in_array('pangu', $this->options->feature)) echo "<pangu>"; ?><?php $this->content(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</pangu>"; ?></div>
<div class="mdui-card-actions">
<a class="mdui-btn mdui-ripple mdui-text-color-theme-accent" href="<?php $this->permalink(); ?>">继续阅读</a>
</div>
Expand Down
2 changes: 0 additions & 2 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<?php endif; ?>
<?php if($this->allow('comment')): ?>
<div id="<?php $this->respondId(); ?>">
<?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?>
<div class="mdui-card mdui-m-y-3">
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
<div class="mdui-card-header"><h2>添加新评论</h2></div>
Expand Down Expand Up @@ -80,7 +79,6 @@
</div>
</form>
</div>
<?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?>
</div>
<?php elseif (!$this->allow('comment') && in_array('comment_disabled', $this->options->article)): ?>
<div class="mdui-chip mdui-m-b-2">
Expand Down
10 changes: 3 additions & 7 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@
</div>
</div>
<div class="footer-copyright mdui-col-xs-6 mdui-valign">
<div class="mdui-center">
<?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?>
Copyright &copy; <?php echo date("Y"); ?> <a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title(); ?></a>
<?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?>
</div>
<div class="mdui-center">Copyright &copy; <?php echo date("Y"); ?> <a href="<?php $this->options->siteUrl(); ?>"><?php $this->options->title(); ?></a></div>
</div>
<div class="footer-credit mdui-col-xs-3 mdui-valign">
<div class="mdui-center">
<div>Powered by <a href="http://typecho.org/" target="_blank">Typecho)))</a></div>
<div>and Theme <a href="https://www.eaimty.com/theme.html" target="_blank">materiality</a></div>
<?php if ($this->options->miibeian): ?>
<div><a href="http://www.beian.miit.gov.cn/" target="_blank"><?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?><?php $this->options->miibeian(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?></a></div>
<div><a href="http://www.beian.miit.gov.cn/" target="_blank"><?php $this->options->miibeian(); ?></a></div>
<?php endif; ?>
</div>
</div>
Expand All @@ -45,4 +41,4 @@
</body>
<?php $this->footer(); ?>
</html>
<?php outputEnd(in_array('pangu', $this->options->feature), in_array('compressHTML', $this->options->feature), in_array('lazyLoad', $this->options->feature)); ?>
<?php outputEnd(in_array('pangu', $this->options->feature), in_array('lazyLoad', $this->options->feature)); ?>
61 changes: 19 additions & 42 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ function getLinks($obj) {
$links_arr = explode("\n", trim($obj));
foreach ($links_arr as $link) {
$link = explode("\", \"", substr(trim($link), 1, -1));
$link[1] = str_replace("'", "\\'", $link[1]);
$link[1] = str_replace("\"", "&quot;", $link[1]);
$link[1] = str_replace("\"", "&quot;", str_replace("'", "\\'", $link[1]));
echo '<a class="mdui-list-item mdui-ripple" target="_blank" rel="external friend noopener" href="' . $link[2] . (($link[1]) ? '" mdui-tooltip="{content: \'' . $link[1] . '\'}">' : '">') . $link[0] . '</a>' . "\n";
}
}
Expand Down Expand Up @@ -192,31 +191,12 @@ function pangu($text) {
return $text;
}

function compressHTML($html) {
$search = [
'/[\\n\\r\\t]+/',
'/\\s{2,}/',
'/>\\s</',
'/\\/\\*.*?\\*\\//i',
'/<!--[^!]*-->/'
];
$replace = [
'',
' ',
'><',
'',
''
];
$html = preg_replace($search, $replace, $html);
return $html;
}

function outputStart() {
ob_end_clean();
ob_start();
}

function outputEnd($pangu, $compressHTML, $lazyLoad) {
function outputEnd($pangu, $lazyLoad) {
$output = ob_get_contents();
ob_end_clean();
if ($lazyLoad) {
Expand All @@ -229,27 +209,25 @@ function outputEnd($pangu, $compressHTML, $lazyLoad) {
}
$output = $dom->saveHtml();
}
if ($pangu || $compressHTML) {
$output = preg_split('/(<nopangu.*?\/nopangu>|<pre.*?\/pre>|<code.*?\/code>|<textarea.*?\/textarea>|<div name="comment-author".*?\/div>)/msi', $output, NULL, PREG_SPLIT_DELIM_CAPTURE);
foreach ($output as $key => $value) {
if (
substr_compare($value, '<pre', 0, 4) !== 0 &&
substr_compare($value, '<code', 0, 5) !== 0 &&
substr_compare($value, '<textarea', 0, 9) !== 0
) {
if ($pangu) {
if (substr_compare($value, '<nopangu', 0, 8) === 0) {
$value = substr($value, 9, -10);
} elseif (substr_compare($value, '<div name="comment-author"', 0, 24) === 0) {
} else {
$value = pangu($value);
if ($pangu) {
$output = preg_split('/(<pangu.*?\/pangu>)/msi', $output, NULL, PREG_SPLIT_DELIM_CAPTURE);
foreach ($output as $splitKey => $splitValue) {
if (substr_compare($splitValue, '<pangu>', 0, 7) == 0) {
$splitValue = preg_split('/(<nopangu.*?\/nopangu>|<pre.*?\/pre>|<code.*?\/code>|<textarea.*?\/textarea>)/msi', substr($splitValue, 7, -8), NULL, PREG_SPLIT_DELIM_CAPTURE);
foreach ($splitValue as $exceptKey => $exceptValue) {
if (
substr_compare($value, '<nopangu', 0, 8) !== 0 &&
substr_compare($value, '<pre', 0, 4) !== 0 &&
substr_compare($value, '<code', 0, 5) !== 0 &&
substr_compare($value, '<textarea', 0, 9) !== 0
) {
$exceptValue = pangu($exceptValue);
}
$splitValue[$exceptKey] = $exceptValue;
}
if ($compressHTML) {
$value = compressHTML($value);
}
$output[$key] = $value;
$splitValue = implode('', $splitValue);
}
$output[$splitKey] = $splitValue;
}
$output = implode('', $output);
}
Expand Down Expand Up @@ -306,9 +284,8 @@ function themeConfig($cfg) {

$feature = new Typecho_Widget_Helper_Form_Element_Checkbox('feature', [
'autoDark' => _t('自动切换至暗色模式(20:00~7:00)'),
'pangu' => _t('在中文、西文、数字间自动插入空格'),
'pangu' => _t('在文章内容中的中文与西文、中文与数字间自动插入空格'),
'pjax' => _t('启用 Pjax 无刷新加载页面'),
'compressHTML' => _t('启用 HTML 压缩(需要消耗一定性能,不建议在服务器性能低或网站 PV 高时开启)'),
'lazyLoad' => _t('延迟加载图片(在页面中其它内容加载完毕后再加载图片,能够优化多图片页面的加载速度)'),
'smoothScroll' => _t('启用惯性滚动(将改善页面滚动时的体验,但可能会造成页面滚动时轻微掉帧)')
], ['autoDark', 'pjax', 'smoothScroll'], _t('主题功能设置'));
Expand Down
8 changes: 3 additions & 5 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
'search' => _t('包含关键字 %s 的文章'),
'tag' => _t('标签 %s 下的文章'),
'author' => _t('%s 发布的文章')
], '', ' - '); ?><?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?><?php $this->options->title(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?></title>
], '', ' - '); ?><?php $this->options->title(); ?></title>
</head>
<body class="<?php if (!in_array('hidden', $this->options->drawer)): ?>mdui-drawer-body-left <?php endif; ?> mdui-appbar-with-toolbar mdui-theme-primary-<?php $this->options->primaryColor(); ?> mdui-theme-accent-<?php $this->options->accentColor(); ?>">
<header class="mdui-appbar mdui-appbar-fixed">
<div class="mdui-toolbar mdui-color-theme">
<span class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white" mdui-drawer="{target: '#drawer', swipe: true}"><i class="mdui-icon materiality-icons">&#xe900;</i></span>
<a href="<?php $this->options->siteUrl(); ?>" class="mdui-typo-headline"><?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?><?php $this->options->title(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?></a>
<a href="<?php $this->options->siteUrl(); ?>" class="mdui-typo-headline"><?php $this->options->title(); ?></a>
<div class="mdui-toolbar-spacer"></div>
<?php if (in_array('darkToggle', $this->options->appbar)): ?>
<span class="mdui-btn mdui-btn-icon mdui-ripple mdui-ripple-white" id="darktoggle_btn" mdui-tooltip="{content: '切换为暗色模式'}" onclick="darkToggle()"><i class="mdui-icon materiality-icons" id="darktoggle_icon">&#xe901;</i></span>
Expand Down Expand Up @@ -195,9 +195,7 @@
<i class="mdui-collapse-item-arrow mdui-icon materiality-icons">&#xe90d;</i>
</div>
<div class="mdui-collapse-item-body mdui-list">
<?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?>
<?php getLinks($this->options->links); ?>
<?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?>
<?php getLinks($this->options->links); ?>
</div>
</div>
<?php endif; ?>
Expand Down
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package materiality-typecho-theme
* @author EAimTY
* @version 4.4
* @version 4.5
* @link https://www.eaimty.com/
*/
?>
Expand All @@ -18,14 +18,14 @@
<div class="mdui-card-primary-subtitle mdui-text-color-theme-text">
<?php $this->date(); ?>
<?php if (in_array('author', $this->options->article)): ?>
<span> |</span><i class="mdui-icon materiality-icons">&#xe904;</i><a href="<?php $this->author->permalink(); ?>"><?php if (in_array('pangu', $this->options->feature)) echo "<nopangu>"; ?><?php $this->author(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</nopangu>"; ?></a>
<span> |</span><i class="mdui-icon materiality-icons">&#xe904;</i><a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a>
<?php endif; ?>
<?php if ($this->category && in_array('category', $this->options->article)): ?>
<span> | </span><i class="mdui-icon materiality-icons">&#xe907;</i><?php $this->category(', '); ?>
<?php endif; ?>
</div>
</div>
<div class="mdui-card-content mdui-typo"><?php $this->content(); ?></div>
<div class="mdui-card-content mdui-typo"><?php if (in_array('pangu', $this->options->feature)) echo "<pangu>"; ?><?php $this->content(); ?><?php if (in_array('pangu', $this->options->feature)) echo "</pangu>"; ?></div>
<div class="mdui-card-actions">
<a class="mdui-btn mdui-ripple mdui-text-color-theme-accent" href="<?php $this->permalink(); ?>">继续阅读</a>
</div>
Expand Down
2 changes: 2 additions & 0 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
<?php endif; ?>
</div>
<div class="mdui-card-content mdui-typo">
<?php if (in_array('pangu', $this->options->feature)) echo "<pangu>"; ?>
<?php if ($this->fields->index == "show"): ?>
<?php getIndex(); ?>
<?php endif; ?>
<?php $this->content(); ?>
<?php if (in_array('pangu', $this->options->feature)) echo "</pangu>"; ?>
</div>
</div>
<?php $this->need('comments.php'); ?>
Expand Down
2 changes: 2 additions & 0 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
</div>
<div class="mdui-card-content">
<div class="mdui-typo">
<?php if (in_array('pangu', $this->options->feature)) echo "<pangu>"; ?>
<?php if ($this->fields->index == "show"): ?>
<?php getIndex(); ?>
<?php endif; ?>
<?php $this->content(); ?>
<?php if (in_array('pangu', $this->options->feature)) echo "</pangu>"; ?>
</div>
<?php if ($this->fields->tags == "show" && $this->tags): ?>
<div class="mdui-divider"></div>
Expand Down

0 comments on commit 891edcb

Please sign in to comment.