Skip to content

Commit

Permalink
Merge pull request #7 from fuxiaohei/develop
Browse files Browse the repository at this point in the history
update to 0.1.6
  • Loading branch information
fuxiaohei committed Jan 27, 2014
2 parents a55a21f + e9b9dd4 commit 6ff0f62
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A fast and simple blog engine with GoInk framework in Golang.

Current version is **0.1.5-beta** on 2014.01.30
Current version is **0.1.6-beta** on 2014.01.31

### Overview

Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

var (
VERSION = 20140130
VERSION = 20140131
App *GoInk.App
staticFileSuffix = ".css,.js,.jpg,.jpeg,.png,.gif,.ico,.xml,.zip,.txt,.html,.otf,.svg,.eot,.woff,.ttf,.doc,.ppt,.xls,.docx,.pptx,.xlsx"
uploadFileSuffix = ".jpg,.png,.gif,.zip,.txt,.doc,.docx,.xls,.xlsx,.ppt,.pptx"
Expand Down
2 changes: 1 addition & 1 deletion app/cmd/zip.go

Large diffs are not rendered by default.

57 changes: 29 additions & 28 deletions app/model/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ func (cnt *Content) TagString() string {
// get content link.
func (cnt *Content) Link() string {
if cnt.IsLinked {
return "/"+cnt.Slug + ".html"
return "/" + cnt.Slug + ".html"
}
return fmt.Sprintf("/%s/%d/%s.html", cnt.Type, cnt.Id, cnt.Slug)
}

// get content text.
func (cnt *Content) Content() string {
txt := strings.Replace(cnt.Text, "<!--more-->", "", -1)
if GetSetting("enable_go_markdown") == "true" {
return utils.Markdown2Html(cnt.Text)
return utils.Markdown2Html(txt)
}
return cnt.Text
return txt
}

// get content summary.
Expand Down Expand Up @@ -211,40 +212,40 @@ func LoadContents() {
articleIndex := make([]int, 0)
pageIndex := make([]int, 0)
filepath.Walk(filepath.Join(Storage.dir, "content"), func(_ string, info os.FileInfo, err error) error {
if err == nil {
if info.IsDir() {
return nil
}
c := new(Content)
file := strings.Replace("content/" + info.Name(), filepath.Ext(info.Name()), "", -1)
Storage.Get(file, c)
if c.Id > 0 {
if c.Status != "DELETE" {
contents[c.Id] = c
if c.Type == "article" {
articleIndex = append(articleIndex, c.Id)
}
if c.Type == "page" {
pageIndex = append(pageIndex, c.Id)
}
if err == nil {
if info.IsDir() {
return nil
}
c := new(Content)
file := strings.Replace("content/"+info.Name(), filepath.Ext(info.Name()), "", -1)
Storage.Get(file, c)
if c.Id > 0 {
if c.Status != "DELETE" {
contents[c.Id] = c
if c.Type == "article" {
articleIndex = append(articleIndex, c.Id)
}
if c.Id > contentMaxId {
contentMaxId = c.Id
if c.Type == "page" {
pageIndex = append(pageIndex, c.Id)
}
}
if c.Id > contentMaxId {
contentMaxId = c.Id
}
}
return nil
})
}
return nil
})
sort.Sort(sort.Reverse(sort.IntSlice(articleIndex)))
sort.Sort(sort.Reverse(sort.IntSlice(pageIndex)))
contentsIndex["article"] = articleIndex
contentsIndex["page"] = pageIndex
}

func StartContentsTimer() {
time.AfterFunc(time.Duration(10) * time.Minute, func() {
println("write contents in 10 min timer")
SyncContents()
StartContentsTimer()
})
time.AfterFunc(time.Duration(10)*time.Minute, func() {
println("write contents in 10 min timer")
SyncContents()
StartContentsTimer()
})
}
9 changes: 9 additions & 0 deletions app/model/locker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

import "sync"

var locker sync.Mutex

func init(){
locker = sync.Mutex{}
}
13 changes: 10 additions & 3 deletions app/model/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

var (
appVersion int
Storage *jsonStorage
Storage *jsonStorage
)

type jsonStorage struct {
Expand Down Expand Up @@ -48,7 +48,10 @@ func (jss *jsonStorage) Get(key string, v interface{}) {
}

func (jss *jsonStorage) Set(key string, v interface{}) {
bytes, e := json.MarshalIndent(v, "", " ")
locker.Lock()
defer locker.Unlock()

bytes, e := json.Marshal(v)
if e != nil {
println("json encode '" + key + "' error")
return
Expand All @@ -60,6 +63,10 @@ func (jss *jsonStorage) Set(key string, v interface{}) {
}
}

func (jss *jsonStorage) Dir(name string) {
os.MkdirAll(path.Join(jss.dir, name), os.ModePerm)
}

func writeDefaultData() {
// write user
u := new(User)
Expand Down Expand Up @@ -207,7 +214,7 @@ func Init(v int) {
Storage.Init("data")
}

func All(){
func All() {
loadAllData()
StartContentsTimer()
}
2 changes: 2 additions & 0 deletions app/upgrade/v20140130.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ func upgrade_20140130(app *GoInk.App) bool {
model.SetSetting("enable_go_markdown_def", "false")
model.SetSetting("site_theme", "default")
model.SetSetting("site_theme_def", "default")
model.SetSetting("c_home_avatar","/static/img/site.png")
model.SyncSettings()

// init plugin
plugin.Init()
model.Storage.Dir("plugin")

// remove static files
os.RemoveAll(app.Get("view_dir"))
Expand Down
32 changes: 32 additions & 0 deletions app/upgrade/v20140131.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package upgrade

import (
"github.com/fuxiaohei/GoBlog/GoInk"
"github.com/fuxiaohei/GoBlog/app/cmd"
"os"
"path"
)

func init() {
cmd.SetUpgradeScript(20140131, upgrade_20140131)
}

func upgrade_20140131(app *GoInk.App) bool {

// re-write all data to non-indent json
/*model.All()
model.SyncContents()
model.SyncFiles()
model.SyncReaders()
model.SyncSettings()
model.SyncTokens()
model.SyncUsers()
model.SyncVersion()*/

// update ling template
os.RemoveAll(path.Join(app.Get("view_dir"), "ling"))
cmd.ExtractBundleBytes()


return true
}
Loading

0 comments on commit 6ff0f62

Please sign in to comment.