diff --git a/.dockerignore b/.dockerignore index c5e3e21..ede0043 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,4 +9,5 @@ vendor vendor/** *.go *.sh -setting \ No newline at end of file +*.DS_Store +setting diff --git a/conf/app.yml b/conf/app.yml index cf0b79f..927265a 100644 --- a/conf/app.yml +++ b/conf/app.yml @@ -11,7 +11,7 @@ pagenum: 10 # 管理界面 pagesize: 20 # 自动截取预览, 字符数 -length: 200 +length: 400 # 截取预览标识 identifier: # favicon diff --git a/db.go b/db.go index 3d5d571..8e5dd40 100644 --- a/db.go +++ b/db.go @@ -351,9 +351,20 @@ func ManageArchivesArticle(artc *Article, s bool, do string) { // 渲染markdown操作和截取摘要操作 var reg = regexp.MustCompile(setting.Conf.Identifier) +// header +var regH = regexp.MustCompile("") + func GenerateExcerptAndRender(artc *Article) { - index := reg.FindStringIndex(artc.Content) - if len(index) > 0 { + content := renderPage([]byte(artc.Content)) + index := regH.FindIndex(content) + if index != nil { + artc.Header = string(content[0:index[1]]) + artc.Content = string(content[index[1]:]) + } else { + artc.Content = string(content) + } + index = reg.FindStringIndex(artc.Content) + if index != nil { artc.Excerpt = IgnoreHtmlTag(artc.Content[0:index[0]]) } else { uc := []rune(artc.Content) @@ -363,7 +374,6 @@ func GenerateExcerptAndRender(artc *Article) { } artc.Excerpt = IgnoreHtmlTag(string(uc[0:length])) } - artc.Content = string(renderPage([]byte(artc.Content))) } // 读取草稿箱 diff --git a/model.go b/model.go index b225cf6..83f2f8c 100644 --- a/model.go +++ b/model.go @@ -115,6 +115,8 @@ type Article struct { Prev *Article `bson:"-"` // 下篇文章 Next *Article `bson:"-"` + // Header + Header string `bson:"-"` // 预览信息 Excerpt string `bson:"-"` } diff --git a/views/about.html b/views/about.html index e50438d..71cc47a 100644 --- a/views/about.html +++ b/views/about.html @@ -1 +1 @@ -{{define "about"}}
{{with .Article}}

{{.Title}}

{{str2html .Content}}

Comments

{{end}}
{{end}} \ No newline at end of file +{{define "about"}}
{{with .Article}}

{{.Title}}

{{str2html .Header}}{{str2html .Content}}

Comments

{{end}}
{{end}} diff --git a/views/archives.html b/views/archives.html index 88f2da4..a0b0fb1 100644 --- a/views/archives.html +++ b/views/archives.html @@ -1 +1 @@ -{{define "archives"}}

归档

{{str2html .Article}}
{{end}} \ No newline at end of file +{{define "archives"}}

归档

{{str2html .Article}}
{{end}} diff --git a/views/article.html b/views/article.html index 81cefb4..c9e4c64 100644 --- a/views/article.html +++ b/views/article.html @@ -1 +1 @@ -{{define "article"}}
{{with .Article}}

{{.Title}}

{{str2html .Content}}

本文链接:参与评论 »

--EOF--

{{with $.Copyright}}{{end}}{{if gt $.Days 100}}

提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。

{{end}}{{with $.Serie}}

专题「{{.Name}}」的其它文章 »

    {{range .Articles}}{{if ne .ID $.Article.ID}}
  • {{.Title}} ({{dateformat .CreateTime "Jan 02, 2006"}})
  • {{end}}{{end}}
{{end}}

Comments

{{end}}
{{end}} \ No newline at end of file +{{define "article"}}
{{with .Article}}

{{.Title}}

{{str2html .Header}}{{str2html .Content}}

本文链接:参与评论 »

--EOF--

{{with $.Copyright}}{{end}}{{if gt $.Days 100}}

提醒:本文最后更新于 {{$.Days}} 天前,文中所描述的信息可能已发生改变,请谨慎使用。

{{end}}{{with $.Serie}}

专题「{{.Name}}」的其它文章 »

    {{range .Articles}}{{if ne .ID $.Article.ID}}
  • {{.Title}} ({{dateformat .CreateTime "Jan 02, 2006"}})
  • {{end}}{{end}}
{{end}}

Comments

{{end}}
{{end}} diff --git a/views/series.html b/views/series.html index da234c7..f31a53f 100644 --- a/views/series.html +++ b/views/series.html @@ -1 +1 @@ -{{define "series"}}

专题

{{str2html .Article}}
{{end}} \ No newline at end of file +{{define "series"}}

专题

{{str2html .Article}}
{{end}}