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 索引 // elasticsearch 索引
ElasticIndex(artc) ElasticIndex(artc)
DoPings(slug) DoPings(slug)
if artc.ID >= setting.Conf.StartID { if artc.ID >= setting.Conf.General.StartID {
ManageTagsArticle(artc, true, ADD) ManageTagsArticle(artc, true, ADD)
ManageSeriesArticle(artc, true, ADD) ManageSeriesArticle(artc, true, ADD)
ManageArchivesArticle(artc, true, ADD) ManageArchivesArticle(artc, true, ADD)

View File

@@ -154,7 +154,7 @@ func HandlePosts(c *gin.Context) {
h["Serie"] = se h["Serie"] = se
h["KW"] = kw h["KW"] = kw
var max int 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 { if pg < max {
vals.Set("page", fmt.Sprint(pg+1)) vals.Set("page", fmt.Sprint(pg+1))
h["Next"] = vals.Encode() h["Next"] = vals.Encode()

View File

@@ -1,23 +1,38 @@
# 运行模式 dev or prod # 运行模式 dev or prod
runmode: dev runmode: dev
# 回收箱保留48小时 # 静态文件版本
trash: -48 staticversion: 1
# 定时清理回收箱,%d小时 # superfeedr url
clean: 1 feedrurl: https://deepzz.superfeedr.com/
# 首页展示文章数量 # 热搜词配置
pagenum: 10 hotwords:
# 管理界面 - docker
pagesize: 20 - mongodb
# 自动截取预览, 字符数 - curl
length: 400 - dns
# 截取预览标识 # ping rpcs 地址
identifier: <!--more--> pingrpcs:
# 文章描述前缀 - http://ping.baidu.com/ping/RPC2
description: "Desc:" - http://blogsearch.google.com/ping/RPC2
# 起始ID预留id不时之需, 不用管 - http://rpc.pingomatic.com/
startid: 11 # 一般配置
# elasticsearch url general:
searchurl: http://elasticsearch:9200 # 首页展示文章数量
pagenum: 10
# 管理界面
pagesize: 20
# 起始ID预留id不时之需, 不用管
startid: 11
# 文章描述前缀
descprefix: "Desc:"
# 截取预览标识
identifier: <!--more-->
# 自动截取预览, 字符数
length: 400
# 回收箱保留48小时
trash: -48
# 定时清理回收箱,每 %d 小时
clean: 1
# 评论相关 # 评论相关
disqus: disqus:
shortname: deepzz shortname: deepzz
@@ -26,16 +41,11 @@ disqus:
postslist: https://disqus.com/api/3.0/threads/listPosts.json postslist: https://disqus.com/api/3.0/threads/listPosts.json
postcreate: https://disqus.com/api/3.0/posts/create.json postcreate: https://disqus.com/api/3.0/posts/create.json
interval: 5 interval: 5
# 热搜词配置
hotwords:
- docker
# 谷歌统计 # 谷歌统计
google: google:
tid: UA-77251712-1 tid: UA-77251712-1
v: "1" v: "1"
t: pageview t: pageview
# 静态文件版本
staticversion: 1
# 七牛CDN # 七牛CDN
kodo: kodo:
name: eiblog name: eiblog
@@ -44,7 +54,6 @@ kodo:
secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf secretkey: BIrMy0fsZ0_SHNceNXk3eDuo7WmVYzj2-zrmd5Tf
# 运行模式 # 运行模式
mode: mode:
# 默认开启HTTP
enablehttp: true enablehttp: true
httpport: 9000 httpport: 9000
enablehttps: false enablehttps: false
@@ -58,13 +67,6 @@ twitter:
site: chenqijing2 site: chenqijing2
image: st.deepzz.com/static/img/avatar.jpg image: st.deepzz.com/static/img/avatar.jpg
address: twitter.com/chenqijing2 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) GenerateExcerptAndRender(v)
Ei.MapArticles[v.Slug] = v Ei.MapArticles[v.Slug] = v
// 分析文章 // 分析文章
if v.ID < setting.Conf.StartID { if v.ID < setting.Conf.General.StartID {
continue continue
} }
if i > 0 { if i > 0 {
v.Prev = artcs[i-1] 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] v.Next = artcs[i+1]
} }
ManageTagsArticle(v, false, ADD) ManageTagsArticle(v, false, ADD)
@@ -244,7 +244,7 @@ func renderPage(md []byte) []byte {
func PageList(p, n int) (prev int, next int, artcs []*Article) { func PageList(p, n int) (prev int, next int, artcs []*Article) {
var l int var l int
for l = len(Ei.Articles); l > 0; l-- { 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 break
} }
} }
@@ -362,15 +362,15 @@ func ManageArchivesArticle(artc *Article, s bool, do string) {
} }
// 渲染markdown操作和截取摘要操作 // 渲染markdown操作和截取摘要操作
var reg = regexp.MustCompile(setting.Conf.Identifier) var reg = regexp.MustCompile(setting.Conf.General.Identifier)
// header // header
var regH = regexp.MustCompile("</nav></div>") var regH = regexp.MustCompile("</nav></div>")
func GenerateExcerptAndRender(artc *Article) { 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") 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:] artc.Content = artc.Content[index:]
} }
@@ -387,7 +387,7 @@ func GenerateExcerptAndRender(artc *Article) {
artc.Excerpt = IgnoreHtmlTag(artc.Content[0:index[0]]) artc.Excerpt = IgnoreHtmlTag(artc.Content[0:index[0]])
} else { } else {
uc := []rune(artc.Content) uc := []rune(artc.Content)
length := setting.Conf.Length length := setting.Conf.General.Length
if len(uc) < length { if len(uc) < length {
length = len(uc) length = len(uc)
} }
@@ -413,7 +413,7 @@ func LoadTrash() (artcs SortArticles, err error) {
func AddArticle(artc *Article) error { func AddArticle(artc *Article) error {
// 分配ID, 占位至起始id // 分配ID, 占位至起始id
for { 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 continue
} else { } else {
artc.ID = id artc.ID = id
@@ -473,10 +473,10 @@ func DelFromLinkedList(artc *Article) {
func AddToLinkedList(id int32) { func AddToLinkedList(id int32) {
i, artc := GetArticle(id) 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] artc.Next = Ei.Articles[i+1]
Ei.Articles[i+1].Prev = artc 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] artc.Prev = Ei.Articles[i-1]
if Ei.Articles[i-1].Next != nil { if Ei.Articles[i-1].Next != nil {
artc.Next = Ei.Articles[i-1].Next artc.Next = Ei.Articles[i-1].Next
@@ -498,10 +498,10 @@ func GetArticle(id int32) (int, *Article) {
// 定时清除回收箱文章 // 定时清除回收箱文章
func timer() { func timer() {
delT := time.NewTicker(time.Duration(setting.Conf.Clean) * time.Hour) delT := time.NewTicker(time.Duration(setting.Conf.General.Clean) * time.Hour)
for { for {
<-delT.C <-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 + "&" "&forum=" + setting.Conf.Disqus.ShortName + "&"
var count, index int var count, index int
for index < len(Ei.Articles) { 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 var threads []string
for ; index < len(Ei.Articles) && count < 50; index++ { for ; index < len(Ei.Articles) && count < 50; index++ {
artc := Ei.Articles[index] artc := Ei.Articles[index]

View File

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

View File

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

View File

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

View File

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