加入「拾编」写作台:文章 / 分类管理 + Markdown 上传
- 新增 studio 应用与 /manage/ 写作台 - 文章增删改查、状态/分类/标签、搜索筛选分页 - 分类增删改查,支持父分类 - 直接上传 .md(front matter)并创建文章,编辑页支持 Markdown 导入 - Post 增加 content_format,公开文章页支持 Markdown 渲染 - 复用拾匣密码解锁;首页页脚新增写作台入口
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{% if messages %}
|
||||
<div class="st-messages" role="status">
|
||||
{% for message in messages %}
|
||||
<p class="st-msg {{ message.tags }}">{{ message }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -0,0 +1,144 @@
|
||||
{% extends "base_content.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}{% if is_new %}新建文章{% else %}编辑文章{% endif %} · 拾编{% endblock %}
|
||||
{% block description %}博客文章编辑{% endblock %}
|
||||
{% block brand_sub %}MIND MAP · STUDIO{% endblock %}
|
||||
{% block footer %}© 2026 拾光<span class="dot"></span>写字的地方{% endblock %}
|
||||
{% block extra_head %}<meta name="robots" content="noindex,nofollow">{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="st st-editor-page">
|
||||
<a class="st-back" href="{% url 'studio:index' %}">← 写作台</a>
|
||||
|
||||
<header class="st-head">
|
||||
<div>
|
||||
<p class="st-eyebrow"><span aria-hidden="true">✦</span>拾编 · STUDIO</p>
|
||||
<h1>{% if is_new %}新建文章{% else %}编辑文章{% endif %}</h1>
|
||||
<p class="st-sub">
|
||||
{% if post %}
|
||||
/post/{{ post.slug }}/ · 最后更新 {{ post.updated_at|date:"Y-m-d H:i" }}
|
||||
{% else %}
|
||||
写好后可以先存草稿,再从写作台发布。
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
<div class="st-head-actions">
|
||||
{% if post and post.status == 'published' %}
|
||||
<a class="st-btn" href="{{ post.get_absolute_url }}" target="_blank" rel="noopener">查看文章 ↗</a>
|
||||
{% endif %}
|
||||
<button class="st-btn st-btn-primary" type="submit" form="stPostForm">保存</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% include "studio/_messages.html" %}
|
||||
|
||||
<form class="st-editor" id="stPostForm" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.non_field_errors }}
|
||||
|
||||
<div class="st-editor-main">
|
||||
<div class="st-field">
|
||||
<label for="{{ form.title.id_for_label }}">标题</label>
|
||||
{{ form.title }}
|
||||
{{ form.title.errors }}
|
||||
</div>
|
||||
|
||||
<div class="st-editor-meta-row">
|
||||
<div class="st-field">
|
||||
<label for="{{ form.slug.id_for_label }}">URL 别名</label>
|
||||
{{ form.slug }}
|
||||
<p class="st-help">留空会自动生成;文章地址是 <code>/post/<slug>/</code>。</p>
|
||||
</div>
|
||||
<div class="st-field st-field-narrow">
|
||||
<label for="{{ form.content_format.id_for_label }}">内容格式</label>
|
||||
{{ form.content_format }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="st-field">
|
||||
<div class="st-content-head">
|
||||
<label for="{{ form.content.id_for_label }}">正文</label>
|
||||
<label class="st-md-import" for="stMdImport">从 Markdown 导入
|
||||
<input type="file" id="stMdImport" accept=".md,.markdown">
|
||||
</label>
|
||||
<span class="st-char-count"><b id="stCharCount">0</b> 字</span>
|
||||
</div>
|
||||
{{ form.content }}
|
||||
{{ form.content.errors }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<aside class="st-editor-side">
|
||||
<section class="st-side-card">
|
||||
<h2>发布</h2>
|
||||
<div class="st-field">
|
||||
<label for="{{ form.status.id_for_label }}">状态</label>
|
||||
{{ form.status }}
|
||||
</div>
|
||||
<div class="st-field">
|
||||
<label for="{{ form.published_at.id_for_label }}">发布时间</label>
|
||||
{{ form.published_at }}
|
||||
</div>
|
||||
<div class="st-field">
|
||||
<label for="{{ form.excerpt.id_for_label }}">摘要</label>
|
||||
{{ form.excerpt }}
|
||||
</div>
|
||||
<div class="st-form-actions">
|
||||
<button class="st-btn st-btn-primary" type="submit">保存文章</button>
|
||||
</div>
|
||||
<p class="st-help">保存后可继续编辑;状态设为「已发布」才会出现在博客上。</p>
|
||||
</section>
|
||||
|
||||
<section class="st-side-card">
|
||||
<h2>分类</h2>
|
||||
<div class="st-check-grid">
|
||||
{% for checkbox in form.categories %}
|
||||
<label class="st-check">{{ checkbox.tag }}<span>{{ checkbox.choice_label }}</span></label>
|
||||
{% empty %}
|
||||
<p class="st-help">还没有分类,先回写作台建一个。</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="st-side-card">
|
||||
<h2>标签</h2>
|
||||
<div class="st-check-grid">
|
||||
{% for checkbox in form.tags %}
|
||||
<label class="st-check">{{ checkbox.tag }}<span>{{ checkbox.choice_label }}</span></label>
|
||||
{% empty %}
|
||||
<p class="st-help">还没有标签。</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="st-field">
|
||||
<label for="{{ form.new_tags.id_for_label }}">新标签</label>
|
||||
{{ form.new_tags }}
|
||||
<p class="st-help">多个用逗号分隔,保存时自动创建。</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{% if post %}
|
||||
<section class="st-side-card st-danger-zone">
|
||||
<h2>删除</h2>
|
||||
<p class="st-help">删除后不可恢复。</p>
|
||||
<button class="st-btn st-danger" type="submit" form="stDeleteForm">删除文章</button>
|
||||
</section>
|
||||
{% endif %}
|
||||
</aside>
|
||||
</form>
|
||||
|
||||
{% if post %}
|
||||
<form id="stDeleteForm" method="post" action="{% url 'studio:post_delete' post.id %}" data-confirm="确定删除这篇文章?此操作不可恢复。">
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'studio/studio.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script src="{% static 'studio/studio.js' %}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,35 @@
|
||||
{% extends "base_content.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}拾编 · 写作台{% endblock %}
|
||||
{% block description %}博客文章与分类管理{% endblock %}
|
||||
{% block brand_sub %}MIND MAP · STUDIO{% endblock %}
|
||||
{% block footer %}© 2026 拾光<span class="dot"></span>写字的地方{% endblock %}
|
||||
{% block extra_head %}<meta name="robots" content="noindex,nofollow">{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="st st-lock-page">
|
||||
<section class="st-lock-card">
|
||||
<p class="st-eyebrow"><span aria-hidden="true">✦</span>拾编 · STUDIO</p>
|
||||
<h1>写作台</h1>
|
||||
<p class="st-lock-sub">文章、分类和草稿,只对站点主人开放。</p>
|
||||
|
||||
<form class="st-unlock-form" id="stUnlockForm">
|
||||
<label class="sr-only" for="stPassword">密码</label>
|
||||
<input type="password" id="stPassword" placeholder="输入密码" autocomplete="current-password">
|
||||
<button class="st-btn st-btn-primary" type="submit">解锁进入</button>
|
||||
</form>
|
||||
|
||||
<p class="st-error" id="stError" hidden></p>
|
||||
<p class="st-lock-hint">与拾匣共用密码</p>
|
||||
</section>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'studio/studio.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script src="{% static 'studio/studio.js' %}"></script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,200 @@
|
||||
{% extends "base_content.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}拾编 · 写作台{% endblock %}
|
||||
{% block description %}博客文章与分类管理{% endblock %}
|
||||
{% block brand_sub %}MIND MAP · STUDIO{% endblock %}
|
||||
{% block footer %}© 2026 拾光<span class="dot"></span>写字的地方{% endblock %}
|
||||
{% block extra_head %}<meta name="robots" content="noindex,nofollow">{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="st">
|
||||
<header class="st-head">
|
||||
<div>
|
||||
<p class="st-eyebrow"><span aria-hidden="true">✦</span>拾编 · STUDIO</p>
|
||||
<h1>写作台</h1>
|
||||
<p class="st-sub">文章、分类和草稿,都放在一张桌子上。</p>
|
||||
</div>
|
||||
<div class="st-head-actions">
|
||||
<a class="st-btn" href="/">回首页</a>
|
||||
<button class="st-btn" id="stLockBtn" type="button">锁定</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{% include "studio/_messages.html" %}
|
||||
|
||||
<div class="st-stats">
|
||||
<div class="st-stat"><b>{{ stats.total }}</b><span>全部文章</span></div>
|
||||
<div class="st-stat"><b>{{ stats.published }}</b><span>已发布</span></div>
|
||||
<div class="st-stat"><b>{{ stats.draft }}</b><span>草稿</span></div>
|
||||
<div class="st-stat"><b>{{ stats.categories }}</b><span>分类</span></div>
|
||||
<div class="st-stat"><b>{{ stats.tags }}</b><span>标签</span></div>
|
||||
</div>
|
||||
|
||||
<div class="st-toolbar">
|
||||
<a class="st-btn st-btn-primary" href="{% url 'studio:post_new' %}">+ 新建文章</a>
|
||||
<button class="st-btn" id="stUploadToggle" type="button">↑ 上传 Markdown</button>
|
||||
<span class="st-toolbar-hint">上传后先进入编辑页,确认后再发布。</span>
|
||||
</div>
|
||||
|
||||
<form class="st-upload-panel" id="stUploadForm" method="post"
|
||||
action="{% url 'studio:upload_markdown' %}" enctype="multipart/form-data" hidden>
|
||||
{% csrf_token %}
|
||||
<div class="st-upload-grid">
|
||||
<label>Markdown 文件
|
||||
<input class="st-file" type="file" name="file" accept=".md,.markdown" required>
|
||||
</label>
|
||||
<label>归入分类
|
||||
<select class="st-input" name="category">
|
||||
<option value="">不归入分类</option>
|
||||
{% for cat in categories %}
|
||||
<option value="{{ cat.id }}">{{ cat.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<label>默认状态
|
||||
<select class="st-input" name="status">
|
||||
<option value="draft">草稿</option>
|
||||
<option value="published">已发布</option>
|
||||
</select>
|
||||
</label>
|
||||
<button class="st-btn st-btn-primary" type="submit">上传并创建</button>
|
||||
</div>
|
||||
<p class="st-help">支持 front matter:<code>title / slug / date / status / categories / tags / excerpt</code>。上传后先进入编辑页,确认后再发布。</p>
|
||||
</form>
|
||||
|
||||
<div class="st-layout">
|
||||
<section class="st-panel st-posts">
|
||||
<div class="st-panel-head">
|
||||
<h2>文章 <b>{{ filtered_count }}</b></h2>
|
||||
</div>
|
||||
|
||||
<form class="st-filters" method="get" action="{% url 'studio:index' %}">
|
||||
<select class="st-input" name="status" aria-label="状态">
|
||||
<option value="all" {% if status == 'all' %}selected{% endif %}>全部状态</option>
|
||||
<option value="published" {% if status == 'published' %}selected{% endif %}>已发布</option>
|
||||
<option value="draft" {% if status == 'draft' %}selected{% endif %}>草稿</option>
|
||||
</select>
|
||||
<select class="st-input" name="category" aria-label="分类">
|
||||
<option value="">全部分类</option>
|
||||
{% for cat in categories %}
|
||||
<option value="{{ cat.id }}" {% if category_id == cat.id %}selected{% endif %}>{{ cat.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input class="st-input" type="search" name="q" value="{{ query }}" placeholder="搜索标题 / 摘要 / 正文">
|
||||
<button class="st-btn" type="submit">筛选</button>
|
||||
<a class="st-btn st-btn-ghost" href="{% url 'studio:index' %}">重置</a>
|
||||
</form>
|
||||
|
||||
<div class="st-table-wrap">
|
||||
<table class="st-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>文章</th>
|
||||
<th>状态</th>
|
||||
<th>分类</th>
|
||||
<th>发布时间</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for post in page %}
|
||||
<tr>
|
||||
<td>
|
||||
<a class="st-post-title" href="{% url 'studio:post_edit' post.id %}">{{ post.title }}</a>
|
||||
<small class="st-slug">/post/{{ post.slug }}/</small>
|
||||
</td>
|
||||
<td><span class="st-badge {{ post.status }}">{{ post.get_status_display }}</span></td>
|
||||
<td>
|
||||
<span class="st-cats">
|
||||
{% for cat in post.categories.all %}<span>{{ cat.name }}</span>{% empty %}<i>未分类</i>{% endfor %}
|
||||
</span>
|
||||
</td>
|
||||
<td><time>{{ post.published_at|date:"Y-m-d H:i" }}</time></td>
|
||||
<td class="st-row-actions">
|
||||
<a href="{% url 'studio:post_edit' post.id %}">编辑</a>
|
||||
{% if post.status == 'published' %}
|
||||
<a href="{{ post.get_absolute_url }}" target="_blank" rel="noopener">查看</a>
|
||||
{% endif %}
|
||||
<form method="post" action="{% url 'studio:post_delete' post.id %}" data-confirm="确定删除这篇文章?此操作不可恢复。">
|
||||
{% csrf_token %}
|
||||
<button class="st-link-danger" type="submit">删除</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="5" class="st-table-empty">没有符合条件的文章。</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% if page.paginator.num_pages > 1 %}
|
||||
<nav class="st-pager" aria-label="文章分页">
|
||||
{% if page.has_previous %}
|
||||
<a href="?page={{ page.previous_page_number }}{% if status != 'all' %}&status={{ status }}{% endif %}{% if category_id %}&category={{ category_id }}{% endif %}{% if query %}&q={{ query|urlencode }}{% endif %}">‹ 上一页</a>
|
||||
{% endif %}
|
||||
<span>{{ page.number }} / {{ page.paginator.num_pages }}</span>
|
||||
{% if page.has_next %}
|
||||
<a href="?page={{ page.next_page_number }}{% if status != 'all' %}&status={{ status }}{% endif %}{% if category_id %}&category={{ category_id }}{% endif %}{% if query %}&q={{ query|urlencode }}{% endif %}">下一页 ›</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
<aside class="st-panel st-cats" id="categories">
|
||||
<div class="st-panel-head">
|
||||
<h2>分类 <b>{{ stats.categories }}</b></h2>
|
||||
<a href="{% url 'studio:index' %}#categories">新建</a>
|
||||
</div>
|
||||
|
||||
<ul class="st-cat-list">
|
||||
{% for cat in categories %}
|
||||
<li{% if edit_category and edit_category.id == cat.id %} class="is-editing"{% endif %}>
|
||||
<div class="st-cat-info">
|
||||
<a href="?edit_cat={{ cat.id }}#categories">{{ cat.name }}</a>
|
||||
<small>{{ cat.slug }}{% if cat.parent %} · 上级 {{ cat.parent.name }}{% endif %}</small>
|
||||
</div>
|
||||
<span class="st-cat-count">{{ cat.post_count }}</span>
|
||||
<div class="st-cat-actions">
|
||||
<a href="?edit_cat={{ cat.id }}#categories">编辑</a>
|
||||
<form method="post" action="{% url 'studio:category_delete' cat.id %}" data-confirm="删除分类「{{ cat.name }}」?文章会保留,但子分类会一起删除。">
|
||||
{% csrf_token %}
|
||||
<button class="st-link-danger" type="submit">删除</button>
|
||||
</form>
|
||||
</div>
|
||||
</li>
|
||||
{% empty %}
|
||||
<li class="st-cat-empty">还没有分类。</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<h3 class="st-cat-form-title">{% if edit_category %}编辑「{{ edit_category.name }}」{% else %}新建分类{% endif %}</h3>
|
||||
<form class="st-cat-form" method="post" action="{% url 'studio:category_save' %}">
|
||||
{% csrf_token %}
|
||||
{{ category_form.id }}
|
||||
<label>名称 {{ category_form.name }}</label>
|
||||
<label>URL 别名 {{ category_form.slug }}</label>
|
||||
<label>上级分类 {{ category_form.parent }}</label>
|
||||
<label>描述 {{ category_form.description }}</label>
|
||||
<div class="st-form-actions">
|
||||
<button class="st-btn st-btn-primary" type="submit">{% if edit_category %}保存修改{% else %}创建分类{% endif %}</button>
|
||||
{% if edit_category %}
|
||||
<a class="st-btn st-btn-ghost" href="{% url 'studio:index' %}#categories">取消</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<p class="st-note">写作台只对站点主人开放;解锁状态与拾匣共用,锁定后此页会回到密码界面。</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link rel="stylesheet" href="{% static 'studio/studio.css' %}">
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script src="{% static 'studio/studio.js' %}"></script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user