bunch of blog updates

trunk
vilmibm 7 months ago
parent 8be261647c
commit 8b120e2112
  1. 36
      blog.css
  2. 34
      blog.tmpl.html
  3. 60
      genblog.go

@ -0,0 +1,36 @@
body {
background-color: #E0B0FF;
font-family: monospace;
}
table {
width: 100%;
}
td {
width: 50%;
vertical-align:top;
}
td p {
word-wrap:anywhere;
}
a {
text-decoration: none;
font-weight:bold;
color:blueviolet;
}
a:hover {
animation: rainbow 1s infinite;
}
@keyframes rainbow {
20%{color: red;}
40%{color: orange;}
60%{color: yellow;}
80%{color: green;}
100%{color: blue;}
}

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>web log of tilde town</title>
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<link rel="stylesheet" href="blog.css">
</head>
<body>
<table>
<tr>
<td>
<h1>a world wide web log for tilde town!</h1>
{{ range .News }}
<h2>{{.Title}}</h2>
<em>{{.Pubdate}}</em>
{{.Content}}
{{ end }}
</td>
<td>
<h1>the town lights</h1>
<p>a dot is a user. + means they've established a webpage. * means they are logged into
the server.</p>
<p>
{{ .Lights }}
&lt;3
</p>
</td>
</tr>
</table>
</body>
</html>

@ -7,37 +7,83 @@ import (
"fmt"
"os"
"os/exec"
"sort"
"text/template"
)
const statsPath = "/town/bin/stats"
const statsPath = "/usr/local/bin/stats"
//go:embed blog.tmpl.html
var blogTmpl string
type newsEntry struct {
Title string `json:"title"` // Title of entry
Pubdate string `json:"pubdate"` // Human readable date
Content string `json:"content"` // HTML of entry
Title string // Title of entry
Pubdate string // Human readable date
Content string // HTML of entry
}
type User struct {
Username string
Default bool
}
type tildeData struct {
News []newsEntry `json:"news"` // Collection of town news entries
News []newsEntry
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 {
return err
}
type tmplData struct {
News []newsEntry
Lights string
}
td := &tmplData{
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("blog").Parse(blogTmpl)
if err != nil {
return fmt.Errorf("failed to parse the blog template: %w", err)
}
out := bytes.Buffer{}
if err = t.Execute(&out, data); err != nil {
if err = t.Execute(&out, td); err != nil {
return fmt.Errorf("failed to render blog template: %w", err)
}
@ -56,7 +102,7 @@ func stats() (*tildeData, error) {
return nil, err
}
data := tildeData{}
var data tildeData
err = json.Unmarshal(sout.Bytes(), &data)
if err != nil {

Loading…
Cancel
Save