try page embed
This commit is contained in:
parent
be89141c06
commit
513d0e57ce
10 changed files with 29 additions and 26 deletions
|
|
@ -12,8 +12,10 @@ COPY go.mod go.sum ./
|
||||||
# Download dependencies
|
# Download dependencies
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
|
|
||||||
COPY main.go .
|
COPY ./*.go .
|
||||||
COPY internal ./internal
|
COPY internal ./internal
|
||||||
|
COPY pages ./pages
|
||||||
|
|
||||||
|
|
||||||
# Enable CGO for go-sqlite3
|
# Enable CGO for go-sqlite3
|
||||||
ENV CGO_ENABLED=1
|
ENV CGO_ENABLED=1
|
||||||
|
|
@ -26,7 +28,6 @@ WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/main .
|
COPY --from=builder /app/main .
|
||||||
COPY keys ./keys
|
COPY keys ./keys
|
||||||
COPY pages ./pages
|
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package gemlog
|
package gemlog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -51,16 +52,14 @@ func (g *Gemlog) HandleRequest(w gemini.ResponseWriter, req *gemini.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed gemlog.gmi
|
||||||
|
var pageContnet string
|
||||||
|
|
||||||
func (g *Gemlog) serveIndex(w gemini.ResponseWriter, req *gemini.Request) {
|
func (g *Gemlog) serveIndex(w gemini.ResponseWriter, req *gemini.Request) {
|
||||||
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
||||||
|
|
||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
page, err := os.ReadFile("./pages/gemlog.gmi")
|
content.Write([]byte(pageContnet))
|
||||||
if err != nil {
|
|
||||||
slog.Error("Problem reading gemlog page", "error", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content.Write(page)
|
|
||||||
content.WriteString("\n")
|
content.WriteString("\n")
|
||||||
|
|
||||||
posts, err := gemlog.ListGemLogs(g.config)
|
posts, err := gemlog.ListGemLogs(g.config)
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
_ "embed"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -215,15 +215,13 @@ func censorString(s string) string {
|
||||||
return string(masked)
|
return string(masked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed guestbook.gmi
|
||||||
|
var pageContnet string
|
||||||
|
|
||||||
func (book *GuestBook) serveIndex(w gemini.ResponseWriter, req *gemini.Request) {
|
func (book *GuestBook) serveIndex(w gemini.ResponseWriter, req *gemini.Request) {
|
||||||
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
page, err := os.ReadFile("./pages/guestbook.gmi")
|
content.Write([]byte(pageContnet))
|
||||||
if err != nil {
|
|
||||||
slog.Error("Problem reading guestbook.gmi", "error", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content.Write(page)
|
|
||||||
content.WriteString("\n")
|
content.WriteString("\n")
|
||||||
|
|
||||||
rows, err := book.db.Query("SELECT id, name, approved, created_at, message FROM guestbook ORDER BY created_at DESC")
|
rows, err := book.db.Query("SELECT id, name, approved, created_at, message FROM guestbook ORDER BY created_at DESC")
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package microblog
|
package microblog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gemini_site/internal/pocketbase"
|
"gemini_site/internal/pocketbase"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -216,6 +216,9 @@ func drawPost(builder *strings.Builder, p post) {
|
||||||
// p.Timestamp.Format("2006-01-02 15:04")))
|
// p.Timestamp.Format("2006-01-02 15:04")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed microblog.gmi
|
||||||
|
var pageContnet string
|
||||||
|
|
||||||
// serveBlogIndex serves the main blog page with recent posts
|
// serveBlogIndex serves the main blog page with recent posts
|
||||||
func (mb *MicroBlog) serveIndex(w gemini.ResponseWriter, req *gemini.Request, pageNum int) {
|
func (mb *MicroBlog) serveIndex(w gemini.ResponseWriter, req *gemini.Request, pageNum int) {
|
||||||
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
||||||
|
|
@ -225,12 +228,7 @@ func (mb *MicroBlog) serveIndex(w gemini.ResponseWriter, req *gemini.Request, pa
|
||||||
// content.WriteString("Here are my microblog posts from various plantforms\n")
|
// content.WriteString("Here are my microblog posts from various plantforms\n")
|
||||||
// Read and include the contents of ../../pages/microblog.gmi
|
// Read and include the contents of ../../pages/microblog.gmi
|
||||||
if pageNum == 1 {
|
if pageNum == 1 {
|
||||||
page, err := os.ReadFile("./pages/microblog.gmi")
|
content.Write([]byte(pageContnet))
|
||||||
if err != nil {
|
|
||||||
slog.Error("Problem reading microblog page", "error", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
content.Write(page)
|
|
||||||
content.WriteString("\n")
|
content.WriteString("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
10
main.go
10
main.go
|
|
@ -2,6 +2,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
_ "embed"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
@ -21,6 +23,9 @@ import (
|
||||||
gemini "github.com/kulak/gemini"
|
gemini "github.com/kulak/gemini"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed home.gmi
|
||||||
|
var homePageContent string
|
||||||
|
|
||||||
type MainHandler struct {
|
type MainHandler struct {
|
||||||
blog microblog.Handler
|
blog microblog.Handler
|
||||||
gemlog gemlog.Handler
|
gemlog gemlog.Handler
|
||||||
|
|
@ -58,11 +63,8 @@ func (h MainHandler) ServeGemini(w gemini.ResponseWriter, req *gemini.Request) {
|
||||||
switch req.URL.Path {
|
switch req.URL.Path {
|
||||||
case "/":
|
case "/":
|
||||||
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
w.WriteStatusMsg(gemini.StatusSuccess, "text/gemini")
|
||||||
data, err := os.ReadFile("pages/home.gmi")
|
|
||||||
requireNoError(err)
|
|
||||||
page := string(data)
|
|
||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
content.WriteString(page)
|
content.WriteString(homePageContent)
|
||||||
content.WriteString(fmt.Sprintf("\n\n------ stats: total requests served %d, this page %d ------", h.counter.GetTotal(), h.counter.Get(req.URL.Path)))
|
content.WriteString(fmt.Sprintf("\n\n------ stats: total requests served %d, this page %d ------", h.counter.GetTotal(), h.counter.Get(req.URL.Path)))
|
||||||
w.WriteBody([]byte(content.String()))
|
w.WriteBody([]byte(content.String()))
|
||||||
// case "/user":
|
// case "/user":
|
||||||
|
|
|
||||||
5
tasks.txt
Normal file
5
tasks.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
task: add hexidecimal numbering to gemlog
|
||||||
|
|
||||||
|
-----------DONE LINE-----------
|
||||||
|
|
||||||
|
DONE task: add request counter
|
||||||
Loading…
Add table
Add a link
Reference in a new issue