Compare commits
No commits in common. "dd8ec0f911778bcae99228e22f028ebabb0a02b7" and "05d1d09dba3f6a5838873d37a732175b58555133" have entirely different histories.
dd8ec0f911
...
05d1d09dba
38
blog.css
38
blog.css
|
@ -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;}
|
||||
}
|
||||
|
|
@ -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 }}
|
||||
<3
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
106
genblog.go
106
genblog.go
|
@ -2,94 +2,90 @@ package main
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
const statsPath = "/usr/local/bin/stats"
|
||||
//const statsPath = "/home/vilmibm/bin/townstats"
|
||||
|
||||
//go:embed blog.tmpl.html
|
||||
var blogTmpl string
|
||||
const statsPath = "/town/bin/stats"
|
||||
|
||||
type newsEntry struct {
|
||||
Title string // Title of entry
|
||||
Pubdate string // Human readable date
|
||||
Content string // HTML of entry
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Username string
|
||||
Default bool
|
||||
Title string `json:"title"` // Title of entry
|
||||
Pubdate string `json:"pubdate"` // Human readable date
|
||||
Content string `json:"content"` // HTML of entry
|
||||
}
|
||||
|
||||
type tildeData struct {
|
||||
News []newsEntry
|
||||
Users []User
|
||||
ActiveUsers []string `json:"active_users"`
|
||||
News []newsEntry `json:"news"` // Collection of town news entries
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
hypertextDocument := getHeader()
|
||||
|
||||
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
|
||||
}
|
||||
for _, entry := range data.News {
|
||||
entryHTML, err := renderEntry(entry)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return false
|
||||
hypertextDocument += entryHTML
|
||||
}
|
||||
|
||||
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 += "."
|
||||
}
|
||||
}
|
||||
hypertextDocument += getFooter()
|
||||
|
||||
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 {
|
||||
return fmt.Errorf("failed to parse the blog template: %w", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
out := bytes.Buffer{}
|
||||
if err = t.Execute(&out, td); err != nil {
|
||||
return fmt.Errorf("failed to render blog template: %w", err)
|
||||
err = t.Execute(&out, entry)
|
||||
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) {
|
||||
|
@ -102,7 +98,7 @@ func stats() (*tildeData, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
var data tildeData
|
||||
data := tildeData{}
|
||||
|
||||
err = json.Unmarshal(sout.Bytes(), &data)
|
||||
if err != nil {
|
||||
|
|
|
@ -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/
|
10
index.html
10
index.html
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue