jlelse
/
hugo-micropub
Archived
1
Fork 0
This repository has been archived on 2020-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
hugo-micropub/post.go

36 lines
806 B
Go

package main
import (
"bytes"
"time"
)
func writeFrontMatter(entry *Entry) string {
var buff bytes.Buffer
t := time.Now().Format(time.RFC3339)
buff.WriteString("---\n")
if len(entry.Name) > 0 {
buff.WriteString("title: \"" + entry.Name + "\"\n")
}
buff.WriteString("date: " + t + "\n")
buff.WriteString("tags:\n")
for _, tag := range entry.Categories {
buff.WriteString("- " + tag + "\n")
}
buff.WriteString("indieweb:\n")
if len(entry.InReplyTo) > 0 {
buff.WriteString(" reply:\n link: " + entry.InReplyTo + "\n")
}
buff.WriteString("---\n")
return buff.String()
}
func WriteHugoPost(entry *Entry) string {
var buff bytes.Buffer
buff.WriteString(writeFrontMatter(entry))
if len(entry.Content) > 0 {
buff.WriteString(entry.Content + "\n")
}
return buff.String()
}