Skip to content

Commit

Permalink
improve seo setting
Browse files Browse the repository at this point in the history
  • Loading branch information
askmhx committed Feb 18, 2019
1 parent 221efc1 commit 6a28a86
Show file tree
Hide file tree
Showing 44 changed files with 633 additions and 330 deletions.
30 changes: 7 additions & 23 deletions app/bootstrap.go
Expand Up @@ -2,39 +2,26 @@ package app

import (
"fmt"
"github.com/jinzhu/gorm"
"github.com/kataras/iris"
"github.com/kataras/iris/sessions"
"github.com/kataras/iris/view"
"gopkg.in/russross/blackfriday.v2"
"html/template"
"iosxc.com/levante/util"
"os"
)

//logger -> db -> context -> web -> run

func Launch(app *iris.Application, config *AppConfig) {
setLogger(app, config)
setDatabase(app, config)
setCtxHolder(app, config)
setWebView(app, config)
registerErrorHandler(app)
app.Run(iris.Addr(fmt.Sprintf("%s:%d", config.Server.Addr, config.Server.Port)), iris.WithCharset(config.Server.CharSet))
}

var ctxHolder *ContextHolder

type ContextHolder struct {
SessionsManager *sessions.Sessions
Database *gorm.DB
Config *AppConfig
}

