加入「拾编」写作台:文章 / 分类管理 + Markdown 上传
- 新增 studio 应用与 /manage/ 写作台 - 文章增删改查、状态/分类/标签、搜索筛选分页 - 分类增删改查,支持父分类 - 直接上传 .md(front matter)并创建文章,编辑页支持 Markdown 导入 - Post 增加 content_format,公开文章页支持 Markdown 渲染 - 复用拾匣密码解锁;首页页脚新增写作台入口
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.2.18 on 2026-11-21 04:31
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("blog", "0003_siteinfo"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="post",
|
||||
name="content_format",
|
||||
field=models.CharField(
|
||||
choices=[("html", "HTML"), ("markdown", "Markdown")],
|
||||
default="html",
|
||||
max_length=20,
|
||||
verbose_name="内容格式",
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -110,6 +110,17 @@ class Post(models.Model):
|
||||
|
||||
# 文章内容(经典编辑器是 HTML,Markdown 插件的话可能是 md 源码)
|
||||
content = models.TextField(verbose_name='内容')
|
||||
|
||||
CONTENT_FORMAT_CHOICES = [
|
||||
('html', 'HTML'),
|
||||
('markdown', 'Markdown'),
|
||||
]
|
||||
content_format = models.CharField(
|
||||
max_length=20,
|
||||
choices=CONTENT_FORMAT_CHOICES,
|
||||
default='html',
|
||||
verbose_name='内容格式',
|
||||
)
|
||||
|
||||
excerpt = models.TextField(
|
||||
blank=True,
|
||||
@@ -163,6 +174,21 @@ class Post(models.Model):
|
||||
def get_absolute_url(self):
|
||||
return reverse('blog:post_detail', kwargs={'slug': self.slug})
|
||||
|
||||
@property
|
||||
def rendered_content(self):
|
||||
"""按 content_format 渲染正文;原有 HTML 文章保持原样。"""
|
||||
if self.content_format == 'markdown':
|
||||
try:
|
||||
import markdown
|
||||
except ImportError:
|
||||
return self.content or ''
|
||||
return markdown.markdown(
|
||||
self.content or '',
|
||||
extensions=['extra', 'sane_lists', 'toc'],
|
||||
output_format='html5',
|
||||
)
|
||||
return self.content or ''
|
||||
|
||||
|
||||
class SiteInfo(models.Model):
|
||||
"""
|
||||
|
||||
@@ -115,6 +115,8 @@ footer {
|
||||
display:flex; align-items:center; gap:14px;
|
||||
}
|
||||
footer .dot { width:3px; height:3px; border-radius:50%; background:var(--ink-faint); }
|
||||
.footer-link { color:var(--ink-faint); text-decoration:none; letter-spacing:.5px; transition:color .18s ease; }
|
||||
.footer-link:hover { color:var(--accent); }
|
||||
|
||||
/* =========================================================
|
||||
脑图容器
|
||||
|
||||
@@ -181,6 +181,8 @@
|
||||
<!-- <span>共 18 篇文章</span> -->
|
||||
<span class="dot"></span>
|
||||
<span>Powered by xiaoan</span>
|
||||
<span class="dot"></span>
|
||||
<a class="footer-link" href="/manage/">写作台</a>
|
||||
</footer>
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<!-- 代码高亮(深色代码块配套主题) -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/github-dark.min.css">
|
||||
{% block extra_css %}{% endblock %}
|
||||
{% block extra_head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<a class="skip-link" href="#article">跳到正文</a>
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
<div class="article-card">
|
||||
<div class="post-body" id="postBody">
|
||||
{{ post.content|safe }}
|
||||
{{ post.rendered_content|safe }}
|
||||
</div>
|
||||
|
||||
{% if post.tags.all %}
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ def post_detail(request, slug):
|
||||
next_post = Post.objects.filter(id=published_ids[index + 1]).first()
|
||||
|
||||
# 阅读统计:先去掉 HTML 标签,再按非空白字符计数
|
||||
plain_text = strip_tags(post.content or '')
|
||||
plain_text = strip_tags(post.rendered_content or '')
|
||||
char_count = len(re.sub(r'\s+', '', plain_text))
|
||||
read_minutes = max(1, math.ceil(char_count / 400))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user