mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Making site page initialization a bit more granular and accessible
This commit is contained in:
parent
cbd9506c29
commit
1302ef9f63
2 changed files with 15 additions and 5 deletions
|
@ -138,8 +138,6 @@ func renderBytes(content []byte, pagefmt string) []byte {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO abstract further to support loading from more
|
||||
// than just files on disk. Should load reader (file, []byte)
|
||||
func newPage(filename string) *Page {
|
||||
page := Page{contentType: "",
|
||||
File: File{FileName: filename, Extension: "html"},
|
||||
|
@ -207,7 +205,7 @@ func layouts(types string, layout string) (layouts []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
|
||||
func NewPage(name string) (page *Page, err error) {
|
||||
if len(name) == 0 {
|
||||
return nil, errors.New("Zero length page name")
|
||||
}
|
||||
|
@ -215,6 +213,10 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
|
|||
// Create new page
|
||||
p := newPage(name)
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (p *Page) ReadFrom(buf io.Reader) (err error) {
|
||||
// Parse for metadata & body
|
||||
if err = p.parse(buf); err != nil {
|
||||
jww.ERROR.Print(err)
|
||||
|
@ -224,7 +226,7 @@ func ReadFrom(buf io.Reader, name string) (page *Page, err error) {
|
|||
//analyze for raw stats
|
||||
p.analyzePage()
|
||||
|
||||
return p, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) analyzePage() {
|
||||
|
|
|
@ -231,6 +231,10 @@ func (s *Site) checkDescriptions() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Site) Initialise() (err error) {
|
||||
return s.initialize()
|
||||
}
|
||||
|
||||
func (s *Site) initialize() (err error) {
|
||||
if err = s.checkDirectories(); err != nil {
|
||||
return err
|
||||
|
@ -317,7 +321,11 @@ func (s *Site) CreatePages() (err error) {
|
|||
go func(file *source.File) (err error) {
|
||||
defer wg.Done()
|
||||
|
||||
page, err := ReadFrom(file.Contents, file.LogicalName)
|
||||
page, err := NewPage(file.LogicalName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = page.ReadFrom(file.Contents)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue