Beispiel #1
0
// 将docs的内容以html格式输出。
func Html(docs []*core.Doc, opt *Options) error {
	t := template.New("core")
	for _, content := range static.Templates {
		template.Must(t.Parse(content))
	}

	i := &info{
		Title:      opt.Title,
		Version:    opt.Version,
		AppVersion: opt.AppVersion,
		Elapsed:    strconv.FormatFloat(float64(opt.Elapsed)/1000000, 'f', 2, 32),
		Date:       time.Now().Format(time.RFC3339),
		Groups:     make(map[string]string, len(docs)),
	}

	groups := map[string][]*core.Doc{}
	for _, v := range docs {
		i.Groups[v.Group] = "./group_" + v.Group + ".html"
		if groups[v.Group] == nil {
			groups[v.Group] = []*core.Doc{}
		}
		groups[v.Group] = append(groups[v.Group], v)
	}

	if err := outputIndex(t, i, opt.DocDir); err != nil {
		return err
	}

	if err := outputGroup(groups, t, i, opt.DocDir); err != nil {
		return err
	}

	// 输出static
	return static.Output(opt.DocDir)
}
Beispiel #2
0
// 根据模板 t 将页面输出到 destDir 目录
func renderHTMLGroups(p *htmlPage, t *template.Template, destDir string) error {
	for name, group := range p.Groups {
		path := filepath.Join(destDir, name+htmlSuffix)
		file, err := os.Create(path)
		if err != nil {
			return err
		}
		defer file.Close()

		p.GroupName = name
		p.Group = group

		tplName := "group"
		if name == app.DefaultGroupName {
			tplName = "index"
		}
		if err = t.ExecuteTemplate(file, tplName, p); err != nil {
			return err
		}
	}

	// 输出static
	return static.Output(destDir)
}