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

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