重做文章详情页:拾光阅读版式与目录/代码/灯箱交互

- 新增内容页外壳 base_content.html 与 reading.css / reading.js
- 重写 post_detail.html:分类胶囊、阅读进度、首字下沉、代码块复制、
  侧栏目录、上下篇、图片灯箱、明暗主题
- post_detail 视图补充上下篇、字数与阅读时长
- base.html 补 extra_css / extra_js block,修复脑图详情页样式不加载
- 加入 mindmaps、api、首页静态资源与模板
- 忽略 __pycache__ / *.pyc / *.back,并将已跟踪的 .pyc 移出版本库
This commit is contained in:
2026-11-20 15:37:55 +08:00
parent 7e45fa620e
commit 6ab9cca4f3
70 changed files with 26103 additions and 38 deletions
View File
+3
View File
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
+6
View File
@@ -0,0 +1,6 @@
from django.apps import AppConfig
class ApiConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "api"
View File
+3
View File
@@ -0,0 +1,3 @@
from django.db import models
# Create your models here.
+20
View File
@@ -0,0 +1,20 @@
# api/renderers.py
from rest_framework.renderers import BaseRenderer
class MarkdownRenderer(BaseRenderer):
"""
自定义 Markdown 渲染器
告诉 DRF 如何处理 text/markdown 类型的响应
"""
media_type = 'text/markdown'
format = 'markdown'
charset = 'utf-8'
def render(self, data, accepted_media_type=None, renderer_context=None):
"""
data 就是我们在视图里传给 Response 的字符串
"""
if isinstance(data, str):
return data.encode(self.charset)
return str(data).encode(self.charset)
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+9
View File
@@ -0,0 +1,9 @@
from django.urls import path
from .views import sitemap_markdown
app_name = "api"
urlpatterns = [
# 对应前端请求的 /api/sitemap/
path('sitemap/', sitemap_markdown, name='sitemap-markdown'),
]
+60
View File
@@ -0,0 +1,60 @@
# api/views.py
from django.db import models
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.response import Response
from blog.models import Category, Post, SiteInfo
from .renderers import MarkdownRenderer
@api_view(['GET'])
@renderer_classes([MarkdownRenderer])
def sitemap_markdown(request):
"""
生成站点地图的 Markdown 文本
分类按最早文章时间升序,文章按发布时间从小到大
"""
site_name = "我的博客"
try:
site_info = SiteInfo.get_site_info()
if site_info.about_title:
site_name = site_info.about_title
except Exception:
pass
lines = [f"# {site_name}", ""]
# 分类按该分类下最早发布的文章时间升序排列
# 没有文章的分类(first_post_date=None)会排在最前面
categories = Category.objects.all().order_by('name')
for cat in categories:
# 文章按 published_at 从小到大(升序)
posts = cat.posts.filter(status='published').order_by('published_at')
lines.append(f"## {cat.name}")
lines.append("")
if posts.exists():
for post in posts:
post_url = f"/post/{post.slug}/"
lines.append(f"### [{post.title}]({post_url})")
else:
lines.append("- *暂无文章*")
lines.append("")
# 未分类文章,同样按发布时间升序
uncategorized = Post.objects.filter(
categories__isnull=True,
status='published'
).order_by('published_at')
if uncategorized.exists():
lines.append("## 未分类")
lines.append("")
for post in uncategorized:
post_url = f"/post/{post.slug}/"
lines.append(f"### [{post.title}]({post_url})")
lines.append("")
markdown_text = "\n".join(lines)
return Response(markdown_text)