working quite well

trunk
vilmibm 2023-07-13 04:59:01 +00:00
parent 3e539dc1dd
commit 458f87066f
3 changed files with 82 additions and 0 deletions

2
.gitignore vendored 100644
View File

@ -0,0 +1,2 @@
blackout
*.swp

24
main.go
View File

@ -4,6 +4,8 @@ import (
"log"
"math/big"
"net/http"
"regexp"
"strings"
"crypto/rand"
"database/sql"
@ -29,6 +31,7 @@ func connectDB() (*sql.DB, error) {
type chunk struct {
Chunk string
Tokens []string
Name string
Author string
}
@ -39,6 +42,8 @@ func main() {
randMax := big.NewInt(maxID)
spaceRE := regexp.MustCompile(`[\t\v\f\r ]+`)
r.GET("/", func(c *gin.Context) {
db, err := connectDB()
if err != nil {
@ -69,6 +74,25 @@ func main() {
c.String(http.StatusInternalServerError, "oh no.")
}
dest.Tokens = []string{}
for _, t := range spaceRE.Split(dest.Chunk, -1) {
if t == "" {
continue
}
if strings.Contains(t, "\n") {
sp := strings.Split(t, "\n")
for x, s := range sp {
nl := "\n"
if x == len(sp)-1 {
nl = ""
}
dest.Tokens = append(dest.Tokens, s+nl)
}
} else {
dest.Tokens = append(dest.Tokens, t)
}
}
c.HTML(http.StatusOK, "index.tmpl", dest)
})
r.Run() // 8080

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<title>blackout engine</title>
</head>
<body>
<style>
body {
background-color: black;
}
.centering {
display: flex;
justify-content: center;
align-items: center;
text-align: left;
min-height: 95vh;
margin-left: 25%;
width: 50%;
}
#paper {
background-color: white;
padding: 2em;
font-size: 150%;
}
.data {
display: none;
}
.black {
background-color: black;
}
#paper span:hover {
background-color: white;
}
</style>
<div class="centering">
<div id="paper">
{{- range .Tokens -}}
<span class="black"> {{.}} </span>
{{- end -}}
</div>
<script>
document.querySelectorAll("#paper span").forEach(span =>
span.onclick = () => span.classList.toggle("black")
);
</script>
</div>
<div class="data" id="chunk">{{.Chunk}}</div>
<div class="data" id="bookTitle">{{.Name}}</div>
<div class="data" id="bookAuthor">{{.Author}}</div>
</body>
</html>