Skip to content

Commit

Permalink
Merge pull request #87 from youranreus/dev3.0
Browse files Browse the repository at this point in the history
一系列bug修复
  • Loading branch information
youranreus authored Oct 25, 2022
2 parents da94700 + c92e7ef commit f921fc3
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
.idea/
.DS_Store
8 changes: 7 additions & 1 deletion archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
?>

<div class="PAP" id="archives">
<div id="page-banner" class="PAP-banner">
<div id="page-banner" class="PAP-banner <?php $img = G::getArticleFieldsBanner($this);
if ($img != 'none') echo 'PAP-IMG-Banner'; ?>">
<?php $img = G::getArticleFieldsBanner($this);
if ($img != 'none'): ?>
<div class="PAP-banner-background" style="background-image: url('<?php echo $img; ?>');"></div>
<div class="PAP-banner-mask"></div>
<?php endif; ?>
<div>
<h1 itemprop="name headline"><?php $this->title() ?></h1>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?php while ($this->next()): ?>
<div class="article-item" style="width: 100%;">
<h2 class="article-title"><a href="<?php $this->permalink(); ?>"><?php $this->title() ?></a></h2>
<p><?php $this->excerpt(50); ?></p>
<p><?php echo G::excerpt($this->excerpt, 50); ?></p>
<div class="article-data">
<span><?php $this->category(); ?></span>
<span><?php $this->date('Y-m-d'); ?></span>
Expand Down
5 changes: 2 additions & 3 deletions components/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
<?php endif; ?>
<link rel="preload" href="<?php echo G::staticUrl('static/js/spotlight.bundle.js'); ?>" as="script">
<link rel="stylesheet" href="<?php echo G::staticUrl('static/css/G.css'); ?>?v=<?php echo $devTag; ?>">
<link rel="stylesheet <?php if (!isset($_COOKIE['night']) || $_COOKIE['night'] != '1') {
echo 'alternate';
} ?>" href="<?php echo G::staticUrl("static/css/dark$minInfix.css?v=$devTag"); ?>" title="dark">
<link rel="stylesheet" href="<?php echo G::staticUrl("static/css/dark$minInfix.css?v=$devTag"); ?>" title="dark">

<style>
/* 设置自定义背景[颜色/图片] */
Expand All @@ -64,6 +62,7 @@
katex: <?php echo $this->options->enableKatex == 1 ? 'true' : 'false' ?>,
imgUrl: "<?php echo G::staticUrl('static/img/'); ?>",
autoTOC: <?php echo G::$config["enableDefaultTOC"] == 1 ? 'true' : 'false' ?>,
nightSpan: "<?php echo G::$config["autoNightSpan"]; ?>"
};

function custom_callback() {
Expand Down
3 changes: 3 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ function themeConfig($form)
$headerBackground = new Typecho_Widget_Helper_Form_Element_Text('headerBackground', null, null, _t('头部背景图'), _t('填写后会在站点头部添加一个半透明的背景图'));
$form->addInput($headerBackground);

$autoNightSpan = new Typecho_Widget_Helper_Form_Element_Text('autoNightSpan', null, '23-6', _t('自动夜间模式时间段'), _t('24小时制,当前晚上x点到第二天早上y点视为夜间,需要自动开启夜间模式,例: 23-6'));
$form->addInput($autoNightSpan);

$enableDefaultTOC = new Typecho_Widget_Helper_Form_Element_Radio('enableDefaultTOC', array(
'1' => _t('开启'),
'0' => _t('关闭')
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 G
* @author 季悠然
* @version 3.3.4
* @version 3.3.6
* @link https://季悠然.space
*/

Expand Down
20 changes: 18 additions & 2 deletions libs/G.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class G
*
* @var string
*/
public static $version = "3.3.4";
public static $version = "3.3.6";

/**
* 主题配置
Expand All @@ -34,7 +34,8 @@ class G
'advanceSetting' => '',
'footerLOGO' => '',
'enableUPYUNLOGO' => '',
'enableDefaultTOC' => ''
'enableDefaultTOC' => '',
'autoNightSpan' => ''
];

public static $advanceConfig = [];
Expand Down Expand Up @@ -318,6 +319,21 @@ public static function analyzeMeme($content)
return $result;
}

/**
* 输出文章概要
*
* @param string $content
* @param Integer $limit
* @return string
*/
public static function excerpt($content, $limit)
{
$result = mb_substr($content, 0, $limit);
$result = self::analyzeMeme($result);
$result = preg_replace('/\[[^\]]*\]/', '', $result);
return $result;
}

/**
* 获取表情包url
*
Expand Down
41 changes: 6 additions & 35 deletions static/js/G.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,47 +179,18 @@ let makeGallery = () => {
* 夜间模式开关
*/
let darkModeToggle = () => {
let night =
document.cookie.replace(/(?:^|.*;\s*)night\s*\=\s*([^;]*).*$|^.*$/, "$1") ||
"0";
if (night === "0") {
document.querySelector('link[title="dark"]').disabled = true;
document.querySelector('link[title="dark"]').disabled = false;
document.cookie = "night=1;path=/";
} else {
document.querySelector('link[title="dark"]').disabled = true;
document.cookie = "night=0;path=/";
}
document.querySelector('link[title="dark"]').disabled = !document.querySelector('link[title="dark"]').disabled;
};

/**
* 自动夜间模式判断
*/
let autoDarkMode = () => {
if (
document.cookie.replace(/(?:^|.*;\s*)night\s*=\s*([^;]*).*$|^.*$/, "$1") ===
""
) {
if (new Date().getHours() > 22 || new Date().getHours() < 6) {
document.querySelector('link[title="dark"]').disabled = true;
document.querySelector('link[title="dark"]').disabled = false;
document.cookie = "night=1;path=/";
} else {
document.cookie = "night=0;path=/";
}
} else {
let night =
document.cookie.replace(
/(?:^|.*;\s*)night\s*\=\s*([^;]*).*$|^.*$/,
"$1"
) || "0";
if (night === "0") {
document.querySelector('link[title="dark"]').disabled = true;
} else if (night === "1") {
document.querySelector('link[title="dark"]').disabled = true;
document.querySelector('link[title="dark"]').disabled = false;
}
}
const [start, end] = window.G_CONFIG.nightSpan.split('-');
if (new Date().getHours() >= parseInt(start) || new Date().getHours() < parseInt(end))
document.querySelector('link[title="dark"]').disabled = false;
else
document.querySelector('link[title="dark"]').disabled = true;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion static/js/G.min.js

Large diffs are not rendered by default.

0 comments on commit f921fc3

Please sign in to comment.