func (page *Page) PrettyDate() string {
	return page.CreatedAt().Format("Jan 02, 2006")
}
PrettyDate returns a human-friendly representation of the CreatedAt date
package pages
import (
	"fmt"
	"io/ioutil"
	"os/exec"
	"path/filepath"
	"strings"
	"time"
	"github.com/ericaro/frontmatter"
	"github.com/senorprogrammer/til/src"
)
const (
	ghFriendlyDateFormat = "2006-01-02T15-04-05"
	FileExtension = "md"
)
type Page struct {
	Content  string `fm:"content" yaml:"-"`
	Date     string `yaml:"date"`
	FilePath string `yaml:"filepath"`
	TagsStr  string `yaml:"tags"`
	Title    string `yaml:"title"`
}
func NewPage(title string, targetDir string) *Page {
	date := time.Now()
	page := &Page{
		Date: date.Format(time.RFC3339),
		FilePath: fmt.Sprintf(
			"%s/%s-%s.%s",
			targetDir,
			date.Format(ghFriendlyDateFormat),
			strings.ReplaceAll(strings.ToLower(title), " ", "-"),
			FileExtension,
		),
		Title: title,
	}
	page.Save()
	return page
}
func PageFromFilePath(filePath string) *Page {
	page := new(Page)
	data, err := ioutil.ReadFile(filePath)
	if err != nil {
		src.Defeat(err)
	}
	err = frontmatter.Unmarshal(data, page)
	if err != nil {
		src.Defeat(err)
	}
	page.FilePath = filePath
	return page
}
func (page *Page) CreatedAt() time.Time {
	date, err := time.Parse(time.RFC3339, page.Date)
	if err != nil {
		return time.Time{}
	}
	return date
}
func (page *Page) CreatedMonth() time.Month {
	if page.CreatedAt().IsZero() {
		return 0
	}
	return page.CreatedAt().Month()
}
func (page *Page) FrontMatter() string {
	return fmt.Sprintf(
		"---\ndate: %s\ntitle: %s\ntags: %s\n---\n\n",
		page.Date,
		page.Title,
		page.TagsStr,
	)
}
func (page *Page) IsContentPage() bool {
	return page.Title != ""
}
func (page *Page) Link() string {
	return fmt.Sprintf(
		"<code>%s</code> [%s](%s)",
		page.PrettyDate(),
		page.Title,
		filepath.Base(page.FilePath),
	)
}
func (page *Page) Open(defaultEditor string) error {
	editor := src.GlobalConfig.UString("editor", defaultEditor)
	if editor == "" {
		editor = defaultEditor
	}
	cmd := exec.Command(editor, page.FilePath)
	err := cmd.Run()
	return err
}