Providing the ability to save (write) a content's source file.

This commit is contained in:
spf13 2014-05-01 13:21:37 -04:00
parent 1302ef9f63
commit 859a78e1bd

View file

@ -567,6 +567,27 @@ func (page *Page) SetSourceMetaData(in interface{}, mark rune) (err error) {
return nil
}
func (page *Page) SaveSourceAs(path string) {
b := new(bytes.Buffer)
b.Write(page.sourceFrontmatter)
b.Write(page.sourceContent)
page.saveSource(b.Bytes(), path)
}
func (page *Page) saveSource(by []byte, inpath string) (err error) {
if !path.IsAbs(inpath) {
inpath = helpers.AbsPathify(inpath)
}
jww.INFO.Println("creating", inpath)
helpers.WriteToDisk(inpath, bytes.NewReader(by))
return nil
}
func (page *Page) SaveSource() {
page.SaveSourceAs(page.FullFilePath())
}
func (p *Page) ProcessShortcodes(t Template) {
p.rawContent = []byte(ShortcodesHandle(string(p.rawContent), p, t))
p.Summary = template.HTML(ShortcodesHandle(string(p.Summary), p, t))
@ -669,6 +690,10 @@ func ReaderToBytes(lines io.Reader) []byte {
return b.Bytes()
}
func (p *Page) FullFilePath() string {
return path.Join(p.Dir, p.FileName)
}
func (p *Page) TargetPath() (outfile string) {
// Always use Url if it's specified