feat: 在管理后台概览页新增文章总字数统计信息
This commit is contained in:
1 parent
f6dba60603
commit
e5aea6b3ef
2 files changed
+40
-10
No files matched your search
@@ -4,18 +4,20 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
const db = platform?.env?.DB;
|
||||
|
||||
let postCount = 0;
|
||||
let totalWords = 0;
|
||||
let tagCount = 0;
|
||||
let categoryCount = 0;
|
||||
let pageCount = 0;
|
||||
|
||||
if (db) {
|
||||
try {
|
||||
const postResult = await db.prepare('SELECT COUNT(*) as count FROM posts').first();
|
||||
const postResult = await db.prepare('SELECT COUNT(*) as count, SUM(LENGTH(content)) as totalWords FROM posts').first();
|
||||
const tagResult = await db.prepare('SELECT COUNT(*) as count FROM tags').first();
|
||||
const categoryResult = await db.prepare('SELECT COUNT(*) as count FROM categories').first();
|
||||
const pageResult = await db.prepare('SELECT COUNT(*) as count FROM pages').first();
|
||||
|
||||
postCount = (postResult?.count as number) || 0;
|
||||
totalWords = (postResult?.totalWords as number) || 0;
|
||||
tagCount = (tagResult?.count as number) || 0;
|
||||
categoryCount = (categoryResult?.count as number) || 0;
|
||||
pageCount = (pageResult?.count as number) || 0;
|
||||
@@ -26,6 +28,7 @@ export const load: PageServerLoad = async ({ platform }) => {
|
||||
|
||||
return {
|
||||
postCount,
|
||||
totalWords,
|
||||
tagCount,
|
||||
categoryCount,
|
||||
pageCount
|
||||
|
||||
@@ -10,32 +10,50 @@
|
||||
|
||||
<div class="stats-grid">
|
||||
<div class="stat-card">
|
||||
<h3>{$page.data.aliases?.post || '文章'}总数</h3>
|
||||
<div class="number">{data.postCount}</div>
|
||||
<div class="stat-body">
|
||||
<h3>{$page.data.aliases?.post || '文章'}总数</h3>
|
||||
<div class="number">{data.postCount}</div>
|
||||
</div>
|
||||
<a href="/admin/posts" class="action-link">
|
||||
管理{$page.data.aliases?.post || '文章'} <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="17" x2="17" y2="7"></line><polyline points="7 7 17 7 17 17"></polyline></svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<h3>{$page.data.aliases?.page || '页面'}总数</h3>
|
||||
<div class="number">{data.pageCount}</div>
|
||||
<div class="stat-body">
|
||||
<h3>{$page.data.aliases?.post || '文章'}总字数</h3>
|
||||
<div class="number">{(data.totalWords || 0).toLocaleString()}</div>
|
||||
</div>
|
||||
<a href="/admin/posts/new" class="action-link">
|
||||
撰写新{$page.data.aliases?.post || '文章'} <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="17" x2="17" y2="7"></line><polyline points="7 7 17 7 17 17"></polyline></svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<div class="stat-body">
|
||||
<h3>{$page.data.aliases?.page || '页面'}总数</h3>
|
||||
<div class="number">{data.pageCount}</div>
|
||||
</div>
|
||||
<a href="/admin/pages" class="action-link">
|
||||
管理{$page.data.aliases?.page || '页面'} <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="17" x2="17" y2="7"></line><polyline points="7 7 17 7 17 17"></polyline></svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<h3>{$page.data.aliases?.category || '分类'}总数</h3>
|
||||
<div class="number">{data.categoryCount}</div>
|
||||
<div class="stat-body">
|
||||
<h3>{$page.data.aliases?.category || '分类'}总数</h3>
|
||||
<div class="number">{data.categoryCount}</div>
|
||||
</div>
|
||||
<a href="/admin/categories" class="action-link">
|
||||
管理{$page.data.aliases?.category || '分类'} <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="17" x2="17" y2="7"></line><polyline points="7 7 17 7 17 17"></polyline></svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="stat-card">
|
||||
<h3>{$page.data.aliases?.tag || '标签'}总数</h3>
|
||||
<div class="number">{data.tagCount}</div>
|
||||
<div class="stat-body">
|
||||
<h3>{$page.data.aliases?.tag || '标签'}总数</h3>
|
||||
<div class="number">{data.tagCount}</div>
|
||||
</div>
|
||||
<a href="/admin/tags" class="action-link">
|
||||
管理{$page.data.aliases?.tag || '标签'} <svg class="arrow-icon" xmlns="http://www.w3.org/2000/svg" width="1.3em" height="1.3em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="7" y1="17" x2="17" y2="7"></line><polyline points="7 7 17 7 17 17"></polyline></svg>
|
||||
</a>
|
||||
@@ -70,12 +88,21 @@
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
transition: border-color 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
border-color: var(--accent-color, #419b38);
|
||||
}
|
||||
|
||||
.stat-body {
|
||||
width: 100%;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.stat-card h3 {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 1.1rem;
|
||||
@@ -87,7 +114,7 @@
|
||||
font-size: 3.2rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-color, rgba(0,0,0,0.86));
|
||||
margin-bottom: 18px;
|
||||
margin-bottom: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user