Exemple #1
0
// NewPage create new page
func (d *Dir) NewPage(f os.FileInfo) (*Page, error) {
	prs, err := parser.New(f.Name())
	if err != nil || strings.HasPrefix(f.Name(), "_") {
		return nil, errors.New(fmt.Sprintf("Not allowed file format %s\n", f.Name()))
	}

	cont, err := ioutil.ReadFile(getPath(d.mdDir, f.Name()))

	if err != nil {
		return nil, err
	}

	title := prs.GetTitle(f.Name())
	html := prs.Parse(cont)

	p := &Page{}
	p.Title = title
	p.Seo = &Seo{
		Title:       "",
		Description: "",
		Keywords:    "",
	}
	p.Body = template.HTML(html)
	p.Path = getPath(d.htmlDir, getUrl(p.Title)+".html")
	p.Url = getPath(d.path, getUrl(p.Title)+".html")
	p.Template = d.template

	return p, nil
}
Exemple #2
0
func generateSidebar(mdSidebar string) (template.HTML, error) {
	var sidebar template.HTML
	prs, err := parser.New(mdSidebar)
	if err != nil {
		return "", err
	}

	file, err := ioutil.ReadFile(mdSidebar)

	if err != nil {
		return "", err
	}

	sidebar = template.HTML(prs.Parse(file))

	return sidebar, nil
}