Skip to content

Commit

Permalink
兼容typecho 1.2.0和问题修复
Browse files Browse the repository at this point in the history
修复扇贝API ,顺便改用te自带函数获取每日数据
兼容1.2.0
其他资源更新、文章页微调
  • Loading branch information
Seevil committed Apr 6, 2022
1 parent dee3445 commit 633e1a8
Show file tree
Hide file tree
Showing 8 changed files with 1,243 additions and 106 deletions.
2 changes: 1 addition & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ article header .meta *{color:#ccc;font-size:.85rem}
article header .author{text-transform:uppercase;letter-spacing:.01em;font-weight:700}
article header .postdate{display:inline}
article .content h2:before{content:"#";color:#2bbc8a;position:absolute;left:-1rem;top:-4px;font-size:1.2rem;font-weight:700}
article .content img,article .content video{max-width:100%;height:auto;display:block;margin:auto}
article .content img,article .content video{max-width:100%;height:auto;display:block;margin:auto;border-radius: 4px;}
article .content .video-container{position:relative;padding-top:56.25%;height:0;overflow:hidden}
.highlight,.hljs,pre{overflow-x:auto}
article .content .video-container embed,article .content .video-container iframe,article .content .video-container object{position:absolute;top:0;left:0;width:100%;height:100%;margin-top:0}
Expand Down
38 changes: 17 additions & 21 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="mx-auto px3 my5">
<footer id="footer" style="display:block;">
<div class="footer-left">
Copyright © <?php echo date('Y'); ?> By <a href="http://www.typecho.org" target="_blank" rel="nofollow">Typecho</a> & <a href="http://www.xde.io" target="_blank">Xingr</a> <?php if($this->options->beian): ?><a href="https://beian.miit.gov.cn/"><?php $this->options->beian();?></a><?php endif; ?>
Copyright © <?php echo date('Y'); ?> By <a href="http://www.typecho.org" target="_blank" rel="nofollow">Typecho</a> & <a href="https://www.krsay.com" target="_blank">Xingr</a> <?php if($this->options->beian): ?><a href="https://beian.miit.gov.cn/"><?php $this->options->beian();?></a><?php endif; ?>
</div>
<div class="footer-right">
<nav>
Expand All @@ -26,28 +26,24 @@
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script>
$(function () {
if (location.pathname !== "/") return;
$.get("<?php $this->options->siteUrl();?><?php echo date('Ymd').'.json';?>", function (data) {
var data = data.data;
// var str = data.content+'\n'
// + data.translation+"\n---- "
// +data.author +'\n'
var str = data.content+'\n'
+ data.translation+"\n---- "

var str = (data.content || "") + "\n" + (data.translation || "");

var options = {
strings: [
str + "Who??^1000",
str + "It's me^2000",
str +'Haha, make a joke',
str +data.author,
strings: [
str + "\nWelcome to my blog. ^1000",
str + "\nHave a good day. ^1000",
str + `\n---- ${data.author}. ^1000`,
],
typeSpeed: 20,
startDelay:300,
startDelay: 300,
// loop: true,
}
};
var typed = new Typed(".description .typed", options);
})
});</script>
});
});
</script>
<?php endif; ?>
<?php if ($this->is('post') || $this->is('page')) : ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('css/lightbox.min.css'); ?>">
Expand All @@ -58,9 +54,7 @@
return '<a href="' + this.src + '" title="' + this.alt + '" data-lightbox="roadtrip"></a>';
});
</script>
<script>
hljs.initHighlightingOnLoad();
</script>
<script>hljs.highlightAll();</script>
<?php endif; ?>
<link rel="stylesheet" href="<?php $this->options->themeUrl('css/search.css'); ?>">
<div class="searchbox">
Expand All @@ -76,9 +70,10 @@
<script>
document.addEventListener('DOMContentLoaded',function(){(function($){$('#search').click(function(){$('.searchbox').toggleClass('show')});$('.searchbox .searchbox-mask').click(function(){$('.searchbox').removeClass('show')});$('.searchbox-close').click(function(){$('.searchbox').removeClass('show')})})(jQuery)});
</script>
<script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
const code = document.querySelector('#code');
navigator.serviceWorker.register('<?php $this->options->themeUrl('/sw.js'); ?>').then(function(registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
Expand All @@ -87,6 +82,7 @@
});
}
</script>

<?php $this->footer(); ?>
</body>
</html>
13 changes: 5 additions & 8 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function themeConfig($form) {
$form->addInput($beian->addRule('xssCheck', _t('请不要在图片链接中使用特殊字符')));
$sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL,NULL, _t('文章置顶'), _t('置顶的文章cid,按照排序输入, 请以半角逗号或空格分隔'));
$form->addInput($sticky);
$Projects = new Typecho_Widget_Helper_Form_Element_Textarea('Projects', NULL, NULL, _t('首页 Projects 作品链接 设置(注意:切换主题会被清空,注意备份!)'), _t('按照格式输入链接信息,格式:<br><strong>链接名称(必须)|链接地址(必须)|链接描述</strong><br>不同信息之间用英文竖线“|”分隔,例如:<br><strong>XDE|http://www.xde.io/|仙岛驿站</strong><br>若中间有暂时不想填的信息,请留空,例如暂时不想填写链接描述:<br><strong>XDE|http://www.xde.io||</strong><br>多个链接换行即可,一行一个'));
$Projects = new Typecho_Widget_Helper_Form_Element_Textarea('Projects', NULL, NULL, _t('首页 Projects 作品链接 设置(注意:切换主题会被清空,注意备份!)'), _t('按照格式输入链接信息,格式:<br><strong>链接名称(必须)|链接地址(必须)|链接描述</strong><br>不同信息之间用英文竖线“|”分隔,例如:<br><strong>XDE|https://www.krsay.com/|可说欢喜</strong><br>若中间有暂时不想填的信息,请留空,例如暂时不想填写链接描述:<br><strong>XDE|https://www.krsay.com||</strong><br>多个链接换行即可,一行一个'));
$form->addInput($Projects);

$catalog = new Typecho_Widget_Helper_Form_Element_Radio('catalog',
Expand Down Expand Up @@ -521,13 +521,10 @@ function today(){
}
$coverstory = date('Ymd').'.json'; //每日故事 json格式
if (!file_exists($coverstory)) {
$stream_opts = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]];
$json = file_get_contents("compress.zlib://".'https://rest.shanbay.com/api/v2/quote/quotes/today/',false, stream_context_create($stream_opts));
@file_put_contents($coverstory,$json); //写入文本
$http = Typecho_Http_Client::get();
$http->Send('https://apiv3.shanbay.com/weapps/dailyquote/quote/');
$shanbaytoday = $http->getResponseBody();
file_put_contents($coverstory,$shanbaytoday); //写入文本
}
$coverstory = json_decode(file_get_contents($coverstory),true);
return $coverstory;
Expand Down
27 changes: 15 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* 仙人掌(Cactus)是优雅简洁的暗色主题
* @package Cactus Theme
* @author Intern
* @version 1.3.2
* @link https://www.xde.io/
* @version 1.3.3
* @link https://www.krsay.com
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$this->need('header.php');
Expand All @@ -16,6 +16,7 @@
$pageSize = $this->options->pageSize;
$select1 = $this->select()->where('type = ?', 'post');
$select2 = $this->select()->where('type = ? && status = ? && created < ?', 'post','publish',time());
//清空原有文章的列队
$this->row = [];
$this->stack = [];
$this->length = 0;
Expand All @@ -24,18 +25,20 @@
if($i == 0) $select1->where('cid = ?', $cid);
else $select1->orWhere('cid = ?', $cid);
$order .= " when $cid then $i";
$select2->where('table.contents.cid != ?', $cid);
$select2->where('table.contents.cid != ?', $cid); //避免重复
}
if ($order) $select1->order(null,"(case cid$order end)");
if ($this->_currentPage == 1) foreach($db->fetchAll($select1) as $sticky_post){
if ($order) $select1->order('', "(case cid$order end)"); //置顶文章的顺序 按 $sticky 中 文章ID顺序
if (($this->_currentPage || $this->currentPage) == 1) foreach($db->fetchAll($select1) as $sticky_post){ //首页第一页才显示
$sticky_post['sticky'] = $sticky_html;
$this->push($sticky_post);
$this->push($sticky_post); //压入列队
}
if($this->user->hasLogin()){
$uid = $this->user->uid; //登录时,显示用户各自的私密文章
if($uid) $select2->orWhere('authorId = ? && status = ?', $uid, 'private');
}
$uid = $this->user->uid;
if($uid) $select2->orWhere('authorId = ? && status = ?',$uid,'private');
$sticky_posts = $db->fetchAll($select2->order('table.contents.created', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize));
foreach($sticky_posts as $sticky_post) $this->push($sticky_post);
$this->setTotal($this->getTotal()-count($sticky_cids));
foreach($sticky_posts as $sticky_post) $this->push($sticky_post); //压入列队
$this->setTotal($this->getTotal()-count($sticky_cids)); //置顶文章不计算在所有文章内
}
?>
<body>
Expand Down Expand Up @@ -106,12 +109,12 @@
</section>
<section id="projects">
<span class="h1">
<a href="<?php if($this->options->Projectsurl): ?><?php $this->options->Projectsurl();?><?php else : ?>#<?php endif; ?>" rel="external nofollow noopener noreferrer" target="_blank">Projects</a>
<a href="<?php if($this->options->Projects): ?><?php $this->options->Projects();?><?php else : ?>#<?php endif; ?>" rel="external nofollow noopener noreferrer" target="_blank">Projects</a>
</span>
<ul class="project-list">
<?php Projects(); ?>
</ul>
</section>
</section>
</div>
<?php $this->need('footer.php'); ?>
<?php $this->need('footer.php'); ?>
33 changes: 20 additions & 13 deletions js/lazyload.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
/*!
* Lazy Load - JavaScript plugin for lazy loading images
*
* Copyright (c) 2007-2017 Mika Tuupola
* Copyright (c) 2007-2019 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Project home:
* https://appelsiini.net/projects/lazyload
*
* Version: 2.0.0-beta.2
* Version: 2.0.0-rc.2
*
*/

(function (root, factory) {
if (typeof exports === "object") {
module.exports = factory(root);
} else if (typeof define === "function" && define.amd) {
define([], factory(root));
define([], factory);
} else {
root.LazyLoad = factory(root);
}
}) (typeof global !== "undefined" ? global : this.window || this.global, function (root) {

"use strict";

if (typeof define === "function" && define.amd){
root = window;
}

const defaults = {
src: "data-src",
srcset: "data-srcset",
selector: ".lazyload"
selector: ".lazyload",
root: null,
rootMargin: "0px",
threshold: 0
};

/**
Expand Down Expand Up @@ -92,14 +99,14 @@

let self = this;
let observerConfig = {
root: null,
rootMargin: "0px",
threshold: [0]
root: this.settings.root,
rootMargin: this.settings.rootMargin,
threshold: [this.settings.threshold]
};

this.observer = new IntersectionObserver(function(entries) {
entries.forEach(function (entry) {
if (entry.intersectionRatio > 0) {
Array.prototype.forEach.call(entries, function (entry) {
if (entry.isIntersecting) {
self.observer.unobserve(entry.target);
let src = entry.target.getAttribute(self.settings.src);
let srcset = entry.target.getAttribute(self.settings.srcset);
Expand All @@ -117,7 +124,7 @@
});
}, observerConfig);

this.images.forEach(function (image) {
Array.prototype.forEach.call(this.images, function (image) {
self.observer.observe(image);
});
},
Expand All @@ -132,7 +139,7 @@
if (!this.settings) { return; }

let self = this;
this.images.forEach(function (image) {
Array.prototype.forEach.call(this.images, function (image) {
let src = image.getAttribute(self.settings.src);
let srcset = image.getAttribute(self.settings.srcset);
if ("img" === image.tagName.toLowerCase()) {
Expand All @@ -143,7 +150,7 @@
image.srcset = srcset;
}
} else {
image.style.backgroundImage = "url(" + src + ")";
image.style.backgroundImage = "url('" + src + "')";
}
});
},
Expand All @@ -170,4 +177,4 @@
}

return LazyLoad;
});
});
1,215 changes: 1,172 additions & 43 deletions lib/highlight.min.js

Large diffs are not rendered by default.

Loading

1 comment on commit 633e1a8

@Seevil
Copy link
Owner Author

@Seevil Seevil commented on 633e1a8 Apr 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.