forked from Colelyman/gozette
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.go
62 lines (52 loc) · 1.4 KB
/
post.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"bytes"
"time"
)
const (
timeZone = "MST"
timeFormat = time.RFC822
)
func writeTomlHugoHeader(entry *Entry) string {
var buff bytes.Buffer
location, _ := time.LoadLocation(timeZone)
t := time.Now().In(location).Format(timeFormat)
// write the front matter in toml format
buff.WriteString("+++\n")
if len(entry.Name) == 0 {
buff.WriteString("title = \"\"\n")
} else {
buff.WriteString("title = \"" + entry.Name + "\"\n")
}
buff.WriteString("date = \"" + t + "\"\n")
buff.WriteString("categories = [\"Micro\"]\n")
buff.WriteString("tags = [")
for i, tag := range entry.Categories {
buff.WriteString("\"" + tag + "\"")
if i < len(entry.Categories)-1 {
buff.WriteString(", ")
}
}
buff.WriteString("]\n")
buff.WriteString("slug = \"" + entry.Slug + "\"\n")
buff.WriteString("+++\n")
return buff.String()
}
func WriteHugoPost(entry *Entry) (string, string) {
var buff bytes.Buffer
buff.WriteString(writeTomlHugoHeader(entry))
if len(entry.In_reply_to) > 0 {
buff.WriteString("↪️ replying to: " + entry.In_reply_to + "\n")
}
if len(entry.Like_of) > 0 {
buff.WriteString("👍: " + entry.Like_of + "\n")
}
if len(entry.Repost_of) > 0 {
buff.WriteString("🔁 repost of: " + entry.Repost_of + "\n")
}
if len(entry.Content) > 0 {
buff.WriteString(entry.Content + "\n")
}
path := entry.Slug + ".md"
return "site/content/micro/" + path, buff.String()
}