Esempio n. 1
0
// Summary returns content summary.
// Summary text means the part before page-break <!--more-->.
// It can be go-markdown rendered.
func (cnt *Content) Summary() string {
	text := strings.Split(cnt.Text, "<!--more-->")[0]
	if GetSetting("enable_go_markdown") == "true" {
		return utils.Markdown2Html(text)
	}
	return text
}
Esempio n. 2
0
func Rss(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	article, _ := model.GetPublishArticleList(1, 20)
	author := model.GetUsersByRole("ADMIN")[0]

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Title"] = a.Title
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Author"] = author.Nick
		str := utils.Markdown2Html(a.Content())
		str = strings.Replace(str, `src="/`, `src="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		str = strings.Replace(str, `href="/`, `href="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		m["Desc"] = str
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC822)
		articleMap[i] = m
	}

	ctx.ContentType("application/rss+xml;charset=UTF-8")

	bytes, e := ctx.App().View().Render("rss.xml", map[string]interface{}{
		"Title":    model.GetSetting("site_title"),
		"Link":     baseUrl,
		"Desc":     model.GetSetting("site_description"),
		"Created":  time.Unix(utils.Now(), 0).Format(time.RFC822),
		"Articles": articleMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes
}
Esempio n. 3
0
// Content returns whole content text.
// If enable go-markdown, return markdown-rendered content.
func (cnt *Content) Content() string {
	txt := strings.Replace(cnt.Text, "<!--more-->", "", -1)
	if GetSetting("enable_go_markdown") == "true" {
		if cnt.textRendered == "" {
			cnt.textRendered = utils.Markdown2Html(txt)
		}
		return cnt.textRendered
	}
	return txt
}