Skip to content

Commit

Permalink
feat: theme directory
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Apr 2, 2019
1 parent 0a94816 commit 276a865
Show file tree
Hide file tree
Showing 128 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ admin/ | 后台目录
auth/ | 授权管理
client/ | 博客客户端
exception/ | 异常处理
front/ | 博客主题
themes/ | 主题目录
gateway | 网关接口层
modules/ | 公共模块
protocols/ | 协议定义
Expand Down
8 changes: 4 additions & 4 deletions server/main.go
Expand Up @@ -16,11 +16,11 @@ import (
"github.com/movsb/taoblog/admin"
"github.com/movsb/taoblog/auth"
"github.com/movsb/taoblog/exception"
"github.com/movsb/taoblog/front"
"github.com/movsb/taoblog/gateway"
"github.com/movsb/taoblog/service"
"github.com/movsb/taoblog/setup/migration"
"github.com/movsb/taoblog/weekly"
"github.com/movsb/taoblog/themes/front"
"github.com/movsb/taoblog/themes/weekly"
)

func main() {
Expand Down Expand Up @@ -75,9 +75,9 @@ func main() {

switch themeName := os.Getenv("THEME"); themeName {
case "BLOG":
front.NewFront(theService, theAuth, router.Group("/blog"), theAPI)
front.NewFront(theService, theAuth, router.Group("/blog"), theAPI, "themes/front")
case "WEEKLY":
weekly.NewWeekly(theService, theAuth, router.Group("/blog"), theAPI)
weekly.NewWeekly(theService, theAuth, router.Group("/blog"), theAPI, "themes/weekly")
default:
panic("unknown theme")
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions front/main.go → themes/front/main.go
Expand Up @@ -74,6 +74,7 @@ type QueryTags struct {

// Front ...
type Front struct {
base string // base directory
service *service.Service
templates *template.Template
router *gin.RouterGroup
Expand All @@ -85,8 +86,9 @@ type Front struct {
}

// NewFront ...
func NewFront(service *service.Service, auth *auth.Auth, router *gin.RouterGroup, api *gin.RouterGroup) *Front {
func NewFront(service *service.Service, auth *auth.Auth, router *gin.RouterGroup, api *gin.RouterGroup, base string) *Front {
f := &Front{
base: base,
service: service,
router: router,
auth: auth,
Expand Down Expand Up @@ -136,7 +138,7 @@ func (f *Front) loadTemplates() {

var tmpl *template.Template
tmpl = template.New("front").Funcs(funcs)
path := filepath.Join("front/templates", "*.html")
path := filepath.Join(f.base, "templates", "*.html")
tmpl, err := tmpl.ParseGlob(path)
if err != nil {
panic(err)
Expand Down Expand Up @@ -213,7 +215,7 @@ func (f *Front) Query(c *gin.Context, path string) {
c.String(http.StatusForbidden, "403 Forbidden")
return
}
c.File(filepath.Join("front/statics", path))
c.File(filepath.Join(f.base, "statics", path))
}

func (f *Front) handle304(c *gin.Context, p *protocols.Post) bool {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions front/tools.go → themes/front/tools.go
Expand Up @@ -9,6 +9,7 @@ import (
)

func toolpath(name string) string {
// TODO use base
return filepath.Join("front/tools/bin", name)
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 5 additions & 3 deletions weekly/main.go → themes/weekly/main.go
Expand Up @@ -49,6 +49,7 @@ type Home struct {

// Weekly ...
type Weekly struct {
base string // base directory
service *service.Service
templates *template.Template
router *gin.RouterGroup
Expand All @@ -60,8 +61,9 @@ type Weekly struct {
}

// NewWeekly ...
func NewWeekly(service *service.Service, auth *auth.Auth, router *gin.RouterGroup, api *gin.RouterGroup) *Weekly {
func NewWeekly(service *service.Service, auth *auth.Auth, router *gin.RouterGroup, api *gin.RouterGroup, base string) *Weekly {
w := &Weekly{
base: base,
service: service,
router: router,
auth: auth,
Expand Down Expand Up @@ -95,7 +97,7 @@ func (w *Weekly) loadTemplates() {

var tmpl *template.Template
tmpl = template.New("weekly").Funcs(funcs)
path := filepath.Join("weekly/templates", "*.html")
path := filepath.Join(w.base, "templates", "*.html")
tmpl, err := tmpl.ParseGlob(path)
if err != nil {
panic(err)
Expand Down Expand Up @@ -131,7 +133,7 @@ func (w *Weekly) Query(c *gin.Context, path string) {
w.queryBySlug(c, slug)
return
}
c.File(filepath.Join("weekly/statics", path))
c.File(filepath.Join(w.base, "statics", path))
}

func (w *Weekly) handle304(c *gin.Context, p *protocols.Post) bool {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 276a865

Please sign in to comment.