mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Providing the ability to save (write) a content's source file.
This commit is contained in:
parent
1302ef9f63
commit
859a78e1bd
1 changed files with 25 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue