${post.tags.slice(0, 3).map(tag => `
${tag}
@@ -251,6 +267,10 @@
const tags = await res.json();
const container = document.getElementById('tagList');
+ if (tags.length === 0) {
+ container.innerHTML = '
暂无标签';
+ return;
+ }
container.innerHTML = tags.slice(0, 10).map(tag => `
${tag.name} (${tag.count})
@@ -264,12 +284,16 @@
const topics = await res.json();
const container = document.getElementById('topicList');
+ if (topics.length === 0) {
+ container.innerHTML = '暂无主题';
+ return;
+ }
container.innerHTML = topics.slice(0, 5).map(topic => `
- ${topic.icon}
+ ${topic.icon || '🔧'}
${topic.name}
-
${topic.questions_count} 问题 · ${topic.followers} 关注
+
${topic.questions_count || 0} 问题 · ${topic.followers || 0} 关注
`).join('');
@@ -281,7 +305,7 @@
const query = e.target.value.trim();
if (!query) return;
- const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`);
+ const res = await fetch('/api/search?q=' + encodeURIComponent(query));
const data = await res.json();
const container = document.getElementById('searchResults');
@@ -289,34 +313,22 @@
if (data.posts.length === 0 && data.topics.length === 0) {
container.innerHTML = '
未找到相关内容
';
} else {
- container.innerHTML = `
- ${data.posts.length > 0 ? `
-
-
帖子 (${data.posts.length})
-
-
- ` : ''}
- ${data.topics.length > 0 ? `
-
-
工具分享 (${data.topics.length})
-
-
- ` : ''}
- `;
+ let html = '';
+ if (data.posts.length > 0) {
+ html += '
帖子 (' + data.posts.length + ')
';
+ }
+ if (data.topics.length > 0) {
+ html += '
工具分享 (' + data.topics.length + ')
';
+ }
+ container.innerHTML = html;
}
document.getElementById('searchModal').classList.remove('hidden');
@@ -330,15 +342,4 @@
}
-