update config

This commit is contained in:
deepzz0
2017-06-24 19:21:53 +08:00
parent 11b0f486cd
commit 055c2307cb
9 changed files with 88 additions and 87 deletions

2
api.go
View File

@@ -258,7 +258,7 @@ func apiPostAdd(c *gin.Context) {
// elasticsearch 索引
ElasticIndex(artc)
DoPings(slug)
if artc.ID >= setting.Conf.StartID {
if artc.ID >= setting.Conf.General.StartID {
ManageTagsArticle(artc, true, ADD)
ManageSeriesArticle(artc, true, ADD)
ManageArchivesArticle(artc, true, ADD)

View File

@@ -154,7 +154,7 @@ func HandlePosts(c *gin.Context) {
h["Serie"] = se
h["KW"] = kw
var max int
max, h["List"] = PageListBack(se, kw, false, false, pg, setting.Conf.PageSize)
max, h["List"] = PageListBack(se, kw, false, false, pg, setting.Conf.General.PageSize)
if pg < max {
vals.Set("page", fmt.Sprint(pg+1))
h["Next"] = vals.Encode()

View File

@@ -1,23 +1,38 @@
# 运行模式 dev or prod
runmode: dev
# 回收箱保留48小时
trash: -48
# 定时清理回收箱,%d小时
clean: 1
# 首页展示文章数量
pagenum: 10
# 管理界面
pagesize: 20
# 自动截取预览, 字符数
length: 400
# 截取预览标识
identifier: <!--more-->
# 文章描述前缀
description: "Desc:"
# 起始ID预留id不时之需, 不用管
startid: 11
# elasticsearch url
searchurl: http://elasticsearch:9200
# 静态文件版本
staticversion: 1
# superfeedr url
feedrurl: https://deepzz.superfeedr.com/
# 热搜词配置
hotwords:
- docker
- mongodb
- curl
- dns
# ping rpcs 地址
pingrpcs:
- http://ping.baidu.com/ping/RPC2
- http://blogsearch.google.com/ping/RPC2
- http://rpc.pingomatic.com/
# 一般配置
general:
# 首页展示文章数量
pagenum: 10
# 管理界面
pagesize: 20
# 起始ID预留id不时之需, 不用管
startid: 11
# 文章描述前缀
descprefix: "Desc:"
# 截取预览标识
identifier: <!--more-->
# 自动截取预览, 字符数
length: 400
# 回收箱保留48小时
trash: -48
# 定时清理回收箱,每 %d 小时
clean: 1
# 评论相关
disqus:
shortname: deepzz
@@ -26,16 +41,11 @@ disqus:
postslist: https://disqus.com/api/3.0/threads/listPosts.json
postcreate: https://disqus.com/api/3.0/posts/create.json
interval: 5
# 热搜词配置
hotwords:
- docker
# 谷歌统计
google:
tid: UA-77251712-1
v: "1"
t: pageview
# 静态文件版本
staticversion: 1
# 七牛CDN
kodo:
name: eiblog
@@ -44,7 +54,6 @@ kodo:
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
# 运行模式
mode:
# 默认开启HTTP
enablehttp: true
httpport: 9000
enablehttps: false
@@ -58,13 +67,6 @@ twitter:
site: chenqijing2
image: st.deepzz.com/static/img/avatar.jpg
address: twitter.com/chenqijing2
# superfeedr url
feedrurl: https://deepzz.superfeedr.com/
# ping rpcs 地址
pingrpcs:
- http://ping.baidu.com/ping/RPC2
- http://blogsearch.google.com/ping/RPC2
- http://rpc.pingomatic.com/
# 以下数据项供初始化使用,仅首次运行有效。
# 若需要修改,请到博客后台操作。

24
db.go
View File

@@ -149,13 +149,13 @@ func loadArticles() (artcs SortArticles) {
GenerateExcerptAndRender(v)
Ei.MapArticles[v.Slug] = v
// 分析文章
if v.ID < setting.Conf.StartID {
if v.ID < setting.Conf.General.StartID {
continue
}
if i > 0 {
v.Prev = artcs[i-1]
}
if artcs[i+1].ID >= setting.Conf.StartID {
if artcs[i+1].ID >= setting.Conf.General.StartID {
v.Next = artcs[i+1]
}
ManageTagsArticle(v, false, ADD)
@@ -244,7 +244,7 @@ func renderPage(md []byte) []byte {
func PageList(p, n int) (prev int, next int, artcs []*Article) {
var l int
for l = len(Ei.Articles); l > 0; l-- {
if Ei.Articles[l-1].ID >= setting.Conf.StartID {
if Ei.Articles[l-1].ID >= setting.Conf.General.StartID {
break
}
}
@@ -362,15 +362,15 @@ func ManageArchivesArticle(artc *Article, s bool, do string) {
}
// 渲染markdown操作和截取摘要操作
var reg = regexp.MustCompile(setting.Conf.Identifier)
var reg = regexp.MustCompile(setting.Conf.General.Identifier)
// header
var regH = regexp.MustCompile("</nav></div>")
func GenerateExcerptAndRender(artc *Article) {
if strings.HasPrefix(artc.Content, setting.Conf.Description) {
if strings.HasPrefix(artc.Content, setting.Conf.General.DescPrefix) {
index := strings.Index(artc.Content, "\r\n")
artc.Desc = IgnoreHtmlTag(artc.Content[len(setting.Conf.Description):index])
artc.Desc = IgnoreHtmlTag(artc.Content[len(setting.Conf.General.DescPrefix):index])
artc.Content = artc.Content[index:]
}
@@ -387,7 +387,7 @@ func GenerateExcerptAndRender(artc *Article) {
artc.Excerpt = IgnoreHtmlTag(artc.Content[0:index[0]])
} else {
uc := []rune(artc.Content)
length := setting.Conf.Length
length := setting.Conf.General.Length
if len(uc) < length {
length = len(uc)
}
@@ -413,7 +413,7 @@ func LoadTrash() (artcs SortArticles, err error) {
func AddArticle(artc *Article) error {
// 分配ID, 占位至起始id
for {
if id := db.NextVal(DB, COUNTER_ARTICLE); id < setting.Conf.StartID {
if id := db.NextVal(DB, COUNTER_ARTICLE); id < setting.Conf.General.StartID {
continue
} else {
artc.ID = id
@@ -473,10 +473,10 @@ func DelFromLinkedList(artc *Article) {
func AddToLinkedList(id int32) {
i, artc := GetArticle(id)
if i == 0 && Ei.Articles[i+1].ID >= setting.Conf.StartID {
if i == 0 && Ei.Articles[i+1].ID >= setting.Conf.General.StartID {
artc.Next = Ei.Articles[i+1]
Ei.Articles[i+1].Prev = artc
} else if i > 0 && Ei.Articles[i-1].ID >= setting.Conf.StartID {
} else if i > 0 && Ei.Articles[i-1].ID >= setting.Conf.General.StartID {
artc.Prev = Ei.Articles[i-1]
if Ei.Articles[i-1].Next != nil {
artc.Next = Ei.Articles[i-1].Next
@@ -498,10 +498,10 @@ func GetArticle(id int32) (int, *Article) {
// 定时清除回收箱文章
func timer() {
delT := time.NewTicker(time.Duration(setting.Conf.Clean) * time.Hour)
delT := time.NewTicker(time.Duration(setting.Conf.General.Clean) * time.Hour)
for {
<-delT.C
db.Remove(DB, COLLECTION_ARTICLE, bson.M{"deletetime": bson.M{"$gt": time.Time{}, "$lt": time.Now().Add(time.Duration(setting.Conf.Trash) * time.Hour)}})
db.Remove(DB, COLLECTION_ARTICLE, bson.M{"deletetime": bson.M{"$gt": time.Time{}, "$lt": time.Now().Add(time.Duration(setting.Conf.General.Trash) * time.Hour)}})
}
}

View File

@@ -32,7 +32,6 @@ func PostsCount() {
"&forum=" + setting.Conf.Disqus.ShortName + "&"
var count, index int
for index < len(Ei.Articles) {
logd.Debugf("count=====%d, index=======%d, length=======%d, bool=========%t\n", count, index, len(Ei.Articles), index < len(Ei.Articles) && count < 50)
var threads []string
for ; index < len(Ei.Articles) && count < 50; index++ {
artc := Ei.Articles[index]

View File

@@ -11,7 +11,6 @@ import (
"strings"
"time"
"github.com/eiblog/eiblog/setting"
"github.com/eiblog/utils/logd"
)
@@ -27,7 +26,7 @@ const (
var es *ElasticService
func init() {
es = &ElasticService{url: setting.Conf.SearchURL, c: new(http.Client)}
es = &ElasticService{url: "http://elasticsearch:9200", c: new(http.Client)}
initIndex()
}

View File

@@ -55,7 +55,6 @@ func StaticVersion(c *gin.Context) (version int) {
func GetBase() gin.H {
return gin.H{
"Favicon": setting.Conf.Favicon,
"BlogName": Ei.BlogName,
"SubTitle": Ei.SubTitle,
"Twitter": setting.Conf.Twitter,
@@ -88,7 +87,7 @@ func HandleHomePage(c *gin.Context) {
if err != nil || pn < 1 {
pn = 1
}
h["Prev"], h["Next"], h["List"] = PageList(pn, setting.Conf.PageNum)
h["Prev"], h["Next"], h["List"] = PageList(pn, setting.Conf.General.PageNum)
c.Status(http.StatusOK)
RenderHTMLFront(c, "home", h)
}
@@ -171,7 +170,7 @@ func HandleSearchPage(c *gin.Context) {
h["Word"] = q
var result *ESSearchResult
vals := c.Request.URL.Query()
result = Elasticsearch(q, setting.Conf.PageNum, start-1)
result = Elasticsearch(q, setting.Conf.General.PageNum, start-1)
if result != nil {
result.Took /= 1000
for i, v := range result.Hits.Hits {
@@ -180,12 +179,12 @@ func HandleSearchPage(c *gin.Context) {
}
}
h["SearchResult"] = result
if start-setting.Conf.PageNum > 0 {
vals.Set("start", fmt.Sprint(start-setting.Conf.PageNum))
if start-setting.Conf.General.PageNum > 0 {
vals.Set("start", fmt.Sprint(start-setting.Conf.General.PageNum))
h["Prev"] = vals.Encode()
}
if result.Hits.Total >= start+setting.Conf.PageNum {
vals.Set("start", fmt.Sprint(start+setting.Conf.PageNum))
if result.Hits.Total >= start+setting.Conf.General.PageNum {
vals.Set("start", fmt.Sprint(start+setting.Conf.General.PageNum))
h["Next"] = vals.Encode()
}
}

View File

@@ -19,19 +19,22 @@ var (
)
type Config struct {
StaticVersion int // 当前静态文件版本
RunMode string // 运行模式
Trash int // 回收箱文章保留时间
Clean int // 清理回收箱频率
PageNum int // 前端每页文章数量
PageSize int // 后台每页文章数量
Length int // 自动截取预览长度
Identifier string // 截取标示
Description string // 文章描述前缀
Favicon string // icon地址
StartID int32 // 文章起始id
SearchURL string // elasticsearch 地址
Disqus struct { // 获取文章数量相关
StaticVersion int // 当前静态文件版本
FeedrURL string // superfeedr url
HotWords []string // 热搜词
PingRPCs []string // ping rpc 地址
General struct {
PageNum int // 前端每页文章数量
PageSize int // 后台每页文章数量
StartID int32 // 文章起始id
DescPrefix string // 文章描述前缀
Identifier string // 文章截取标示
Length int // 文章自动截取预览长度
Trash int // 回收箱文章保留时间
Clean int // 清理回收箱频率
}
Disqus struct { // 获取文章数量相关
ShortName string
PublicKey string
PostsCount string
@@ -39,8 +42,7 @@ type Config struct {
PostCreate string
Interval int
}
HotWords []string // 热搜词
Google struct { // 谷歌统计
Google struct { // 谷歌统计
Tid string
V string
T string
@@ -51,23 +53,29 @@ type Config struct {
AccessKey string
SecretKey string
}
Mode RunMode // 运行模式
Mode struct { // 运行模式
EnableHttp bool
HttpPort int
EnableHttps bool
HttpsPort int
CertFile string
KeyFile string
Domain string
}
Twitter struct { // twitter信息
Card string
Site string
Image string
Address string
}
FeedrURL string // superfeedr url
PingRPCs []string // ping rpc 地址
Account struct {
Account struct { // account 账户
Username string // *
Password string // *
Email string
PhoneNumber string
Address string
}
Blogger struct { // 初始化数据
Blogger struct { // blog info 博客信息
BlogName string
SubTitle string
BeiAn string
@@ -76,16 +84,6 @@ type Config struct {
}
}
type RunMode struct {
EnableHttp bool
HttpPort int
EnableHttps bool
HttpsPort int
CertFile string
KeyFile string
Domain string
}
func init() {
// 初始化配置
data, err := ioutil.ReadFile("conf/app.yml")

View File

@@ -2,11 +2,15 @@
package setting
import (
"fmt"
"encoding/json"
"testing"
)
func TestInit(t *testing.T) {
init()
fmt.Printf("%v\n", *Conf)
data, err := json.Marshal(Conf)
if err != nil {
t.Fatal(err)
}
t.Log(string(data))
}