This commit is contained in:
deepzz0
2016-10-03 15:51:54 +08:00
parent abda7b511e
commit 1ff66bdd16
8 changed files with 125 additions and 143 deletions
+26 -34
View File
@@ -152,12 +152,12 @@ func apiPostAdd(c *gin.Context) {
var cid int var cid int
defer func() { defer func() {
if !publish { if !publish {
// {"success":1,"time":"10:40:46 AM","cid":"4"}
if err == nil { if err == nil {
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid}) c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
return } else {
}
logd.Error(err) logd.Error(err)
c.JSON(http.StatusOK, gin.H{"fail": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
}
} }
if err == nil { if err == nil {
c.Redirect(http.StatusFound, "/admin/manage-posts") c.Redirect(http.StatusFound, "/admin/manage-posts")
@@ -183,7 +183,6 @@ func apiPostAdd(c *gin.Context) {
t := CheckDate(date) t := CheckDate(date)
serieid := CheckSerieID(serie) serieid := CheckSerieID(serie)
publish = CheckPublish(do) publish = CheckPublish(do)
if cid, err = strconv.Atoi(c.PostForm("cid")); err != nil || cid < 1 {
artc := &Article{ artc := &Article{
Title: title, Title: title,
Content: text, Content: text,
@@ -194,6 +193,8 @@ func apiPostAdd(c *gin.Context) {
SerieID: serieid, SerieID: serieid,
Tags: tags, Tags: tags,
} }
cid, err = strconv.Atoi(c.PostForm("cid"))
if err != nil || cid < 1 {
err = AddArticle(artc) err = AddArticle(artc)
if err != nil { if err != nil {
logd.Error(err) logd.Error(err)
@@ -203,43 +204,35 @@ func apiPostAdd(c *gin.Context) {
if publish { if publish {
ElasticIndex(artc) ElasticIndex(artc)
} }
} else {
artc := QueryArticle(int32(cid))
if artc == nil {
err = errors.New("没有发现该文章")
return return
} }
if publish { artc.ID = int32(cid)
if Ei.MapArticles[artc.Slug] != nil { if CheckBool(c.PostForm("update")) {
i, a := GetArticle(artc.ID)
DelFromLinkedList(a)
Ei.Articles[i] = artc
if a.SerieID != serieid {
ManageSeriesArticle(a, false, DELETE)
}
if strings.Join(a.Tags, ",") != tag {
ManageTagsArticle(a, false, DELETE)
}
ManageArchivesArticle(a, false, DELETE)
} else {
Ei.Articles = append(Ei.Articles, artc)
artc.IsDraft = false
}
Ei.MapArticles[artc.Slug] = artc
}
artc.Title = title
artc.Slug = slug
artc.Content = text
artc.CreateTime = t
artc.UpdateTime = time.Now() artc.UpdateTime = time.Now()
artc.SerieID = serieid }
artc.Tags = tags i, a := GetArticle(artc.ID)
if a != nil {
artc.IsDraft = false
artc.Count = a.Count
artc.UpdateTime = a.UpdateTime
}
err = UpdateArticle(bson.M{"id": artc.ID}, artc) err = UpdateArticle(bson.M{"id": artc.ID}, artc)
if err != nil { if err != nil {
logd.Error(err) logd.Error(err)
return return
} }
if publish { if !artc.IsDraft {
if a != nil {
Ei.Articles = append(Ei.Articles[0:i], Ei.Articles[i+1:]...)
DelFromLinkedList(a)
ManageTagsArticle(a, false, DELETE)
ManageSeriesArticle(a, false, DELETE)
ManageArchivesArticle(a, false, DELETE)
delete(Ei.MapArticles, a.Slug)
a = nil
}
Ei.MapArticles[artc.Slug] = artc
Ei.Articles = append(Ei.Articles, artc)
sort.Sort(Ei.Articles) sort.Sort(Ei.Articles)
GenerateExcerptAndRender(artc) GenerateExcerptAndRender(artc)
// elasticsearch 索引 // elasticsearch 索引
@@ -251,7 +244,6 @@ func apiPostAdd(c *gin.Context) {
AddToLinkedList(artc.ID) AddToLinkedList(artc.ID)
} }
} }
}
} }
func apiSerieDelete(c *gin.Context) { func apiSerieDelete(c *gin.Context) {
+1 -1
View File
@@ -40,7 +40,7 @@ func CheckSerieID(sid string) int32 {
} }
func CheckBool(str string) bool { func CheckBool(str string) bool {
return str == "true" return str == "true" || str == "1"
} }
func CheckPublish(do string) bool { func CheckPublish(do string) bool {
+1 -1
View File
@@ -13,7 +13,7 @@ pagesize: 20
# 自动截取预览, 字符数 # 自动截取预览, 字符数
length: 200 length: 200
# 截取预览标识 # 截取预览标识
identifier: <!-- more --> identifier: <!--more-->
# favicon # favicon
favicon: //st.deepzz.com/static/img/favicon.ico favicon: //st.deepzz.com/static/img/favicon.ico
# 起始ID,预留id不时之需, 不用管 # 起始ID,预留id不时之需, 不用管
+4 -16
View File
@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"regexp" "regexp"
"sort" "sort"
// "strings"
"sync" "sync"
"time" "time"
@@ -262,8 +261,7 @@ func PageList(p, n int) (prev int, next int, artcs []*Article) {
return return
} }
func ManageTagsArticle(artc *Article, s bool, dos ...string) { func ManageTagsArticle(artc *Article, s bool, do string) {
for _, do := range dos {
switch do { switch do {
case ADD: case ADD:
for _, tag := range artc.Tags { for _, tag := range artc.Tags {
@@ -285,14 +283,11 @@ func ManageTagsArticle(artc *Article, s bool, dos ...string) {
} }
} }
} }
}
} }
func ManageSeriesArticle(artc *Article, s bool, dos ...string) { func ManageSeriesArticle(artc *Article, s bool, do string) {
for _, do := range dos {
switch do { switch do {
case ADD: case ADD:
if artc.SerieID != 0 {
for i, serie := range Ei.Series { for i, serie := range Ei.Series {
if serie.ID == artc.SerieID { if serie.ID == artc.SerieID {
Ei.Series[i].Articles = append(Ei.Series[i].Articles, artc) Ei.Series[i].Articles = append(Ei.Series[i].Articles, artc)
@@ -303,9 +298,7 @@ func ManageSeriesArticle(artc *Article, s bool, dos ...string) {
} }
} }
} }
}
case DELETE: case DELETE:
if artc.SerieID != 0 {
for i, serie := range Ei.Series { for i, serie := range Ei.Series {
if serie.ID == artc.SerieID { if serie.ID == artc.SerieID {
for j, v := range serie.Articles { for j, v := range serie.Articles {
@@ -318,13 +311,9 @@ func ManageSeriesArticle(artc *Article, s bool, dos ...string) {
} }
} }
} }
}
}
} }
func ManageArchivesArticle(artc *Article, s bool, dos ...string) { func ManageArchivesArticle(artc *Article, s bool, do string) {
for _, do := range dos {
switch do { switch do {
case ADD: case ADD:
add := false add := false
@@ -358,8 +347,6 @@ func ManageArchivesArticle(artc *Article, s bool, dos ...string) {
} }
} }
} }
}
} }
// 渲染markdown操作和截取摘要操作 // 渲染markdown操作和截取摘要操作
@@ -438,6 +425,7 @@ func DelArticles(ids ...int32) error {
if err != nil { if err != nil {
return err return err
} }
artc = nil
} }
Ei.CH <- ARCHIVE_MD Ei.CH <- ARCHIVE_MD
Ei.CH <- SERIES_MD Ei.CH <- SERIES_MD
+1 -1
View File
@@ -12,7 +12,7 @@ services:
volumes: volumes:
- /data/eiblog/conf/es/config:/usr/share/elasticsearch/config - /data/eiblog/conf/es/config:/usr/share/elasticsearch/config
- /data/eiblog/conf/es/plugins:/usr/share/elasticsearch/plugins - /data/eiblog/conf/es/plugins:/usr/share/elasticsearch/plugins
- /data/eiblog/conf/es/data:/usr/share/elasticsearch/data - /data/eiblog/esdata/data:/usr/share/elasticsearch/data
- /data/eiblog/conf/es/logs:/usr/share/elasticsearch/logs - /data/eiblog/conf/es/logs:/usr/share/elasticsearch/logs
environment: environment:
ES_JAVA_OPTS: "-Xms512m -Xmx512m" ES_JAVA_OPTS: "-Xms512m -Xmx512m"
+2
View File
@@ -132,6 +132,8 @@ func HandleArticlePage(c *gin.Context) {
h["Copyright"] = Ei.Copyright h["Copyright"] = Ei.Copyright
if !artc.UpdateTime.IsZero() { if !artc.UpdateTime.IsZero() {
h["Days"] = int(time.Now().Sub(artc.UpdateTime).Hours()) / 24 h["Days"] = int(time.Now().Sub(artc.UpdateTime).Hours()) / 24
} else {
h["Days"] = int(time.Now().Sub(artc.CreateTime).Hours()) / 24
} }
if artc.SerieID > 0 { if artc.SerieID > 0 {
h["Serie"] = QuerySerie(artc.SerieID) h["Serie"] = QuerySerie(artc.SerieID)
+1 -1
View File
@@ -61,7 +61,7 @@
<td> <td>
<input type="checkbox" value="{{.ID}}" name="cid[]" /> <input type="checkbox" value="{{.ID}}" name="cid[]" />
</td> </td>
<td><a href="/admin/manage-comments?cid={{.ID}}" class="balloon-button size-1">{{.Count}}</a></td> <td><a href="/post/{{.Slug}}.html#comments" class="balloon-button size-1">{{.Count}}</a></td>
<td> <td>
<a href="/admin/write-post?cid={{.ID}}">{{.Title}}</a> <a href="/admin/write-post?cid={{.ID}}">{{.Title}}</a>
<a target="_black" href="/post/{{.Slug}}.html" title="浏览 {{.Title}}"><i class="i-exlink"></i></a> <a target="_black" href="/post/{{.Slug}}.html" title="浏览 {{.Title}}"><i class="i-exlink"></i></a>
+1 -1
View File
@@ -1 +1 @@
{{define "article"}}<div id=content class=inner>{{with .Article}}<article class="post post-{{.ID}}" itemscope itemtype="http://schema.org/Article"><div class=meta><div class=date><time itemprop=datePublished content="{{dateformat .CreateTime " 2006-01-02 "}}">{{dateformat .CreateTime "Jan 02, 2006"}}</time></div><div class=comment><a href="#comments">{{.Count}} Comments</a></div></div><h1 class=title itemprop=headline>{{.Title}}</h1><div class="entry-content" itemprop=articleBody>{{str2html .Content}}<p>本文链接:<a rel="bookmark" title="Permalink to {{.Title}}" href="//{{$.Domain}}/post/{{.Slug}}.html" itemprop="url">https://{{$.Domain}}/post/{{.Slug}}.html</a><a href="//{{$.Domain}}/post/{{.Slug}}.html#comments">参与评论 »</a></p><p>--<acronym title="End of File">EOF</acronym>--</p><p class="post-info">发表于 <span class="date">{{dateformat .CreateTime "2006-01-02 15:04:05"}}</span>{{if gt (.Tags|len) 0}},并被添加「{{range $index, $elem := .Tags}}{{if gt $index 0}}、{{end}}<a href="/search.html?q=tag:{{$elem}}">{{$elem}}</a>{{end}}」标签{{end}}{{if .UpdateTime|isnotzero}},最后修改于 <span class="date">{{dateformat .UpdateTime "2006-01-02 15:04:05"}}</span>{{end}}。</p>{{with $.Copyright}}<p class="copyright-info">{{str2html $.Copyright}}<a href="//{{$.Domain}}/post/about.html#toc-1">更多说明 »</a></p>{{end}} {{with $.Serie}}{{if gt $.Days 100}}<p class="expire-tips">提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。</p>{{end}}<div class="entry-series"><h3>专题「{{.Name}}」的其它文章 <a href="/series.html#toc-{{.ID}}" title="更多">»</a></h3><ul>{{range .Articles}}{{if ne .ID $.Article.ID}}<li><a href="/post/{{.Slug}}.html">{{.Title}}</a> <span class="date">({{dateformat .CreateTime "Jan 02, 2006"}})</span></li>{{end}}{{end}}</ul></div>{{end}}</div></article><nav class="page-navi">{{with .Prev}}<a href="/post/{{.Slug}}.html" class=prev>« {{.Title}}</a>{{end}}{{with .Next}}<a href="/post/{{.Slug}}.html" class=next>{{.Title}} »</a>{{end}}</nav><section id=comments><h1 class=title>Comments<span id=switch_thread_mode></h1><div id=disqus_thread class=ds-thread data-identifier="post-{{.Slug}}" data-url="https://{{$.Domain}}/post/{{.Slug}}.html"></div><div id=simple_thread data-id="{{.Slug}}"></div></section>{{end}}</div>{{end}} {{define "article"}}<div id=content class=inner>{{with .Article}}<article class="post post-{{.ID}}" itemscope itemtype="http://schema.org/Article"><div class=meta><div class=date><time itemprop=datePublished content="{{dateformat .CreateTime " 2006-01-02 "}}">{{dateformat .CreateTime "Jan 02, 2006"}}</time></div><div class=comment><a href="#comments">{{.Count}} Comments</a></div></div><h1 class=title itemprop=headline>{{.Title}}</h1><div class="entry-content" itemprop=articleBody>{{str2html .Content}}<p>本文链接:<a rel="bookmark" title="Permalink to {{.Title}}" href="//{{$.Domain}}/post/{{.Slug}}.html" itemprop="url">https://{{$.Domain}}/post/{{.Slug}}.html</a><a href="//{{$.Domain}}/post/{{.Slug}}.html#comments">参与评论 »</a></p><p>--<acronym title="End of File">EOF</acronym>--</p><p class="post-info">发表于 <span class="date">{{dateformat .CreateTime "2006-01-02 15:04:05"}}</span>{{if gt (.Tags|len) 0}},并被添加「{{range $index, $elem := .Tags}}{{if gt $index 0}}、{{end}}<a href="/search.html?q=tag:{{$elem}}">{{$elem}}</a>{{end}}」标签{{end}}{{if .UpdateTime|isnotzero}},最后修改于 <span class="date">{{dateformat .UpdateTime "2006-01-02 15:04:05"}}</span>{{end}}。</p>{{with $.Copyright}}<p class="copyright-info">{{str2html $.Copyright}}<a href="//{{$.Domain}}/post/about.html#toc-1">更多说明 »</a></p>{{end}}{{if gt $.Days 100}}<p class="expire-tips">提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。</p>{{end}}{{with $.Serie}}<div class="entry-series"><h3>专题「{{.Name}}」的其它文章 <a href="/series.html#toc-{{.ID}}" title="更多">»</a></h3><ul>{{range .Articles}}{{if ne .ID $.Article.ID}}<li><a href="/post/{{.Slug}}.html">{{.Title}}</a> <span class="date">({{dateformat .CreateTime "Jan 02, 2006"}})</span></li>{{end}}{{end}}</ul></div>{{end}}</div></article><nav class="page-navi">{{with .Prev}}<a href="/post/{{.Slug}}.html" class=prev>« {{.Title}}</a>{{end}}{{with .Next}}<a href="/post/{{.Slug}}.html" class=next>{{.Title}} »</a>{{end}}</nav><section id=comments><h1 class=title>Comments<span id=switch_thread_mode></h1><div id=disqus_thread class=ds-thread data-identifier="post-{{.Slug}}" data-url="https://{{$.Domain}}/post/{{.Slug}}.html"></div><div id=simple_thread data-id="{{.Slug}}"></div></section>{{end}}</div>{{end}}