Пример #1
0
func loadContent(file string) (art *Article, err error) {

	art = &Article{}

	ctx, err := ReadMuCtx(file)

	if err != nil {
		return nil, err
	}

	sumLines := conf.SiteSumLine()

	summary, err := makeSummary(ctx.Content, sumLines)

	if err != nil {
		return nil, err
	}

	art.Title = ctx.Title
	art.Description = ctx.Description
	art.Category = ctx.Categories
	art.Tags = ctx.Tags
	art.Summary = summary
	art.Content = utils.MarkdownToHtml(ctx.Content)
	art.CreatedAt = utils.Str2Unix("2006-01-02", ctx.Date)

	return art, nil
}
Пример #2
0
// 获取about内容
func GetAbout() (art *Article, err error) {
	art = &Article{}
	about := path.Join(conf.DirMark(), "/about.md")

	if _, err := os.Stat(about); os.IsNotExist(err) {
		return art, nil
	}

	content, err := ioutil.ReadFile(about)

	if err != nil {
		return nil, err
	}

	art.Title = ""
	art.Content = utils.MarkdownToHtml(string(content))
	art.CreatedAt = time.Now().Unix()

	return art, nil
}
Пример #3
0
// 根据文件获取摘要信息
func makeSummary(content string, lines int) (string, error) {
	buff := bufio.NewReader(bytes.NewBufferString(content))
	dst := ""
	for lines > 0 {
		line, err := buff.ReadString('\n')
		if err != nil || io.EOF == err {
			break
		}

		if strings.Contains(line, "[toc]") {
			continue
		}

		if strings.Trim(line, "\r\n\t ") == "```" {
			continue
		}

		dst += line
		lines--
	}

	return utils.MarkdownToHtml(dst), nil
}