hugo-micropub/post.go

42 lines
972 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.title) > 0 {
buff.WriteString("title: \"" + entry.title + "\"\n")
}
buff.WriteString("date: " + t + "\n")
buff.WriteString("tags:\n")
for _, tag := range entry.tags {
buff.WriteString("- " + tag + "\n")
}
if len(entry.link) > 0 {
buff.WriteString("externalURL: " + entry.link + "\n")
}
buff.WriteString("indieweb:\n")
if len(entry.replyLink) > 0 {
buff.WriteString(" reply:\n link: " + entry.replyLink + "\n")
if len(entry.replyTitle) > 0 {
buff.WriteString(" title: " + entry.replyTitle + "\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)
}
return buff.String()
}