From 65a1834e9dbe5ff96f61defa1a7fd2b1748873fc Mon Sep 17 00:00:00 2001
From: Caleb Gardner
Date: Tue, 6 Aug 2024 18:35:34 -0500
Subject: [PATCH] Fixed some bugs pertaining to new pages
---
blog.go | 11 ++++++-----
internal/blog/blog.go | 2 +-
main.go | 16 +++++++++++-----
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/blog.go b/blog.go
index 474181b..222678d 100644
--- a/blog.go
+++ b/blog.go
@@ -11,15 +11,16 @@ import (
)
const (
- blogTitle = ""
+ blogTitle = ""
blogAuthor = "By %v
"
- blogCreate = "Written on: %v
%v
"
+ blogCreate = "Written on: %v
"
+ blogMain = "%v
"
authorInfo = `
+About the author:
 |
- %v%v |
+ %v%v |
`
)
@@ -60,7 +61,7 @@ func blogHandle(w http.ResponseWriter, r *http.Request, blog string) {
}
func blogElement(b *blog.Blog) (out string) {
- out = fmt.Sprintf(blogTitle, b.ID, b.Title)
+ out = fmt.Sprintf(blogTitle, b.ID, b.ID, b.Title)
auth, err := blogApp.GetAuthor(b)
if err == nil {
out += fmt.Sprintf(blogAuthor, auth.Name)
diff --git a/internal/blog/blog.go b/internal/blog/blog.go
index bf0e518..1a55136 100644
--- a/internal/blog/blog.go
+++ b/internal/blog/blog.go
@@ -52,7 +52,7 @@ func (b *BlogApp) Blog(ID string) (*Blog, error) {
return nil, res.Err()
}
var blog Blog
- err := res.Decode(blog)
+ err := res.Decode(&blog)
if err != nil {
return nil, err
}
diff --git a/main.go b/main.go
index 3ca93c8..498d258 100644
--- a/main.go
+++ b/main.go
@@ -6,6 +6,8 @@ import (
"flag"
"log"
"net/http"
+ "net/http/httputil"
+ "net/url"
"os"
"path"
"path/filepath"
@@ -85,13 +87,15 @@ func setupBackend(mux *http.ServeMux) {
}
func setupWebsite(mux *http.ServeMux) {
+ url, _ := url.Parse("https://localhost:30000")
+ mux.Handle("rpg.darkstorm.tech/", httputil.NewSingleHostReverseProxy(url))
mux.HandleFunc("GET /files", filesRequest)
mux.HandleFunc("GET /portfolio", portfolioRequest)
mux.HandleFunc("/", mainHandle)
}
func mainHandle(w http.ResponseWriter, r *http.Request) {
- path := path.Clean(r.URL.Path)
+ path := strings.TrimPrefix(path.Clean(r.URL.Path), "/")
if path == "/" || path == "" {
latestBlogsHandle(w, r)
return
@@ -102,10 +106,12 @@ func mainHandle(w http.ResponseWriter, r *http.Request) {
return
}
spl := strings.Split(path, "/")
- stat, err = os.Stat(filepath.Join(*webRoot, spl[0]))
- if err == nil && stat.IsDir() {
- http.ServeFile(w, r, filepath.Join(*webRoot, spl[0], "index.html"))
- return
+ if len(spl) > 1 {
+ stat, err = os.Stat(filepath.Join(*webRoot, spl[0]))
+ if err == nil && stat.IsDir() {
+ http.ServeFile(w, r, filepath.Join(*webRoot, spl[0], "index.html"))
+ return
+ }
}
blogHandle(w, r, path)
}