Beispiel #1
0
func initRoute() error {
	m, err := web.NewModule("front")
	if err != nil {
		return err
	}

	m.Get("/", etagHandler(handlers.CompressFunc(pageRoot))).
		Get(app.TagsURL(), etagHandler(handlers.CompressFunc(pageTags))).
		Get(app.TagURL("{id}", 1), etagHandler(handlers.CompressFunc(pageTag))).
		Get(app.PostsURL(1), etagHandler(handlers.CompressFunc(pagePosts))).
		Get(app.PostURL("{id}"), etagHandler(handlers.CompressFunc(pagePost))). // 获取文章详细内容
		Post(app.PostURL("{id}"), etagHandler(handlers.CompressFunc(pagePost))) // 提交评论

	// TODO 静态文件压缩
	m.Get(cfg.UploadURLPrefix+"/", http.StripPrefix(cfg.UploadURLPrefix, http.FileServer(http.Dir(cfg.UploadDir)))).
		Get(cfg.ThemeURLPrefix+"/", http.StripPrefix(cfg.ThemeURLPrefix, http.FileServer(http.Dir(cfg.ThemeDir))))

	// API
	m.Prefix(cfg.FrontAPIPrefix).
		PostFunc("/posts/{id:\\d+}/comments", frontPostPostComment).
		GetFunc("/posts/{id:\\d+}/comments", frontGetPostComments)

	return nil
}
Beispiel #2
0
// 返回文章的链接,相对URL
func (p *Post) Permalink() string {
	if len(p.Name) > 0 {
		return app.PostURL(p.Name)
	}
	return app.PostURL(strconv.FormatInt(p.ID, 10))
}