diff --git a/templates/templates.go b/templates/templates.go index 6b8647a..b8f0dc3 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -65,7 +65,11 @@ func Parse(path string) (*Template, error) { } func (templ Template) Ext() string { - return filepath.Ext(templ.srcPath) + ext := filepath.Ext(templ.srcPath) + if ext == ".org" { + ext = ".html" + } + return ext } func (templ Template) Render() ([]byte, error) { @@ -87,7 +91,7 @@ func (templ Template) Render() ([]byte, error) { contents = append(contents, scanner.Text()+"\n"...) } - if templ.Ext() == ".org" { + if strings.HasSuffix(templ.srcPath, ".org") { // if it's an org file, convert to html doc := org.New().Parse(bytes.NewReader(contents), templ.srcPath) html, err := doc.Write(org.NewHTMLWriter()) diff --git a/templates/templates_test.go b/templates/templates_test.go index fd0b554..6f2c15e 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -119,7 +119,47 @@ tags: ["software", "web"] } func TestRenderOrg(t *testing.T) { - // TODO + input := `--- +title: my new post +subtitle: a blog post +tags: ["software", "web"] +--- +#+OPTIONS: toc:nil num:nil +* My title +** my Subtitle +- list 1 +- list 2 +` + + file := newFile("test*.org", input) + defer os.Remove(file.Name()) + + templ, err := Parse(file.Name()) + assertEqual(t, err, nil) + assertEqual(t, templ.Ext(), ".html") + + content, err := templ.Render() + assertEqual(t, err, nil) + expected := `
+

+My title +

+
+
+

+my Subtitle +

+
+
    +
  • list 1
  • +
  • list 2
  • +
+
+
+
+
+` + assertEqual(t, string(content), expected) } func TestRenderLiquidLayout(t *testing.T) {