博客文章优化

This commit is contained in:
DelLevin-Home
2026-05-18 00:54:08 +08:00
parent fa4c784b96
commit 5e33d53ea3
5 changed files with 54 additions and 34 deletions

View File

@@ -55,7 +55,7 @@
<path d="M21 15C21 15.5304 20.7893 16.0391 20.4142 16.4142C20.0391 16.7893 19.5304 17 19 17H7L3 21V7C3 6.46957 3.21071 5.96086 3.58579 5.58579C3.96086 5.21071 4.46957 5 5 5H19C19.5304 5 20.0391 5.21071 20.4142 5.58579C20.7893 5.96086 21 6.46957 21 7V15Z" <path d="M21 15C21 15.5304 20.7893 16.0391 20.4142 16.4142C20.0391 16.7893 19.5304 17 19 17H7L3 21V7C3 6.46957 3.21071 5.96086 3.58579 5.58579C3.96086 5.21071 4.46957 5 5 5H19C19.5304 5 20.0391 5.21071 20.4142 5.58579C20.7893 5.96086 21 6.46957 21 7V15Z"
stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg> </svg>
<span class="btn-label">留言板</span> <span class="btn-label" data-i18n="btn_guestbook">留言板</span>
</button> </button>
<!-- Hover 浮动预览面板 --> <!-- Hover 浮动预览面板 -->
@@ -80,13 +80,13 @@
<path d="M16 17H8" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> <path d="M16 17H8" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M10 9H8" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/> <path d="M10 9H8" stroke="#666" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg> </svg>
<span class="btn-label">博客文章</span> <span class="btn-label" data-i18n="btn_blog_posts">博客文章</span>
</button> </button>
<!-- Hover 浮动预览面板 --> <!-- Hover 浮动预览面板 -->
<div id="blog-posts-preview" class="blog-posts-preview"> <div id="blog-posts-preview" class="blog-posts-preview">
<div class="preview-header"> <div class="preview-header">
<h3>最新文章</h3> <h3 data-i18n="blog_latest_posts">最新文章</h3>
</div> </div>
<div class="preview-body blog-posts-list"> <div class="preview-body blog-posts-list">
<!-- 最新文章预览将在这里动态加载 --> <!-- 最新文章预览将在这里动态加载 -->

View File

@@ -9,7 +9,7 @@
/* 博客文章按钮容器 */ /* 博客文章按钮容器 */
.blog-posts-btn-container { .blog-posts-btn-container {
position: fixed; position: fixed;
top: 95px; top: 115px;
right: 80px; right: 80px;
z-index: 999; z-index: 999;
} }
@@ -19,14 +19,14 @@
background: #fff; background: #fff;
border: 1px solid #e8e8e8; border: 1px solid #e8e8e8;
border-radius: 50%; border-radius: 50%;
width: 60px; width: 80px;
height: 60px; height: 80px;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 3px; gap: 4px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
} }
@@ -35,20 +35,20 @@
background: #fff; background: #fff;
border: 1px solid #e8e8e8; border: 1px solid #e8e8e8;
border-radius: 50%; border-radius: 50%;
width: 60px; width: 80px;
height: 60px; height: 80px;
cursor: pointer; cursor: pointer;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 3px; gap: 4px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
} }
.btn-label { .btn-label {
font-size: 12px; font-size: 13px;
color: #666; color: #666;
line-height: 1; line-height: 1;
} }
@@ -62,8 +62,8 @@
.guestbook-btn svg, .guestbook-btn svg,
.blog-posts-btn svg { .blog-posts-btn svg {
width: 28px; width: 32px;
height: 28px; height: 32px;
} }
.guestbook-btn svg path, .guestbook-btn svg path,

View File

@@ -142,35 +142,47 @@
// 追加文章 // 追加文章
function appendPosts(posts) { function appendPosts(posts) {
const container = document.querySelector('.blog-posts-container'); const containers = document.querySelectorAll('.blog-posts-container');
const loadMoreBtn = document.querySelector('.load-more-btn'); const loadMoreBtns = document.querySelectorAll('.load-more-btn');
const oldTip = document.querySelector('.load-complete'); const oldTips = document.querySelectorAll('.load-complete');
if (!container) return; if (containers.length === 0) {
console.error('未找到 .blog-posts-container 容器');
return;
}
posts.forEach(post => { // 向所有容器追加新文章
const div = document.createElement('div'); containers.forEach(container => {
div.innerHTML = renderPostItem(post); posts.forEach(post => {
container.appendChild(div.firstElementChild); const div = document.createElement('div');
div.innerHTML = renderPostItem(post);
container.appendChild(div.firstElementChild);
});
}); });
// 移除旧的加载更多按钮和提示 // 移除所有旧的加载更多按钮和提示
if (loadMoreBtn) loadMoreBtn.remove(); loadMoreBtns.forEach(btn => btn.remove());
if (oldTip) oldTip.remove(); oldTips.forEach(tip => tip.remove());
// 添加新的加载更多按钮或提示 // 向所有容器后添加新的加载更多按钮或提示
if (hasMore) { if (hasMore) {
const btn = document.createElement('button'); containers.forEach(container => {
btn.className = 'load-more-btn'; const btn = document.createElement('button');
btn.textContent = '点击加载更多'; btn.className = 'load-more-btn';
btn.onclick = window.loadMoreBlogPosts; btn.textContent = '点击加载更多';
container.after(btn); btn.onclick = window.loadMoreBlogPosts;
container.after(btn);
});
} else { } else {
const tip = document.createElement('div'); containers.forEach(container => {
tip.className = 'load-complete'; const tip = document.createElement('div');
tip.textContent = '已显示全部'; tip.className = 'load-complete';
container.after(tip); tip.textContent = '已显示全部';
container.after(tip);
});
} }
console.log(`成功追加 ${posts.length} 篇文章到 ${containers.length} 个容器,当前页码: ${currentPage}`);
} }
// 渲染单个文章项 // 渲染单个文章项

View File

@@ -70,4 +70,8 @@ const translationsEN = {
guestbook_submit_success: "Message submitted successfully!", guestbook_submit_success: "Message submitted successfully!",
guestbook_submit_error: "Failed to submit message, please try again", guestbook_submit_error: "Failed to submit message, please try again",
guestbook_required_nickname: "Please enter a nickname", guestbook_required_nickname: "Please enter a nickname",
// Top-right buttons
btn_guestbook: "Guestbook",
btn_blog_posts: "Blog Posts",
blog_latest_posts: "Latest Posts",
}; };

View File

@@ -70,4 +70,8 @@ const translationsZH = {
guestbook_submit_success: "留言提交成功!", guestbook_submit_success: "留言提交成功!",
guestbook_submit_error: "留言提交失败,请重试", guestbook_submit_error: "留言提交失败,请重试",
guestbook_required_nickname: "请输入昵称", guestbook_required_nickname: "请输入昵称",
// 右上角按钮
btn_guestbook: "留言板",
btn_blog_posts: "博客文章",
blog_latest_posts: "最新文章",
}; };