Skip to content

Commit

Permalink
更换css为熟悉的Bootstrap,定义站定名称变量,调整markdown渲染样式
Browse files Browse the repository at this point in the history
  • Loading branch information
lixu committed Nov 27, 2019
1 parent 308f7d1 commit 67f934e
Show file tree
Hide file tree
Showing 31 changed files with 25,691 additions and 125 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*.dll
*.so
*.dylib

gitmdblog
logs/*
# Test binary, build with `go test -c`
*.test

Expand Down
Binary file removed config/.config.go.swp
Binary file not shown.
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package config

// ---------------- 定义变量 ----------------
var (
siteName = "HappeLife"
blogPostsDir = "posts"
)

func GetBlogPostsDir() string {
return blogPostsDir
}

func GetSiteName() string {
return siteName
}
22 changes: 0 additions & 22 deletions logs/gitmdblog.log

This file was deleted.

31 changes: 21 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"fmt"
logger "github.com/ccpaging/log4go"
"gitmdblog/config"
"gitmdblog/models"
"io"
"io/ioutil"
Expand All @@ -15,9 +15,12 @@ import (
"strings"
"text/template"
"time"

logger "github.com/ccpaging/log4go"
)

var (
siteName = config.GetSiteName()
host = "127.0.0.1:8001"
isCreateHTML = false
htmlPrefix = "../itopic.org" //without last slash
Expand All @@ -26,17 +29,15 @@ var (
)

func init() {
logger_init()
}

func logger_init() {
logger.LoadConfiguration("conf/log4go.xml")
}

func main() {
logger.Info("%s", "--- in main ---")
router := loadHTTPRouter()
ticker := time.NewTicker(1800 * time.Second)

// 定时器,定时刷新
ticker := time.NewTicker(3 * time.Second)
go func() {
for range ticker.C {
models.InitTopicList()
Expand Down Expand Up @@ -84,18 +85,23 @@ func main() {
func loadHTTPRouter() map[string]bytes.Buffer {
router := make(map[string]bytes.Buffer)
var tpl *template.Template

// 指定模板文件存放目录
tpl, err := template.ParseGlob("views/*.tpl")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var pages []map[string]string
//homepage router

//首页 homepage router
var buff bytes.Buffer
topicCnt := len(models.Topics)
topicDivCnt := topicCnt / 2
var topicsLeft []*models.TopicMonth
var topicsRight []*models.TopicMonth

var topicsLeft []*models.TopicMonth //左侧
var topicsRight []*models.TopicMonth //右侧

if topicDivCnt > 0 {
t := 0
isSplit := false
Expand All @@ -114,7 +120,10 @@ func loadHTTPRouter() map[string]bytes.Buffer {
} else {
topicsLeft = models.TopicsGroupByMonth
}

// 网页模板
if err := tpl.ExecuteTemplate(&buff, "index.tpl", map[string]interface{}{
"siteName": siteName,
"topics_l": topicsLeft,
"topics_r": topicsRight,
"domain": domain,
Expand All @@ -126,13 +135,15 @@ func loadHTTPRouter() map[string]bytes.Buffer {
}
router["/"] = buff
router["/index"] = buff

pages = append(pages, map[string]string{
"loc": domain + "/",
"lastmod": time.Now().Format("2006-01-02"),
"changefreq": "weekly",
"priority": "1",
})
//topic router

// 文章页 topic router
for i := range models.Topics {
if models.Topics[i].IsPublic == false {
continue
Expand Down
1 change: 1 addition & 0 deletions models/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (

//Topic struct
type Topic struct {
SiteName string
TopicID string
Title string
Time time.Time
Expand Down
8 changes: 7 additions & 1 deletion models/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"bufio"
"bytes"
"errors"
"gopkg.in/russross/blackfriday.v2"
"gitmdblog/config"
"os"
"path/filepath"
"strings"
"time"

"gopkg.in/russross/blackfriday.v2"
)

//GetTopicByPath read the topic by path
Expand Down Expand Up @@ -97,6 +99,10 @@ func GetTopicByPath(path string) (*Topic, error) {
if lastModTime.Unix()-t.Time.Unix() > 7*86400 && time.Now().Unix()-lastModTime.Unix() < 365*86400 {
t.LastModifyTime = lastModTime
}

// ----------------- 站点配置 -----------------
t.SiteName = config.GetSiteName()

return t, nil
}

Expand Down
Loading

0 comments on commit 67f934e

Please sign in to comment.