diff options
| -rw-r--r-- | main.go | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "github.com/adrg/frontmatter" "github.com/gomarkdown/markdown" ) @@ -17,6 +18,10 @@ type Page struct { Content template.HTML } +type Frontmatter struct { + Title string `yaml:"title"` +} + func main() { contentDir := "./content" outputDir := "./output" @@ -33,9 +38,9 @@ func main() { if strings.HasSuffix(d.Name(), ".md") { fmt.Println("Processing:", path) - htmlContent := convertToHtml(path) + title, htmlContent := convertToHtml(path) newPage := Page{ - Title: "hello", // you can customize this later + Title: title, // you can customize this later Content: template.HTML(htmlContent), } @@ -81,12 +86,16 @@ func main() { fmt.Println("All files processed!") } -func convertToHtml(path string) []byte { +func convertToHtml(path string) (string, []byte) { md, err := os.ReadFile(path) + var matter Frontmatter + rest, err := frontmatter.Parse(strings.NewReader(string(md)), &matter) if err != nil { log.Fatalf("Error reading %s: %s", path, err) } - html := markdown.ToHTML(md, nil, nil) - return html + fmt.Printf("Found post %s\n", matter.Title) + + html := markdown.ToHTML(rest, nil, nil) + return matter.Title, html } |
