Add feed generating capabilities #1
							
								
								
									
										38
									
								
								genfeed.go
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								genfeed.go
									
									
									
									
									
								
							| @ -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
					
				 | ||||
| 	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
					
				 
				
					
						vilmibm
						commented  can delete can delete | ||||
| 	type tmplData struct { | ||||
| 		News   []newsEntry | ||||
| 		Lights string | ||||
| 	} | ||||
| 
					
					acdw marked this conversation as resolved
					
				 
				
					
						vilmibm
						commented  can delete can delete | ||||
| 
 | ||||
| 	td := &tmplData{ | ||||
| 
					
					acdw marked this conversation as resolved
					
				 
				
					
						vilmibm
						commented  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) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	
this struct can be deleted