完善了首页和关于前端页面,以及解决了图片存储方案问题

This commit is contained in:
2026-10-20 04:53:06 +08:00
parent 16a75807ee
commit 7e45fa620e
20 changed files with 625 additions and 96 deletions
+117
View File
@@ -0,0 +1,117 @@
{% extends "base.html" %}
{% load static %}
{% block title %}郭安的小站{% endblock %}
{% block content %}
{% for post in posts %}
<div class="post-item">
<h2><a href="{{ post.get_absolute_url }}">{{ post.title }}</a></h2>
<div class="post-date">{{ post.published_at|date:"Y年m月d日" }}</div>
{% if post.excerpt %}
<div class="post-summary">{{ post.excerpt }}</div>
{% endif %}
</div>
{% empty %}
<div class="post-item" style="text-align: center; padding: 4rem 0; color: var(--text-muted);">
<p style="margin-bottom: 0.5rem;">还没有文章</p>
<p style="font-size: 0.9rem;">
<a href="/admin/" style="color: var(--text-light); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px;">去管理后台写一篇</a>
</p>
</div>
{% endfor %}
<!-- ✅ 分页组件(可点击页码 + 智能省略) -->
{% if posts.paginator.num_pages > 1 %}
<nav style="
margin-top: 3rem;
text-align: center;
font-family: -apple-system, 'Noto Sans SC', sans-serif;
font-size: 0.9rem;
">
<!-- 首页 -->
{% if posts.has_previous %}
<a href="?page=1" style="margin-right: 0.6rem; color: var(--text-light); text-decoration: none;">« 首页</a>
{% else %}
<span style="margin-right: 0.6rem; color: var(--text-muted);">« 首页</span>
{% endif %}
<!-- 上一页 -->
{% if posts.has_previous %}
<a href="?page={{ posts.previous_page_number }}" style="margin-right: 1rem; color: var(--text-light); text-decoration: none;">‹ 上一页</a>
{% else %}
<span style="margin-right: 1rem; color: var(--text-muted);">‹ 上一页</span>
{% endif %}
<!-- ✅ 页码列表(智能省略) -->
{% for num in posts.paginator.page_range %}
{% if posts.paginator.num_pages <= 9 %}
<!-- 总页数 ≤ 9:全部显示 -->
{% if num == posts.number %}
<span style="
margin: 0 0.3rem;
color: var(--bg);
background: var(--text);
padding: 0.2rem 0.6rem;
border-radius: var(--radius);
font-weight: 600;
">{{ num }}</span>
{% else %}
<a href="?page={{ num }}" style="margin: 0 0.3rem; color: var(--text-light); text-decoration: none;">{{ num }}</a>
{% endif %}
{% else %}
<!-- 总页数 > 9:智能省略 -->
{% if num == 1 or num == posts.paginator.num_pages %}
<!-- 第一页 & 最后一页始终显示 -->
{% if num == posts.number %}
<span style="
margin: 0 0.3rem;
color: var(--bg);
background: var(--text);
padding: 0.2rem 0.6rem;
border-radius: var(--radius);
font-weight: 600;
">{{ num }}</span>
{% else %}
<a href="?page={{ num }}" style="margin: 0 0.3rem; color: var(--text-light); text-decoration: none;">{{ num }}</a>
{% endif %}
{% elif num >= posts.number|add:'-2' and num <= posts.number|add:'2' %}
<!-- 当前页前后 2 页 -->
{% if num == posts.number %}
<span style="
margin: 0 0.3rem;
color: var(--bg);
background: var(--text);
padding: 0.2rem 0.6rem;
border-radius: var(--radius);
font-weight: 600;
">{{ num }}</span>
{% else %}
<a href="?page={{ num }}" style="margin: 0 0.3rem; color: var(--text-light); text-decoration: none;">{{ num }}</a>
{% endif %}
{% elif num == posts.number|add:'-3' or num == posts.number|add:'3' %}
<!-- 省略号 -->
<span style="margin: 0 0.2rem; color: var(--text-muted);">…</span>
{% endif %}
{% endif %}
{% endfor %}
<!-- 下一页 -->
{% if posts.has_next %}
<a href="?page={{ posts.next_page_number }}" style="margin-left: 1rem; color: var(--text-light); text-decoration: none;">下一页 ›</a>
{% else %}
<span style="margin-left: 1rem; color: var(--text-muted);">下一页 ›</span>
{% endif %}
<!-- 末页 -->
{% if posts.has_next %}
<a href="?page={{ posts.paginator.num_pages }}" style="margin-left: 0.6rem; color: var(--text-light); text-decoration: none;">末页 »</a>
{% else %}
<span style="margin-left: 0.6rem; color: var(--text-muted);">末页 »</span>
{% endif %}
</nav>
{% endif %}
{% endblock %}