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

@ -1,12 +1,28 @@
<!DOCTYPE html>
<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>
<body>
{{range $i, $board := .Boards}}
{{if $i}}
<hr>
{{end}}
{{.Board}}
{{end}}
<div id="containers">
</div>
</body>
</html>

Loading…
Cancel
Save