据于Typecho默认模板(default)修改,转载记录于此,备忘。
资料来源:
1、拾月-我的博客主题
2、SycBlog-CSS适配系统级黑夜模式
1、修改字体
使用了鹜霞文楷
字体。
首先,在主题 header.php
中添加引用字体的 css 文件
<link rel="stylesheet" href="https://cdn.staticfile.org/lxgw-wenkai-screen-webfont/1.6.0/lxgwwenkaiscreen.css">
然后,修改style.css
文件,在body
和h1,h2,h3,h4,h5,h6
中的 font-family,如下:
body {
background-color: #FFF;
color: #444;
font-family: "LXGW WenKai Screen","Droid Serif",Georgia,"Times New Roman","PingFang SC","Hiragino Sans GB","Source Han Sans CN","WenQuanYi Micro Hei","Microsoft Yahei",serif;
font-size: 100%;
}
h1,h2,h3,h4,h5,h6 {
font-family: "LXGW WenKai Screen","Droid Serif",Georgia,"Times New Roman","PingFang SC","Hiragino Sans GB","Source Han Sans CN","WenQuanYi Micro Hei","Microsoft Yahei",serif;
}
2、CSS适配系统级黑夜模式
在style.css
内合适位置添加以下代码,适配黑夜模式:
@media (prefers-color-scheme: dark) {
html {
filter: invert(90%) hue-rotate(180deg);
}
img, video, svg {
filter: invert(110%) hue-rotate(180deg);
opacity: .8;
}
}
3、修改页脚,增加网站运行天数及日志和评论统计
打开footer.php
,在合适位置添加以下代码,显示页脚「本站已运行 xx 天,共 xx 篇文章和 xx 条评论。」,并增加了运行天数及日志和评论统计:
本站已运行
<?php
$unixTime_1 = "1422748800";
$unixTime_2 = time();
$timediff = abs($unixTime_2 - $unixTime_1);
$days = intval($timediff / 86400);
echo $days." 天. ";?>
<?php $stat = Typecho_Widget::widget('Widget_Stat');?>共 <?php echo $stat->PublishedPostsNum;?> 篇文章和 <?php echo $stat->publishedCommentsNum;?> 条评论.
注意:代码中$unixTime_1 = "1422748800";
的1422748800
数字为时间戳,根据自己的需要自行转换,可以点击此处进行在线转换。
4、增加图片注释
修改 Typecho
的 Markdown 解析器,首先需要修改 var/HyperDown.php
,对图片修改为
<figure><img class=\"skyimg\" src=\"https://static.skyue.com{$url}\" alt=\"{$escaped}\" title=\"{$escaped}\"><figcaption class=\"image-caption\">{$escaped}</figcaption></figure>
相应 style.css
增加
figure {
border-style: solid;
border-width: 1px;
border-color: #e7e7e7;
padding: 2px;
}
.image-caption {
color: #999999;
text-align: center;
}
以上修改实现的功能:
- src 增加 https://static.skyue.com 前缀,本地写作时,不用补全前缀即可发布。
- 图片和图片标题包在 figure 中,并添加灰色边框,避免白底图与背景色重合,分不清边界。
- 图片标签放在 figcaption 中,使用灰色字体。
5、统计信息调用代码
以下代码实现的功能是在网站前端界面,调用整站的文章总数、分类总数、评论总数以及页面总数量显示在指定位置,通常是放在侧边栏。
<?php if ($this->options->sidebarBlock && in_array('showSiteStatistics', $this->options->sidebarBlock)): ?>
<section class="widget">
<h3><?php _e('数据统计'); ?></h3>
<ul>
<?php Typecho_Widget::widget('Widget_Stat')->to($stat); ?>
<li><?php _e('文章数量:'); ?><?php $stat->publishedPostsNum() ?></li>
<li><?php _e('分类数量:'); ?><?php $stat->categoriesNum() ?></li>
<li><?php _e('评论数量:'); ?><?php $stat->publishedCommentsNum() ?></li>
<li><?php _e('页面数量:'); ?><?php echo $stat->publishedPagesNum + $stat->publishedPostsNum; ?></li>
</section>
修改完毕。