Spaces:
Running
Running
Claude commited on
コメント時刻表示とコメント件数の記事一覧への追加
Browse files- blog_detail.html: コメントの日付表示を日付のみ([:10])から日時(JST, YYYY-MM-DD HH:MM)に変更
- main.py: _to_jst_str を Jinja2 フィルタ "to_jst" として登録
- main.py: get_all_comment_counts() を追加(コメントAPI を fields=articleId で1回叩き、articleIdごとに集計)
- blog_list.html: 各記事カードに "💬 N件" のコメント件数を表示
https://claude.ai/code/session_018sq37X4VGvDxwtnyyvQmFv
- main.py +19 -0
- templates/blog_detail.html +1 -1
- templates/blog_list.html +1 -1
main.py
CHANGED
|
@@ -193,6 +193,23 @@ def _to_jst_str(iso: str) -> str:
|
|
| 193 |
except Exception:
|
| 194 |
return iso[:16].replace("T", " ")
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
def get_backups(original_id: str) -> list:
|
| 197 |
try:
|
| 198 |
r = http_requests.get(cms_url("blog-backup"), headers=CMS_HEADERS_GET(), params={
|
|
@@ -311,6 +328,7 @@ async def index(request: Request, id: str = None, page: int = 0,
|
|
| 311 |
total_pages = max(1, -(-total // ARTICLES_PER_PAGE))
|
| 312 |
page = max(0, min(page, total_pages - 1))
|
| 313 |
page_articles = filtered[page * ARTICLES_PER_PAGE:(page + 1) * ARTICLES_PER_PAGE]
|
|
|
|
| 314 |
|
| 315 |
return templates.TemplateResponse(request, "blog_list.html", {
|
| 316 |
"articles": page_articles,
|
|
@@ -326,6 +344,7 @@ async def index(request: Request, id: str = None, page: int = 0,
|
|
| 326 |
"get_tags": get_tags,
|
| 327 |
"make_snippet": make_snippet,
|
| 328 |
"get_content": get_content,
|
|
|
|
| 329 |
})
|
| 330 |
|
| 331 |
|
|
|
|
| 193 |
except Exception:
|
| 194 |
return iso[:16].replace("T", " ")
|
| 195 |
|
| 196 |
+
templates.env.filters["to_jst"] = _to_jst_str
|
| 197 |
+
|
| 198 |
+
def get_all_comment_counts() -> dict:
|
| 199 |
+
try:
|
| 200 |
+
r = http_requests.get(cms_url("comments"), headers=CMS_HEADERS_GET(), params={
|
| 201 |
+
"limit": 100,
|
| 202 |
+
"fields": "articleId",
|
| 203 |
+
})
|
| 204 |
+
counts: dict = {}
|
| 205 |
+
for c in r.json().get("contents", []):
|
| 206 |
+
aid = c.get("articleId", "")
|
| 207 |
+
if aid:
|
| 208 |
+
counts[aid] = counts.get(aid, 0) + 1
|
| 209 |
+
return counts
|
| 210 |
+
except Exception:
|
| 211 |
+
return {}
|
| 212 |
+
|
| 213 |
def get_backups(original_id: str) -> list:
|
| 214 |
try:
|
| 215 |
r = http_requests.get(cms_url("blog-backup"), headers=CMS_HEADERS_GET(), params={
|
|
|
|
| 328 |
total_pages = max(1, -(-total // ARTICLES_PER_PAGE))
|
| 329 |
page = max(0, min(page, total_pages - 1))
|
| 330 |
page_articles = filtered[page * ARTICLES_PER_PAGE:(page + 1) * ARTICLES_PER_PAGE]
|
| 331 |
+
comment_counts = get_all_comment_counts()
|
| 332 |
|
| 333 |
return templates.TemplateResponse(request, "blog_list.html", {
|
| 334 |
"articles": page_articles,
|
|
|
|
| 344 |
"get_tags": get_tags,
|
| 345 |
"make_snippet": make_snippet,
|
| 346 |
"get_content": get_content,
|
| 347 |
+
"comment_counts": comment_counts,
|
| 348 |
})
|
| 349 |
|
| 350 |
|
templates/blog_detail.html
CHANGED
|
@@ -76,7 +76,7 @@
|
|
| 76 |
<div class="bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-xl p-4 mb-3">
|
| 77 |
<div class="flex justify-between items-center mb-1">
|
| 78 |
<span class="font-bold text-sm text-gray-700 dark:text-gray-200">{{ c.get("name","名無し") }}</span>
|
| 79 |
-
<span class="text-xs text-gray-400 dark:text-gray-500">{{ c.get("createdAt","")
|
| 80 |
</div>
|
| 81 |
<p class="text-sm text-gray-600 dark:text-gray-300 leading-relaxed">{{ c.get("body","") }}</p>
|
| 82 |
</div>
|
|
|
|
| 76 |
<div class="bg-white dark:bg-gray-800 border dark:border-gray-700 rounded-xl p-4 mb-3">
|
| 77 |
<div class="flex justify-between items-center mb-1">
|
| 78 |
<span class="font-bold text-sm text-gray-700 dark:text-gray-200">{{ c.get("name","名無し") }}</span>
|
| 79 |
+
<span class="text-xs text-gray-400 dark:text-gray-500">{{ c.get("createdAt","") | to_jst }}</span>
|
| 80 |
</div>
|
| 81 |
<p class="text-sm text-gray-600 dark:text-gray-300 leading-relaxed">{{ c.get("body","") }}</p>
|
| 82 |
</div>
|
templates/blog_list.html
CHANGED
|
@@ -51,7 +51,7 @@
|
|
| 51 |
{% endif %}
|
| 52 |
<div class="flex-1 min-w-0">
|
| 53 |
<h2 class="font-bold text-gray-800 dark:text-gray-100 text-base leading-snug mb-1 truncate">{{ a.get("title","無題") }}</h2>
|
| 54 |
-
<p class="text-xs text-gray-400 dark:text-gray-500 mb-2">👤 {{ a.get("author","") }} | 📅 {{ a.get("publishedAt","")[:10] }}</p>
|
| 55 |
<div class="mb-2">
|
| 56 |
{% for t in tags %}<span class="tag-badge">#{{ t }}</span>{% endfor %}
|
| 57 |
</div>
|
|
|
|
| 51 |
{% endif %}
|
| 52 |
<div class="flex-1 min-w-0">
|
| 53 |
<h2 class="font-bold text-gray-800 dark:text-gray-100 text-base leading-snug mb-1 truncate">{{ a.get("title","無題") }}</h2>
|
| 54 |
+
<p class="text-xs text-gray-400 dark:text-gray-500 mb-2">👤 {{ a.get("author","") }} | 📅 {{ a.get("publishedAt","")[:10] }} | 💬 {{ comment_counts.get(a.id, 0) }}件</p>
|
| 55 |
<div class="mb-2">
|
| 56 |
{% for t in tags %}<span class="tag-badge">#{{ t }}</span>{% endfor %}
|
| 57 |
</div>
|