fix:优化文章显示效果

pull/536/head
lifei6671 2019-03-11 18:09:19 +08:00
parent b1979a3fdb
commit 0856b9e42f
2 changed files with 129 additions and 116 deletions

View File

@ -53,7 +53,7 @@ func (c *BlogController) Index() {
c.JsonResult(6001, "文章密码不正确")
} else if blog.BlogStatus == "password" && password == blog.Password {
//如果密码输入正确则存入session中
c.CruSession.Set(blogReadSession, blogId)
_ = c.CruSession.Set(blogReadSession, blogId)
c.JsonResult(0, "OK")
}
c.JsonResult(0, "OK")
@ -61,8 +61,11 @@ func (c *BlogController) Index() {
//如果不存在已输入密码的标记
c.TplName = "blog/index_password.tpl"
}
if blog.BlogType != 1 {
//加载文章附件
blog.LinkAttach();
_ = blog.LinkAttach()
}
c.Data["Model"] = blog
c.Data["Content"] = template.HTML(blog.BlogRelease)

View File

@ -1,16 +1,16 @@
package models
import (
"time"
"github.com/lifei6671/mindoc/conf"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego"
"github.com/lifei6671/mindoc/cache"
"bytes"
"fmt"
"github.com/PuerkitoBio/goquery"
"strings"
"bytes"
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/lifei6671/mindoc/cache"
"github.com/lifei6671/mindoc/conf"
"github.com/lifei6671/mindoc/utils"
"strings"
"time"
)
//博文表
@ -61,24 +61,24 @@ type Blog struct {
}
// 多字段唯一键
func (m *Blog) TableUnique() [][]string {
func (b *Blog) TableUnique() [][]string {
return [][]string{
{"blog_id", "blog_identify"},
}
}
// TableName 获取对应数据库表名.
func (m *Blog) TableName() string {
func (b *Blog) TableName() string {
return "blogs"
}
// TableEngine 获取数据使用的引擎.
func (m *Blog) TableEngine() string {
func (b *Blog) TableEngine() string {
return "INNODB"
}
func (m *Blog) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + m.TableName()
func (b *Blog) TableNameWithPrefix() string {
return conf.GetDatabasePrefix() + b.TableName()
}
func NewBlog() *Blog {
@ -97,7 +97,6 @@ func (b *Blog) Find(blogId int) (*Blog,error) {
return nil, err
}
return b.Link()
}
@ -125,7 +124,6 @@ func (b *Blog) FindFromCache(blogId int) (blog *Blog,err error) {
return
}
//查找指定用户的指定文章
func (b *Blog) FindByIdAndMemberId(blogId, memberId int) (*Blog, error) {
o := orm.NewOrm()
@ -138,6 +136,7 @@ func (b *Blog) FindByIdAndMemberId(blogId,memberId int) (*Blog,error) {
return b.Link()
}
//根据文章标识查询文章
func (b *Blog) FindByIdentify(identify string) (*Blog, error) {
o := orm.NewOrm()
@ -161,6 +160,7 @@ func (b *Blog)Link() (*Blog,error) {
} else {
b.DocumentIdentify = doc.Identify
b.BlogRelease = doc.Release
//目前仅支持markdown文档进行链接
b.BlogContent = doc.Markdown
book := NewBook()
@ -170,6 +170,17 @@ func (b *Blog)Link() (*Blog,error) {
b.BookIdentify = book.Identify
b.BookId = doc.BookId
}
//处理链接文档存在源文档修改时间的问题
if content, err := goquery.NewDocumentFromReader(bytes.NewBufferString(b.BlogRelease)); err == nil {
content.Find(".wiki-bottom").Remove()
if html,err := content.Html();err == nil {
b.BlogRelease = html
} else {
beego.Error("处理文章失败 ->",err)
}
}else {
beego.Error("处理文章失败 ->",err)
}
}
}
@ -288,7 +299,6 @@ func (b *Blog) FindToPager(pageIndex, pageSize int,memberId int,status string) (
query = query.Filter("blog_status", status)
}
_, err = query.OrderBy("-order_index", "-blog_id").Offset(offset).Limit(pageSize).All(&blogList)
if err != nil {