~srivathsan/blaze

f3d97227832bcca10fc368e567b89dcf8e9aa9b3 — Srivathsan Murali 3 years ago 450ff01
seperate toHTML and parseTemplate
3 files changed, 9 insertions(+), 21 deletions(-)

M builder/builder.go
M builder/page.go
M watcher/watcher.go
M builder/builder.go => builder/builder.go +0 -4
@@ 20,10 20,6 @@ func Build(config *config.BlazeConfig) error {
	}

	for _, p := range pages {
		if err != p.ConvertToHTML() {
			return err
		}

		if err != p.WritePage() {
			return err
		}

M builder/page.go => builder/page.go +9 -12
@@ 87,19 87,11 @@ func ParsePage(relativePath string, config *config.BlazeConfig) (*Page, error) {
		return nil, err
	}

	return page, nil
}

func (p *Page) ConvertToHTML() error {
	p.Content = ToHTML(p.Content)

	readyData, err := ParseTemplate(p.Site, p.Template, p)
	if err != nil {
		return err
	if page.Extension == ".html" {
		page.Content = ToHTML(page.Content)
	}

	p.HTML = readyData
	return nil
	return page, nil
}

func (p *Page) WritePage() error {


@@ 109,7 101,12 @@ func (p *Page) WritePage() error {
		return err
	}

	if err := ioutil.WriteFile(p.outputPath, p.HTML, 0644); err != nil {
	readyData, err := ParseTemplate(p.Site, p.Template, p)
	if err != nil {
		return err
	}

	if err := ioutil.WriteFile(p.outputPath, readyData, 0644); err != nil {
		return err
	}


M watcher/watcher.go => watcher/watcher.go +0 -5
@@ 55,11 55,6 @@ func Watch(config *config.BlazeConfig) error {
						return
					}

					if err := pageData.ConvertToHTML(); err != nil {
						log.Fatalf("Error Executing Page: %v", err)
						return
					}

					if err := pageData.WritePage(); err != nil {
						log.Fatalf("Error Executing Page: %v", err)
						return