summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBigCoke233 <hi@guhub.cn>2020-07-11 09:32:16 +0800
committerBigCoke233 <hi@guhub.cn>2020-07-11 09:32:16 +0800
commit4817b6ffa38af8b269e4ad91591d70c032dd8e5d (patch)
tree028633c00df80fb806335bf6745150818afca5be
parentfdb60d77b1b68c9326b08a8ece770af3ac168877 (diff)
:zap: Perf: 优化归档页面 meta 元信息 #64
-rw-r--r--includes/header.php32
-rw-r--r--libs/Utils.php13
-rw-r--r--pagefile.php7
3 files changed, 37 insertions, 15 deletions
diff --git a/includes/header.php b/includes/header.php
index 56c0db1..1a228c2 100644
--- a/includes/header.php
+++ b/includes/header.php
@@ -140,18 +140,28 @@
<?php elseif($this->is('post') || $this->is('page')): ?>
<h1><?php $this->title(); ?></h1>
<div class="header-meta">
- <?php if($this->fields->meta==''): ?>
- <div class="header-meta-line-one">
- <?php if($this->is('post')): ?><i class="iconfont icon-block" title="文章分类"></i> <?php $this->category(','); ?>&emsp;<?php endif; ?>
- <i class="iconfont icon-comments" title="共 <?php $this->commentsNum('0', '1', '%d'); ?> 条评论"></i> <?php $this->commentsNum('0', '1', '%d'); ?>&emsp;
- </div>
- <div class="header-meta-line-two">
- <i class="iconfont icon-clock" title="该文章发布于 <?php $this->date(); ?>"></i> <?php $this->date(); ?>&emsp;
- <i class="icon-view iconfont" title="该文章被浏览 <?php Contents::postViews($this) ?> 次"></i> <?php Contents::postViews($this) ?>
- </div>
- <?php else: ?>
+ <?php if($this->fields->meta==''):
+ if($_SESSION["isPageArchive"]!=true){ ?>
+ <div class="header-meta-line-one">
+ <?php if($this->is('post')): ?><i class="iconfont icon-block" title="文章分类"></i> <?php $this->category(','); ?>&emsp;<?php endif; ?>
+ <i class="iconfont icon-comments" title="共 <?php $this->commentsNum('0', '1', '%d'); ?> 条评论"></i> <?php $this->commentsNum('0', '1', '%d'); ?>&emsp;
+ </div>
+ <div class="header-meta-line-two">
+ <i class="iconfont icon-clock" title="该文章发布于 <?php $this->date(); ?>"></i> <?php $this->date(); ?>&emsp;
+ <i class="icon-view iconfont" title="该文章被浏览 <?php Contents::postViews($this) ?> 次"></i> <?php Contents::postViews($this) ?>
+ </div>
+ <?php }else{ ?>
+ <div class="header-meta-line-one">
+ <i class="iconfont icon-clock" title="一切开始于 <?php Utils::getOldestPostDate(); ?>"></i> <?php Utils::getOldestPostDate(); ?>&emsp;
+ </div>
+ <div class="header-meta-line-two">
+ <i class="icon-view iconfont" title="该页面被浏览 <?php Contents::postViews($this) ?> 次"></i> <?php Contents::postViews($this) ?>
+ </div>
+ <?php }
+ else: ?>
<?php $this->fields->meta(); ?><div style="display:none"><?php Contents::postViews($this) ?></div>
- <?php endif; ?>
+ <?php endif;
+ $_SESSION["isPageArchive"]=false; //清除归档页面标识,避免不必要的问题?>
</div>
<?php elseif($this->is('archive')): ?>
<h1><?php $this->archiveTitle(array(
diff --git a/libs/Utils.php b/libs/Utils.php
index f9785bc..34ac4fe 100644
--- a/libs/Utils.php
+++ b/libs/Utils.php
@@ -140,4 +140,17 @@ class Utils
}
}
}
+
+ /**
+ * 获取最早文章创建时间
+ */
+ public static function getOldestPostDate() {
+ $db = Typecho_Db::get();
+ $content = $db->fetchRow($db->select()->from('table.contents')
+ ->where('table.contents.status = ?', 'publish')
+ ->where('table.contents.password IS NULL')
+ ->order('table.contents.created', Typecho_Db::SORT_ASC)
+ ->limit(1));
+ echo '一切开始于 '.date('Y-m-d', $content['created']);
+ }
} \ No newline at end of file
diff --git a/pagefile.php b/pagefile.php
index 4c03844..a24d2bb 100644
--- a/pagefile.php
+++ b/pagefile.php
@@ -6,6 +6,7 @@
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$this->need('includes/head.php');
+$_SESSION["isPageArchive"] = true; //归档页面标识
$this->need('includes/header.php');
?>
<main class="main-container container" role="main">
@@ -22,8 +23,7 @@ $this->need('includes/header.php');
<?php endif; ?>
<br />
<h2>文章归档</h2>
- <ul class="archives-list">
- <?php
+ <ul class="archives-list"><?php
$archives = Contents::archives($this);
$number = 0;
foreach($archives as $year => $posts) {
@@ -38,8 +38,7 @@ $this->need('includes/header.php');
}
echo '</details>';
$number++;
- }
- ?>
+ }?>
</ul>
</div>
</div>