atom/atom.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
package atom import ( "fmt" "log" "net/http" "git.j3s.sh/j3s.sh/thought" ) const maxFeed = 10 func Handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/atom+xml") posts, err := thought.Posts() if err != nil { log.Println(err) return } thought.DateSort(posts) if len(posts) > maxFeed { posts = posts[:maxFeed] } var updated string if len(posts) > 0 { updated = posts[0].Updated } fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title>j3s.sh</title> <link rel="self" href="https://j3s.sh/feed.atom" /> <link href="https://j3s.sh/" /> <updated>%s</updated> <author> <name>Jes Olson</name> </author> <id>https://j3s.sh/</id> `, updated) // maybe add p.Content here someday for _, p := range posts { fmt.Fprintf(w, ` <entry> <title>%s</title> <link href="%s"/> <id>%s</id> <updated>%s</updated> </entry> `, p.Title, p.Link, p.Link, p.Updated) } fmt.Fprint(w, ` </feed>`) }