hugo-micropub/post.go

36 lines
806 B
Go
Raw Normal View History

2019-11-07 10:00:24 +00:00
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()
}