安裝配置
需要先安裝配置 Golang,然后安裝配置 beego,beego是一個(gè)使用 Go 的思維來(lái)幫助您
構(gòu)建并開(kāi)發(fā) Go 應(yīng)用程序的開(kāi)源Web開(kāi)發(fā)框架,beego的中文文檔很友好,請(qǐng)自行查看 beego
安裝配置完成之后,使用 bee命令創(chuàng)建工程
說(shuō)明: 使用beego框架開(kāi)發(fā),后臺(tái)數(shù)據(jù)庫(kù)是 MongoDB,編輯是 Mardkdown
bee new blog
// 目錄結(jié)構(gòu)如下
├─conf
├─controllers
├─models
├─routers
├─static
│ ├─css
│ ├─img
│ └─js
├─tests
└─views
使用 bee run,請(qǐng)?jiān)跒g覽器打開(kāi) 127.0.0.1:8080就能看到效果了
markdown編輯器
使用的是 SimpleMDE來(lái)定制個(gè)人的markdown編輯器,關(guān)于 SimpleMDE的相關(guān)的配置請(qǐng)參考這篇文章
beego框架默認(rèn)支持后綴是 tpl 和 html的模板
- 在views中創(chuàng)建editor.html
- 在 static中引入
simplemde.min.css
對(duì)simplemde.min.css稍微改造一下,添加一個(gè)標(biāo)題和發(fā)布按鈕,默認(rèn)全屏并顯示預(yù)覽界面,SimpleMDE
的核心配置如下:
var simplemde = new SimpleMDE({
element: document.getElementById("editor"),
status: false,
autoDownloadFontAwesome: false,
tabSize: 4,
renderingConfig: {
codeSyntaxHighlighting: true
},
});
simplemde.toggleSideBySide();
添加一個(gè) Editor 的控制器
在 controllers中添加文件 editor.go
package controllers
import "github.com/astaxie/beego"
type EditorController struct {
beego.Controller
}
func (this *EditorController) Get() {
this.TplName = "editor.html"
}
添加對(duì)應(yīng)的路由
在 routers/router.go中添加路由映射
beego.Router("/editor", &controllers.EditorController{})
在瀏覽器中輸入地址 127.0.0.1:8080/editor 查看效果
