mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-08 15:52:25 +08:00
update
This commit is contained in:
110
api.go
110
api.go
@@ -152,12 +152,12 @@ func apiPostAdd(c *gin.Context) {
|
||||
var cid int
|
||||
defer func() {
|
||||
if !publish {
|
||||
// {"success":1,"time":"10:40:46 AM","cid":"4"}
|
||||
if err == nil {
|
||||
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
return
|
||||
} else {
|
||||
logd.Error(err)
|
||||
c.JSON(http.StatusOK, gin.H{"fail": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
||||
}
|
||||
logd.Error(err)
|
||||
}
|
||||
if err == nil {
|
||||
c.Redirect(http.StatusFound, "/admin/manage-posts")
|
||||
@@ -183,17 +183,18 @@ func apiPostAdd(c *gin.Context) {
|
||||
t := CheckDate(date)
|
||||
serieid := CheckSerieID(serie)
|
||||
publish = CheckPublish(do)
|
||||
if cid, err = strconv.Atoi(c.PostForm("cid")); err != nil || cid < 1 {
|
||||
artc := &Article{
|
||||
Title: title,
|
||||
Content: text,
|
||||
Slug: slug,
|
||||
CreateTime: t,
|
||||
IsDraft: !publish,
|
||||
Author: Ei.Username,
|
||||
SerieID: serieid,
|
||||
Tags: tags,
|
||||
}
|
||||
artc := &Article{
|
||||
Title: title,
|
||||
Content: text,
|
||||
Slug: slug,
|
||||
CreateTime: t,
|
||||
IsDraft: !publish,
|
||||
Author: Ei.Username,
|
||||
SerieID: serieid,
|
||||
Tags: tags,
|
||||
}
|
||||
cid, err = strconv.Atoi(c.PostForm("cid"))
|
||||
if err != nil || cid < 1 {
|
||||
err = AddArticle(artc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
@@ -203,53 +204,44 @@ func apiPostAdd(c *gin.Context) {
|
||||
if publish {
|
||||
ElasticIndex(artc)
|
||||
}
|
||||
} else {
|
||||
artc := QueryArticle(int32(cid))
|
||||
if artc == nil {
|
||||
err = errors.New("没有发现该文章")
|
||||
return
|
||||
}
|
||||
if publish {
|
||||
if Ei.MapArticles[artc.Slug] != nil {
|
||||
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
|
||||
return
|
||||
}
|
||||
artc.ID = int32(cid)
|
||||
if CheckBool(c.PostForm("update")) {
|
||||
artc.UpdateTime = time.Now()
|
||||
artc.SerieID = serieid
|
||||
artc.Tags = tags
|
||||
err = UpdateArticle(bson.M{"id": artc.ID}, artc)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
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)
|
||||
if err != nil {
|
||||
logd.Error(err)
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
if publish {
|
||||
sort.Sort(Ei.Articles)
|
||||
GenerateExcerptAndRender(artc)
|
||||
// elasticsearch 索引
|
||||
ElasticIndex(artc)
|
||||
if artc.ID >= setting.Conf.StartID {
|
||||
ManageTagsArticle(artc, true, ADD)
|
||||
ManageSeriesArticle(artc, true, ADD)
|
||||
ManageArchivesArticle(artc, true, ADD)
|
||||
AddToLinkedList(artc.ID)
|
||||
}
|
||||
Ei.MapArticles[artc.Slug] = artc
|
||||
Ei.Articles = append(Ei.Articles, artc)
|
||||
sort.Sort(Ei.Articles)
|
||||
GenerateExcerptAndRender(artc)
|
||||
// elasticsearch 索引
|
||||
ElasticIndex(artc)
|
||||
if artc.ID >= setting.Conf.StartID {
|
||||
ManageTagsArticle(artc, true, ADD)
|
||||
ManageSeriesArticle(artc, true, ADD)
|
||||
ManageArchivesArticle(artc, true, ADD)
|
||||
AddToLinkedList(artc.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
check.go
2
check.go
@@ -40,7 +40,7 @@ func CheckSerieID(sid string) int32 {
|
||||
}
|
||||
|
||||
func CheckBool(str string) bool {
|
||||
return str == "true"
|
||||
return str == "true" || str == "1"
|
||||
}
|
||||
|
||||
func CheckPublish(do string) bool {
|
||||
|
||||
@@ -13,7 +13,7 @@ pagesize: 20
|
||||
# 自动截取预览, 字符数
|
||||
length: 200
|
||||
# 截取预览标识
|
||||
identifier: <!-- more -->
|
||||
identifier: <!--more-->
|
||||
# favicon
|
||||
favicon: //st.deepzz.com/static/img/favicon.ico
|
||||
# 起始ID,预留id不时之需, 不用管
|
||||
|
||||
146
db.go
146
db.go
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
// "strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -262,24 +261,50 @@ func PageList(p, n int) (prev int, next int, artcs []*Article) {
|
||||
return
|
||||
}
|
||||
|
||||
func ManageTagsArticle(artc *Article, s bool, dos ...string) {
|
||||
for _, do := range dos {
|
||||
switch do {
|
||||
case ADD:
|
||||
for _, tag := range artc.Tags {
|
||||
Ei.Tags[tag] = append(Ei.Tags[tag], artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Tags[tag])
|
||||
func ManageTagsArticle(artc *Article, s bool, do string) {
|
||||
switch do {
|
||||
case ADD:
|
||||
for _, tag := range artc.Tags {
|
||||
Ei.Tags[tag] = append(Ei.Tags[tag], artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Tags[tag])
|
||||
}
|
||||
}
|
||||
case DELETE:
|
||||
for _, tag := range artc.Tags {
|
||||
for i, v := range Ei.Tags[tag] {
|
||||
if v == artc {
|
||||
Ei.Tags[tag] = append(Ei.Tags[tag][0:i], Ei.Tags[tag][i+1:]...)
|
||||
if len(Ei.Tags[tag]) == 0 {
|
||||
delete(Ei.Tags, tag)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
case DELETE:
|
||||
for _, tag := range artc.Tags {
|
||||
for i, v := range Ei.Tags[tag] {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ManageSeriesArticle(artc *Article, s bool, do string) {
|
||||
switch do {
|
||||
case ADD:
|
||||
for i, serie := range Ei.Series {
|
||||
if serie.ID == artc.SerieID {
|
||||
Ei.Series[i].Articles = append(Ei.Series[i].Articles, artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Series[i].Articles)
|
||||
Ei.CH <- SERIES_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
case DELETE:
|
||||
for i, serie := range Ei.Series {
|
||||
if serie.ID == artc.SerieID {
|
||||
for j, v := range serie.Articles {
|
||||
if v == artc {
|
||||
Ei.Tags[tag] = append(Ei.Tags[tag][0:i], Ei.Tags[tag][i+1:]...)
|
||||
if len(Ei.Tags[tag]) == 0 {
|
||||
delete(Ei.Tags, tag)
|
||||
}
|
||||
Ei.Series[i].Articles = append(Ei.Series[i].Articles[0:j], Ei.Series[i].Articles[j+1:]...)
|
||||
Ei.CH <- SERIES_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -288,78 +313,40 @@ func ManageTagsArticle(artc *Article, s bool, dos ...string) {
|
||||
}
|
||||
}
|
||||
|
||||
func ManageSeriesArticle(artc *Article, s bool, dos ...string) {
|
||||
for _, do := range dos {
|
||||
switch do {
|
||||
case ADD:
|
||||
if artc.SerieID != 0 {
|
||||
for i, serie := range Ei.Series {
|
||||
if serie.ID == artc.SerieID {
|
||||
Ei.Series[i].Articles = append(Ei.Series[i].Articles, artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Series[i].Articles)
|
||||
Ei.CH <- SERIES_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case DELETE:
|
||||
if artc.SerieID != 0 {
|
||||
for i, serie := range Ei.Series {
|
||||
if serie.ID == artc.SerieID {
|
||||
for j, v := range serie.Articles {
|
||||
if v == artc {
|
||||
Ei.Series[i].Articles = append(Ei.Series[i].Articles[0:j], Ei.Series[i].Articles[j+1:]...)
|
||||
Ei.CH <- SERIES_MD
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
func ManageArchivesArticle(artc *Article, s bool, do string) {
|
||||
switch do {
|
||||
case ADD:
|
||||
add := false
|
||||
y, m, _ := artc.CreateTime.Date()
|
||||
for i, archive := range Ei.Archives {
|
||||
ay, am, _ := archive.Time.Date()
|
||||
if y == ay && m == am {
|
||||
add = true
|
||||
Ei.Archives[i].Articles = append(Ei.Archives[i].Articles, artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Archives[i].Articles)
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func ManageArchivesArticle(artc *Article, s bool, dos ...string) {
|
||||
for _, do := range dos {
|
||||
switch do {
|
||||
case ADD:
|
||||
add := false
|
||||
y, m, _ := artc.CreateTime.Date()
|
||||
for i, archive := range Ei.Archives {
|
||||
ay, am, _ := archive.Time.Date()
|
||||
if y == ay && m == am {
|
||||
add = true
|
||||
Ei.Archives[i].Articles = append(Ei.Archives[i].Articles, artc)
|
||||
if s {
|
||||
sort.Sort(Ei.Archives[i].Articles)
|
||||
if !add {
|
||||
Ei.Archives = append(Ei.Archives, &Archive{Time: artc.CreateTime, Articles: SortArticles{artc}})
|
||||
}
|
||||
case DELETE:
|
||||
for i, archive := range Ei.Archives {
|
||||
ay, am, _ := archive.Time.Date()
|
||||
if y, m, _ := artc.CreateTime.Date(); ay == y && am == m {
|
||||
for j, v := range archive.Articles {
|
||||
if v == artc {
|
||||
Ei.Archives[i].Articles = append(Ei.Archives[i].Articles[0:j], Ei.Archives[i].Articles[j+1:]...)
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !add {
|
||||
Ei.Archives = append(Ei.Archives, &Archive{Time: artc.CreateTime, Articles: SortArticles{artc}})
|
||||
}
|
||||
case DELETE:
|
||||
for i, archive := range Ei.Archives {
|
||||
ay, am, _ := archive.Time.Date()
|
||||
if y, m, _ := artc.CreateTime.Date(); ay == y && am == m {
|
||||
for j, v := range archive.Articles {
|
||||
if v == artc {
|
||||
Ei.Archives[i].Articles = append(Ei.Archives[i].Articles[0:j], Ei.Archives[i].Articles[j+1:]...)
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 渲染markdown操作和截取摘要操作
|
||||
@@ -438,6 +425,7 @@ func DelArticles(ids ...int32) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
artc = nil
|
||||
}
|
||||
Ei.CH <- ARCHIVE_MD
|
||||
Ei.CH <- SERIES_MD
|
||||
|
||||
@@ -12,7 +12,7 @@ services:
|
||||
volumes:
|
||||
- /data/eiblog/conf/es/config:/usr/share/elasticsearch/config
|
||||
- /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
|
||||
environment:
|
||||
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
|
||||
|
||||
2
front.go
2
front.go
@@ -132,6 +132,8 @@ func HandleArticlePage(c *gin.Context) {
|
||||
h["Copyright"] = Ei.Copyright
|
||||
if !artc.UpdateTime.IsZero() {
|
||||
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 {
|
||||
h["Serie"] = QuerySerie(artc.SerieID)
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<td>
|
||||
<input type="checkbox" value="{{.ID}}" name="cid[]" />
|
||||
</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>
|
||||
<a href="/admin/write-post?cid={{.ID}}">{{.Title}}</a>
|
||||
<a target="_black" href="/post/{{.Slug}}.html" title="浏览 {{.Title}}"><i class="i-exlink"></i></a>
|
||||
|
||||
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user