Skip to content

Commit dcbc059

Browse files
committed
Ready for use
1 parent 2f8ec10 commit dcbc059

20 files changed

+608
-235
lines changed

bee.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"version": 0,
33
"gopm": {
4-
"enable": true,
4+
"enable": false,
55
"install": true
66
},
7-
"go_install": false,
7+
"go_install": true,
88
"watch_ext": [],
99
"dir_structure": {
1010
"controllers": "",

conf/app.conf

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
appname = Go China Blog
1+
appname = Go China Blog
2+
3+
archives=go_china_spring_cal

content/go_china_spring_cal.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Hello world
2+
3+
hey guys!

controllers/home.go

+5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414

1515
package controllers
1616

17+
import (
18+
"github.com/Unknwon/gcblog/models"
19+
)
20+
1721
type HomeController struct {
1822
baseController
1923
}
2024

2125
func (this *HomeController) Get() {
2226
this.TplNames = "home.html"
27+
this.Data["RecentArchives"] = models.GetRecentPosts()
2328
}

controllers/post.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 gcblog authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations
13+
// under the License.
14+
15+
package controllers
16+
17+
import (
18+
"github.com/Unknwon/gcblog/models"
19+
)
20+
21+
type PostController struct {
22+
baseController
23+
}
24+
25+
func (this *PostController) Get() {
26+
this.TplNames = "home.html"
27+
this.Data["IsSinglePost"] = true
28+
this.Data["RecentArchives"] = models.GetRecentPosts()
29+
arch := models.GetSinglePost(this.Ctx.Request.RequestURI[1:])
30+
if arch == nil {
31+
this.Redirect("/", 302)
32+
return
33+
}
34+
this.Data["SinglePost"] = arch
35+
}

gcblog.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,22 @@ import (
2222
)
2323

2424
const (
25-
APP_VER = "0.0.1.1212"
25+
APP_VER = "0.1.0.1212"
2626
)
2727

2828
func main() {
2929
beego.Info(beego.AppName, APP_VER)
3030

3131
// Register routers.
3232
beego.Router("/", &controllers.HomeController{})
33+
beego.Router("/:all", &controllers.PostController{})
34+
35+
// Register template functions.
36+
beego.AddFuncMap("byte2str", byte2Str)
3337

3438
beego.Run()
3539
}
40+
41+
func byte2Str(data []byte) string {
42+
return string(data)
43+
}

models/models.go

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2013 gcblog authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations
13+
// under the License.
14+
15+
package models
16+
17+
import (
18+
"path"
19+
"strings"
20+
21+
"github.com/Unknwon/com"
22+
"github.com/astaxie/beego"
23+
"github.com/slene/blackfriday"
24+
)
25+
26+
type archive struct {
27+
Name string
28+
Title string
29+
Content []byte
30+
}
31+
32+
var archives []*archive
33+
34+
func init() {
35+
archNames := strings.Split(beego.AppConfig.String("archives"), "|")
36+
archives = make([]*archive, 0, len(archNames))
37+
for _, name := range archNames {
38+
arch := getFile(path.Join("content", name))
39+
if arch == nil {
40+
continue
41+
}
42+
arch.Name = name
43+
archives = append(archives, arch)
44+
}
45+
}
46+
47+
func markdown(raw []byte) (out []byte) {
48+
return blackfriday.MarkdownCommon(raw)
49+
}
50+
51+
func getFile(filePath string) *archive {
52+
df := &archive{}
53+
p, err := com.ReadFile(filePath + ".md")
54+
if err != nil {
55+
beego.Error("models.getFile -> ", err)
56+
return nil
57+
}
58+
59+
// Parse and render.
60+
s := string(p)
61+
i := strings.Index(s, "\n")
62+
if i > -1 {
63+
// Has title.
64+
df.Title = strings.TrimSpace(
65+
strings.Replace(s[:i+1], "#", "", -1))
66+
df.Content = []byte(strings.TrimSpace(s[i+2:]))
67+
} else {
68+
df.Content = p
69+
}
70+
71+
df.Content = markdown(df.Content)
72+
return df
73+
}
74+
75+
func GetRecentPosts() []*archive {
76+
if len(archives) >= 10 {
77+
return archives[:10]
78+
}
79+
return archives
80+
}
81+
82+
func GetSinglePost(name string) *archive {
83+
for _, arch := range archives {
84+
if name == arch.Name {
85+
return arch
86+
}
87+
}
88+
return nil
89+
}

static/css/font-awesome.min.css

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/css/gcblog.css

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
body {
88
padding-top: 70px;
9+
font-size: 15px;
910
}
1011
.navbar-gcblog {
1112
background-color: #2894FF;
@@ -35,4 +36,7 @@ body {
3536
margin-bottom: 10px;
3637
text-align: center;
3738
padding: 10px 5px;
39+
}
40+
.title > a {
41+
color: #8600FF;
3842
}

static/fonts/FontAwesome.otf

61.4 KB
Binary file not shown.

static/fonts/fontawesome-webfont.eot

37.3 KB
Binary file not shown.

static/fonts/fontawesome-webfont.svg

+414
Loading

static/fonts/fontawesome-webfont.ttf

78.8 KB
Binary file not shown.

static/fonts/fontawesome-webfont.woff

43.4 KB
Binary file not shown.
-19.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)