working quite well
This commit is contained in:
		
							parent
							
								
									3e539dc1dd
								
							
						
					
					
						commit
						458f87066f
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,2 @@ | ||||
| blackout | ||||
| *.swp | ||||
							
								
								
									
										24
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								main.go
									
									
									
									
									
								
							| @ -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 | ||||
|  | ||||
							
								
								
									
										56
									
								
								templates/index.tmpl
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								templates/index.tmpl
									
									
									
									
									
										Normal 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> | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user