func setCtxHolder(app *iris.Application, config *AppConfig) {
ctxHolder = &ContextHolder{}
ctxHolder.Config = config
ctxHolder.Database = db
ctxHolder.SessionsManager = sessions.New(sessions.Config{Cookie: "mysessioncookie"})
func registerErrorHandler(application *iris.Application) {
application.OnAnyErrorCode(func(ctx iris.Context) {
ctx.ViewData("Message", ctx.Values().GetStringDefault("message", "网页丢啦"))
ctx.View("front/error.html")
})
}

func setLogger(application *iris.Application, config *AppConfig) {
Expand All @@ -49,9 +36,6 @@ func setLogger(application *iris.Application, config *AppConfig) {
application.Use(logger)
}

func setDatabase(app *iris.Application, config *AppConfig) {
initDatabase(config)
}

func setWebView(app *iris.Application, config *AppConfig) {
staticPath := fmt.Sprintf("%s%s", config.Home, config.View.Static.Path)
Expand All @@ -71,7 +55,7 @@ func setWebView(app *iris.Application, config *AppConfig) {
}
app.StaticWeb(config.View.Static.URI, staticPath)
app.StaticWeb(config.View.HTML.URI, htmlPath)
templateView := view.HTML(templatePath, config.View.Template.Ext).Layout(config.View.Template.Layout).Reload(config.View.Template.Reload)
templateView := iris.HTML(templatePath, config.View.Template.Ext).Layout(config.View.Template.Layout).Reload(config.View.Template.Reload)
templateView.AddFunc("markdown",func(arg string) template.HTML {
buf := blackfriday.Run([]byte(arg))
return template.HTML(buf)
Expand Down
33 changes: 0 additions & 33 deletions app/cache.go

This file was deleted.

61 changes: 0 additions & 61 deletions app/context.go

This file was deleted.

2 changes: 1 addition & 1 deletion app/database.go
Expand Up @@ -12,7 +12,7 @@ import (

var db *gorm.DB

func initDatabase(config *AppConfig) *gorm.DB{
func InitDatabase(config *AppConfig) *gorm.DB{
var err error
dbConnURL := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local", config.Database.User, config.Database.Password, config.Database.Host, config.Database.Port, config.Database.Schema)
db, err = gorm.Open("mysql", dbConnURL)
Expand Down
65 changes: 65 additions & 0 deletions app/route.go
@@ -0,0 +1,65 @@
package app

import (
"github.com/jinzhu/gorm"
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
"iosxc.com/levante/controllers"
"iosxc.com/levante/repositories"
"iosxc.com/levante/services"
)

const url_index = "/"
const url_favicon = "/favicon.ico"
const url_sitemap = "/sitemap.xml"
const url_start = "/start"
const url_about = "/about"
const url_photo = "/photo"
const url_post = "/post"
const url_comment = "/comment"

func InitRoute(application *iris.Application, config *AppConfig, database *gorm.DB) {
application.Favicon(config.Home+"assets/statics/img/favicon.ico", url_favicon)

indexCtrl := new(controllers.IndexController)
postCtrl := new(controllers.PostController)
commentCtrl := new(controllers.CommentController)
photoCtrl := new(controllers.PhotoController)
aboutCtrl := new(controllers.AboutController)
startCtrl := new(controllers.StartController)
sitemapCtrl := new(controllers.SiteMapController)

cacheRepository := repositories.NewMemCacheRepository(2048)

postRepository := repositories.NewPostRepository(database)
linkRepository := repositories.NewLinkRepository(database)

postService := services.NewPostService(postRepository,cacheRepository)
linkService := services.NewLinkService(linkRepository)

indexMvc := mvc.New(application.Party(url_index))
indexMvc.Register(postService)
indexMvc.Handle(indexCtrl)

postMvc := mvc.New(application.Party(url_post))
postMvc.Register(postService)
postMvc.Handle(postCtrl)

startMvc := mvc.New(application.Party(url_start))
startMvc.Register(linkService)
startMvc.Handle(startCtrl)


commentMvc := mvc.New(application.Party(url_comment))
commentMvc.Handle(commentCtrl)

photoMvc := mvc.New(application.Party(url_photo))
photoMvc.Handle(photoCtrl)

aboutMvc := mvc.New(application.Party(url_about))
aboutMvc.Handle(aboutCtrl)

sitemapMvc := mvc.New(application.Party(url_sitemap))
sitemapMvc.Register(postService)
sitemapMvc.Handle(sitemapCtrl)
}
15 changes: 15 additions & 0 deletions controllers/about.go
@@ -0,0 +1,15 @@
package controllers

import (
"github.com/kataras/iris/mvc"
"iosxc.com/levante/services"
)

type AboutController struct {
PostService services.PostService
LinkService services.LinkService
}

func (this *AboutController) Get() mvc.Result {
return ViewPagePlant("about")
}
38 changes: 38 additions & 0 deletions controllers/base.go
@@ -0,0 +1,38 @@
package controllers

import (
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
"iosxc.com/levante/model"
)

type BaseController struct {
Ctx iris.Context
}

var ViewPageNotFound = mvc.View{
Name: "front/error.html",
Data: model.RspDataPageNotFound,
}

var ViewPagePlant = func(html string) mvc.View {
return mvc.View{
Name: "front/"+html+".html",
}
}

var ViewPageWithDataMap = func(html string,dataMap iris.Map) mvc.View {
return mvc.View{
Name: "front/"+html+".html",
Data: dataMap,
}
}

var ViewPageWithModel = func(html,key string,model interface{}) mvc.View {
return mvc.View{
Name: "front/"+html+".html",
Data: iris.Map{
key: model,
},
}
}
15 changes: 15 additions & 0 deletions controllers/comment.go
@@ -0,0 +1,15 @@
package controllers

import "github.com/kataras/iris/mvc"

type CommentController struct {
BaseController
}

func (this *CommentController) ReadHandle() mvc.Result{
return ViewPageNotFound
}

func (this *CommentController) CreateHandle() mvc.Result{
return ViewPageNotFound
}
25 changes: 25 additions & 0 deletions controllers/index.go
@@ -0,0 +1,25 @@
package controllers

import (
"github.com/kataras/iris"
"github.com/kataras/iris/mvc"
"iosxc.com/levante/services"
)

type IndexController struct {
PostService services.PostService
LinkService services.LinkService
}

func (this *IndexController) Get() mvc.Result{
var postList = this.PostService.GetList(0,5)
var mcList = this.PostService.GetMonthList()
var tagList = this.PostService.GetTagList()
var dataMap = iris.Map{}
dataMap["postList"] = postList
dataMap["monthList"] = mcList
dataMap["tagList"] = tagList
return ViewPageWithDataMap("index",dataMap)

}

24 changes: 24 additions & 0 deletions controllers/photo.go
@@ -0,0 +1,24 @@
package controllers

import (
"github.com/kataras/iris/mvc"
)

type PhotoController struct {
BaseController
}

func (this *PhotoController) ReadHandle() mvc.Result{
return ViewPageNotFound

}

func (this *PhotoController) IndexHandle() mvc.Result{
return ViewPageNotFound

}

func (this *PhotoController) UpdateHandle() mvc.Result{
return ViewPageNotFound

}

0 comments on commit 6a28a86

Please sign in to comment.