main
Bill Mill 2 years ago
parent 18314b65c5
commit 3c5b876ebd
  1. 18
      server/main.go
  2. 28
      server/templates/index.html

@ -2,9 +2,7 @@
// TODO: // TODO:
// * wipe expired posts // * wipe expired posts
// * add difficulty checking // * add difficulty checking
// * check post mtime // * check that the body contains a proper last-modified tag
// * that the header is valid (and 409 if not)
// * that the body contains a proper last-modified tag
// * implement peer sharing and receiving // * implement peer sharing and receiving
// * display HTML safely, and in shadow DOMs // * display HTML safely, and in shadow DOMs
// * right now we just don't allow actual HTML, which is of course // * right now we just don't allow actual HTML, which is of course
@ -16,14 +14,15 @@ import (
"crypto/ed25519" "crypto/ed25519"
"database/sql" "database/sql"
"encoding/hex" "encoding/hex"
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"html/template"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"os" "os"
"strings" "strings"
"text/template"
"time" "time"
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
@ -330,10 +329,17 @@ func (s *Spring83Server) showBoard(w http.ResponseWriter, r *http.Request) {
return return
} }
boardBytes, err := json.Marshal(boards)
if err != nil {
log.Printf(err.Error())
http.Error(w, "Unable to marshal boards", http.StatusInternalServerError)
return
}
data := struct { data := struct {
Boards []Board Boards string
}{ }{
Boards: boards, Boards: string(boardBytes),
} }
s.homeTemplate.Execute(w, data) s.homeTemplate.Execute(w, data)

@ -1,12 +1,28 @@
<!DOCTYPE html> <!DOCTYPE html>
<html><head><title>Spring83</title> <html><head><title>Spring83</title>
<style>
.board {
border: 1px solid black;
margin: 10px;
}
</style>
<script>
window.addEventListener("DOMContentLoaded", (_evt) => {
const boards = {{.Boards}}
const divs = boards.map(board => {
return `<div id="b${board.Key}" class="board"></div>\n`
});
document.querySelector("#containers").innerHTML = divs.join("\n");
boards.forEach(board => {
const container = document.querySelector(`#b${board.Key}`);
const shadow = container.attachShadow({mode: 'closed'});
shadow.innerHTML = board.Board;
});
});
</script>
</head> </head>
<body> <body>
{{range $i, $board := .Boards}} <div id="containers">
{{if $i}} </div>
<hr>
{{end}}
{{.Board}}
{{end}}
</body> </body>
</html> </html>

Loading…
Cancel
Save