Compare commits

..

5 Commits

Author SHA1 Message Date
vilmibm dd8ec0f911 add a copy of the script 2022-09-08 18:30:58 +00:00
vilmibm ae0bbce795 tweaks 2022-04-25 22:23:07 +00:00
vilmibm 8b120e2112 bunch of blog updates 2022-04-25 22:20:11 +00:00
vilmibm 8be261647c switch to embedding blog template 2022-04-25 21:22:10 +00:00
eq 355af071eb update language and basic accessibility
we add some aria tags. (this is not enough but it is what i have time
for presently.) we change "homestead" to "good time" because we don't
want to liken our little computer guy to american settler colonialism.
2022-03-12 18:36:18 +00:00
5 changed files with 144 additions and 58 deletions

38
blog.css 100644
View File

@ -0,0 +1,38 @@
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;}
}

34
blog.tmpl.html 100644
View File

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

View File

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

10
generate_homepage 100644
View File

@ -0,0 +1,10 @@
#!/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