Compare commits

..

No commits in common. "dd8ec0f911778bcae99228e22f028ebabb0a02b7" and "05d1d09dba3f6a5838873d37a732175b58555133" have entirely different histories.

5 changed files with 57 additions and 143 deletions

View File

@ -1,38 +0,0 @@
body {
background-color: #E0B0FF;
font-family: monospace;
}
table {
width: 100%;
}
td {
width: 50%;
vertical-align:top;
}
#lights {
word-wrap:anywhere;
border: 4px solid black;
padding: 2px;
}
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;}
}

View File

@ -1,34 +0,0 @@
<!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 id="lights">
{{ .Lights }}
&lt;3
</p>
</td>
</tr>
</table>
</body>
</html>

View File

@ -2,94 +2,90 @@ package main
import ( import (
"bytes" "bytes"
_ "embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"sort"
"text/template" "text/template"
) )
const statsPath = "/usr/local/bin/stats" //const statsPath = "/home/vilmibm/bin/townstats"
//go:embed blog.tmpl.html const statsPath = "/town/bin/stats"
var blogTmpl string
type newsEntry struct { type newsEntry struct {
Title string // Title of entry Title string `json:"title"` // Title of entry
Pubdate string // Human readable date Pubdate string `json:"pubdate"` // Human readable date
Content string // HTML of entry Content string `json:"content"` // HTML of entry
}
type User struct {
Username string
Default bool
} }
type tildeData struct { type tildeData struct {
News []newsEntry News []newsEntry `json:"news"` // Collection of town news entries
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 { func _main() error {
data, err := stats() data, err := stats()
if err != nil { if err != nil {
return err return err
} }
type tmplData struct { hypertextDocument := getHeader()
News []newsEntry
Lights string
}
td := &tmplData{ for _, entry := range data.News {
News: data.News, entryHTML, err := renderEntry(entry)
Lights: "", if err != nil {
} return err
sort.Sort(ByName(data.Users))
isActive := func(username string) bool {
for _, u := range data.ActiveUsers {
if u == username {
return true
}
} }
return false hypertextDocument += entryHTML
} }
for _, u := range data.Users { hypertextDocument += getFooter()
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) fmt.Println(hypertextDocument)
return nil
}
func renderEntry(entry newsEntry) (string, error) {
t, err := template.New("news").Parse(`
<h2>{{.Title}}</h2>
<em>{{.Pubdate}}</em>
{{.Content}}
`)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse the blog template: %w", err) return "", err
} }
out := bytes.Buffer{} out := bytes.Buffer{}
if err = t.Execute(&out, td); err != nil { err = t.Execute(&out, entry)
return fmt.Errorf("failed to render blog template: %w", err) if err != nil {
return "", err
} }
fmt.Println(out.String()) return out.String(), nil
}
return nil func getHeader() string {
return `
<!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="style.css">
</head>
<body>
<h1>a web log for tilde town or at least what passes for one</h1>
`
}
func getFooter() string {
return `
</body>
</html>
`
} }
func stats() (*tildeData, error) { func stats() (*tildeData, error) {
@ -102,7 +98,7 @@ func stats() (*tildeData, error) {
return nil, err return nil, err
} }
var data tildeData data := tildeData{}
err = json.Unmarshal(sout.Bytes(), &data) err = json.Unmarshal(sout.Bytes(), &data)
if err != nil { if err != nil {

View File

@ -1,10 +0,0 @@
#!/bin/bash
set -e
#/town/src/townstats/townstats | /usr/local/bin/mustache /town/src/tildetown-scripts/tildetown/templates/frontpage.html > /var/www/tilde.town/index.html
cd /town/src/tilde.town
/usr/bin/go run genblog.go > blog.html
/usr/bin/go run genusers.go > users.html
/bin/cp index.html blog.html users.html blog.css style.css /var/www/tilde.town/

File diff suppressed because one or more lines are too long