Skip to content

Commit acf3c46

Browse files
authored
issues: 功能优化和体验优化 (#972)
* pref: 优化小屏幕下 cherry-markdown.css 样式 * fix: 修复 markdown 上传图片功能没有回显链接问题 * fix: #853 修复文章被删除后可以从缓存读取 * feat: #834 增加文章私有状态, 文章分类下不展示私有文章
1 parent cd9667b commit acf3c46

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed

controllers/BlogController.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (c *BlogController) ManageList() {
128128

129129
pageIndex, _ := c.GetInt("page", 1)
130130

131-
blogList, totalCount, err := models.NewBlog().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId, "")
131+
blogList, totalCount, err := models.NewBlog().FindToPager(pageIndex, conf.PageSize, c.Member.MemberId, "all")
132132

133133
if err != nil {
134134
c.ShowErrorPage(500, err.Error())
@@ -168,7 +168,7 @@ func (c *BlogController) ManageSetting() {
168168
if strings.Count(blogExcerpt, "") > 500 {
169169
c.JsonResult(6008, i18n.Tr(c.Lang, "message.blog_digest_tips"))
170170
}
171-
if blogStatus != "public" && blogStatus != "password" && blogStatus != "draft" {
171+
if blogStatus != "private" && blogStatus != "public" && blogStatus != "password" && blogStatus != "draft" {
172172
blogStatus = "public"
173173
}
174174
if blogStatus == "password" && blogPassword == "" {

models/Blog.go

+23-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/mindoc-org/mindoc/utils"
1616
)
1717

18-
//博文表
18+
// 博文表
1919
type Blog struct {
2020
BlogId int `orm:"pk;auto;unique;column(blog_id)" json:"blog_id"`
2121
//文章标题
@@ -89,7 +89,7 @@ func NewBlog() *Blog {
8989
}
9090
}
9191

92-
//根据文章ID查询文章
92+
// 根据文章ID查询文章
9393
func (b *Blog) Find(blogId int) (*Blog, error) {
9494
o := orm.NewOrm()
9595

@@ -102,7 +102,7 @@ func (b *Blog) Find(blogId int) (*Blog, error) {
102102
return b.Link()
103103
}
104104

105-
//从缓存中读取文章
105+
// 从缓存中读取文章
106106
func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
107107
key := fmt.Sprintf("blog-id-%d", blogId)
108108
var temp Blog
@@ -126,7 +126,7 @@ func (b *Blog) FindFromCache(blogId int) (blog *Blog, err error) {
126126
return
127127
}
128128

129-
//查找指定用户的指定文章
129+
// 查找指定用户的指定文章
130130
func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
131131
o := orm.NewOrm()
132132

@@ -139,7 +139,7 @@ func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
139139
return b.Link()
140140
}
141141

142-
//根据文章标识查询文章
142+
// 根据文章标识查询文章
143143
func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
144144
o := orm.NewOrm()
145145

@@ -151,7 +151,7 @@ func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
151151
return b, nil
152152
}
153153

154-
//获取指定文章的链接内容
154+
// 获取指定文章的链接内容
155155
func (b *Blog) Link() (*Blog, error) {
156156
o := orm.NewOrm()
157157
//如果是链接文章,则需要从链接的项目中查找文章内容
@@ -211,14 +211,14 @@ func (b *Blog) Link() (*Blog, error) {
211211
return b, nil
212212
}
213213

214-
//判断指定的文章标识是否存在
214+
// 判断指定的文章标识是否存在
215215
func (b *Blog) IsExist(identify string) bool {
216216
o := orm.NewOrm()
217217

218218
return o.QueryTable(b.TableNameWithPrefix()).Filter("blog_identify", identify).Exist()
219219
}
220220

221-
//保存文章
221+
// 保存文章
222222
func (b *Blog) Save(cols ...string) error {
223223
o := orm.NewOrm()
224224

@@ -239,7 +239,7 @@ func (b *Blog) Save(cols ...string) error {
239239
b.Modified = time.Now()
240240
_, err = o.Update(b, cols...)
241241
key := fmt.Sprintf("blog-id-%d", b.BlogId)
242-
cache.Delete(key)
242+
_ = cache.Delete(key)
243243

244244
} else {
245245

@@ -250,7 +250,7 @@ func (b *Blog) Save(cols ...string) error {
250250
return err
251251
}
252252

253-
//过滤文章的危险标签,处理文章外链以及图片.
253+
// 过滤文章的危险标签,处理文章外链以及图片.
254254
func (b *Blog) Processor() *Blog {
255255

256256
b.BlogRelease = utils.SafetyProcessor(b.BlogRelease)
@@ -285,7 +285,7 @@ func (b *Blog) Processor() *Blog {
285285
return b
286286
}
287287

288-
//分页查询文章列表
288+
// 分页查询文章列表
289289
func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string) (blogList []*Blog, totalCount int, err error) {
290290

291291
o := orm.NewOrm()
@@ -297,10 +297,14 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
297297
if memberId > 0 {
298298
query = query.Filter("member_id", memberId)
299299
}
300-
if status != "" {
300+
if status != "" && status != "all" {
301301
query = query.Filter("blog_status", status)
302302
}
303303

304+
if status == "" {
305+
query = query.Filter("blog_status__ne", "private")
306+
}
307+
304308
_, err = query.OrderBy("-order_index", "-blog_id").Offset(offset).Limit(pageSize).All(&blogList)
305309

306310
if err != nil {
@@ -326,8 +330,11 @@ func (b *Blog) FindToPager(pageIndex, pageSize int, memberId int, status string)
326330
return
327331
}
328332

329-
//删除文章
333+
// 删除文章
330334
func (b *Blog) Delete(blogId int) error {
335+
// 删除文章缓存
336+
key := fmt.Sprintf("blog-id-%d", blogId)
337+
_ = cache.Delete(key)
331338
o := orm.NewOrm()
332339

333340
_, err := o.QueryTable(b.TableNameWithPrefix()).Filter("blog_id", blogId).Delete()
@@ -337,7 +344,7 @@ func (b *Blog) Delete(blogId int) error {
337344
return err
338345
}
339346

340-
//查询下一篇文章
347+
// 查询下一篇文章
341348
func (b *Blog) QueryNext(blogId int) (*Blog, error) {
342349
o := orm.NewOrm()
343350
blog := NewBlog()
@@ -355,7 +362,7 @@ func (b *Blog) QueryNext(blogId int) (*Blog, error) {
355362
return blog, err
356363
}
357364

358-
//查询下一篇文章
365+
// 查询下一篇文章
359366
func (b *Blog) QueryPrevious(blogId int) (*Blog, error) {
360367
o := orm.NewOrm()
361368
blog := NewBlog()
@@ -373,7 +380,7 @@ func (b *Blog) QueryPrevious(blogId int) (*Blog, error) {
373380
return blog, err
374381
}
375382

376-
//关联文章附件
383+
// 关联文章附件
377384
func (b *Blog) LinkAttach() (err error) {
378385

379386
o := orm.NewOrm()

static/cherry/cherry-markdown.css

+12
Original file line numberDiff line numberDiff line change
@@ -6078,3 +6078,15 @@ span.change {
60786078
border-radius: 10px !important;
60796079
background-color: #b3d4fc !important;
60806080
}
6081+
6082+
6083+
@media screen and (max-width: 1400px) {
6084+
.cherry-toolbar-button {
6085+
padding: 0;
6086+
}
6087+
6088+
.cherry-toolbar .toolbar-left {
6089+
justify-content: space-between;
6090+
width: 95%;
6091+
}
6092+
}

static/editor.md/plugins/image-dialog/image-dialog.js

+11-17
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"<label>" + imageLang.url + "</label>" +
5252
"<input type=\"text\" data-url />" + (function() {
5353
return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" +
54-
// 3xxx 下行添加multiple=\"multiple\"
54+
// 3xxx �������multiple=\"multiple\"
5555
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/jpeg,image/png,image/gif,image/jpg\" multiple=\"multiple\" />" +
5656
"<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" +
5757
"</div>" : "";
@@ -78,7 +78,7 @@
7878
opacity: settings.dialogMaskOpacity,
7979
backgroundColor: settings.dialogMaskBgColor
8080
},
81-
// 这里将多图片地址改造后插入文档中
81+
// ���ォ��ͼƬ��ַ���������ĵ���
8282
buttons: {
8383
enter: [lang.buttons.enter, function() {
8484
var url = this.find("[data-url]").val();
@@ -88,7 +88,7 @@
8888
alert(imageLang.imageURLEmpty);
8989
return false;
9090
}
91-
// 这里增加循环
91+
// ��������ѭ��
9292
let arr = url.split(";");
9393
var altAttr = (alt !== "") ? " \"" + alt + "\"" : "";
9494
for (let i = 0; i < arr.length; i++) {
@@ -121,19 +121,19 @@
121121
fileInput.bind("change", function() {
122122
// 3xxx 20240602
123123
// let formData = new FormData();
124-
// 获取文本框dom
124+
// ��ȡ�ı���dom
125125
// var doc = document.getElementById('doc');
126-
// 获取上传控件dom
126+
// ��ȡ�ϴ��ؼ�dom
127127
// var upload = document.getElementById('upload');
128128
// let files = upload.files;
129-
//遍历文件信息append到formData存储
129+
//�����ļ���Ϣappend��formData�洢
130130
// for (let i = 0; i < files.length; i++) {
131131
// let file = files[i]
132132
// formData.append('files', file)
133133
// }
134-
// 获取文件名
134+
// ��ȡ�ļ���
135135
// var fileName = upload.files[0].name;
136-
// 获取文件路径
136+
// ��ȡ�ļ�·��
137137
// var filePath = upload.value;
138138
// doc.value = fileName;
139139
// 3xxx
@@ -161,17 +161,11 @@
161161
var json = (body.innerText) ? body.innerText : ((body.textContent) ? body.textContent : null);
162162
json = (typeof JSON.parse !== "undefined") ? JSON.parse(json) : eval("(" + json + ")");
163163
var url="";
164-
for (let i = 0; i < json.length; i++) {
165-
if (json[i].success === 1) {
166-
if (i==0){
167-
url=json[i].url;
168-
}else{
169-
url=url+";"+json[i].url;
170-
}
164+
if (json.success === 1) {
165+
url=json.url;
171166
} else {
172-
alert(json[i].message);
167+
alert(json.message);
173168
}
174-
}
175169
dialog.find("[data-url]").val(url)
176170
return false;
177171
};

views/blog/manage_setting.tpl

+4-1
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@
7979
<label class="radio-inline">
8080
<input type="radio" {{if eq .Model.BlogStatus "password"}}checked{{end}} name="status" value="password">{{i18n .Lang "blog.encryption"}}<span class="text"></span>
8181
</label>
82+
<label class="radio-inline">
83+
<input type="radio" {{if eq .Model.BlogStatus "private"}}checked{{end}} name="status" value="private">{{i18n .Lang "blog.private"}}<span class="text"></span>
84+
</label>
8285
</div>
8386
</div>
84-
<div class="form-group"{{if eq .Model.BlogStatus "public"}} style="display: none;"{{end}} id="blogPassword">
87+
<div class="form-group"{{if ne .Model.BlogStatus "password"}} style="display: none;"{{end}} id="blogPassword">
8588
<label>{{i18n .Lang "blog.blog_pwd"}}</label>
8689
<input type="password" class="form-control" name="password" id="password" placeholder="{{i18n .Lang "blog.blog_pwd"}}" value="{{.Model.Password}}" maxlength="20">
8790
</div>

0 commit comments

Comments
 (0)