Add feed generating capabilities #1

Merged
vilmibm merged 3 commits from acdw/tilde.town:trunk into trunk 2022-09-10 00:27:19 +00:00
Showing only changes of commit fc7ec910c5 - Show all commits

View File

@ -7,7 +7,6 @@ import (
"fmt"
"os"
"os/exec"
"sort"
"text/template"
)
@ -22,23 +21,10 @@ type newsEntry struct {
Content string // HTML of entry
}
type User struct {
Username string
Default bool
}
type tildeData struct {
News []newsEntry
acdw marked this conversation as resolved
Review

this struct can be deleted

this struct can be deleted
Users []User
ActiveUsers []string `json:"active_users"`
}
type ByName []User
func (n ByName) Len() int { return len(n) }
func (n ByName) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
func (n ByName) Less(i, j int) bool { return n[i].Username < n[j].Username }
func _main() error {
data, err := stats()
if err != nil {
@ -47,34 +33,10 @@ func _main() error {
acdw marked this conversation as resolved
Review

can delete

can delete
type tmplData struct {
News []newsEntry
Lights string
}
acdw marked this conversation as resolved
Review

can delete

can delete
td := &tmplData{
acdw marked this conversation as resolved
Review

can delete these three functions

can delete these three functions
News: data.News,
Lights: "",
}
sort.Sort(ByName(data.Users))
isActive := func(username string) bool {
for _, u := range data.ActiveUsers {
if u == username {
return true
}
}
return false
}
for _, u := range data.Users {
if isActive(u.Username) {
td.Lights += fmt.Sprintf("<a href=\"/~%s\">*</a>", u.Username)
} else if !u.Default {
td.Lights += fmt.Sprintf("<a href=\"/~%s\">+</a>", u.Username)
} else {
td.Lights += "."
}
}
t, err := template.New("feed").Parse(feedTmpl)