Exemplo n.º 1
0
func (p *Post) normalize() error {
	if p.Slug == "" {
		// use filename instead of slug, do not use title
		p.Slug = strings.TrimSuffix(filepath.Base(p.fileURL), filepath.Ext(p.fileURL))
	}
	var err error
	if p.Date != "" {
		if p.dateTime, err = parseTimeString(p.Date); err != nil {
			return err
		}
	}
	if p.Update == "" {
		p.Update = p.Date
		p.updateTime = p.dateTime
	} else {
		if p.updateTime, err = parseTimeString(p.Update); err != nil {
			return err
		}
	}
	p.contentBytes = helper.Markdown(p.Bytes)
	p.briefBytes = helper.Markdown(bytes.Split(p.Bytes, postBriefSeparator)[0])
	permaURL := fmt.Sprintf("/%d/%d/%d/%s", p.dateTime.Year(), p.dateTime.Month(), p.dateTime.Day(), p.Slug)
	p.postURL = permaURL + ".html"
	for _, t := range p.TagString {
		p.Tags = append(p.Tags, NewTag(t))
	}
	return nil
}
Exemplo n.º 2
0
func (p *Page) normalize() error {
	if p.Template == "" {
		p.Template = "page.html"
	}
	var err error
	if p.Date != "" {
		if p.dateTime, err = parseTimeString(p.Date); err != nil {
			return err
		}
	}
	if p.Update == "" {
		p.Update = p.Date
		p.updateTime = p.dateTime
	} else {
		if p.updateTime, err = parseTimeString(p.Update); err != nil {
			return err
		}
	}
	p.contentBytes = helper.Markdown(p.Bytes)
	p.pageURL = "/" + p.Slug
	if !p.Node {
		p.pageURL = fmt.Sprintf("/%s", p.Slug) + ".html"
	}
	return nil
}