Fixed some bugs pertaining to new pages

This commit is contained in:
Caleb Gardner
2024-08-06 18:35:34 -05:00
parent f99c9bd2fb
commit 65a1834e9d
3 changed files with 18 additions and 11 deletions
+6 -5
View File
@@ -11,15 +11,16 @@ import (
) )
const ( const (
blogTitle = "<h1 class='blog-title'><a href='%v'>%v</a></h1>" blogTitle = "<h1 class='blog-title'><a href='%v' onclick=\"return setToPath('%v')\" style='text-decoration:none'>%v</a></h1>"
blogAuthor = "<h4 class='blog-author'><i><b>By %v</b></i></h4>" blogAuthor = "<h4 class='blog-author'><i><b>By %v</b></i></h4>"
blogCreate = "<h5 class='blog-time'><i>Written on: %v</i></h5" blogCreate = "<h5 class='blog-time'><i>Written on: %v</i></h5>"
blogMain = "<p class='blog'>%v</p>" blogMain = "<div class='blog'>%v</div>"
authorInfo = ` authorInfo = `
<h2 class='blog-author-info'>About the author:</h2>
<table><tr> <table><tr>
<td><img src="%v" alt="%v" class='author-pic'></td> <td><img src="%v" alt="%v" class='author-pic'></td>
<td><h2 class="author-title">%v</h2>%v</td> <td><h3 class="author-title">%v</h3>%v</td>
</tr></table>` </tr></table>`
) )
@@ -60,7 +61,7 @@ func blogHandle(w http.ResponseWriter, r *http.Request, blog string) {
} }
func blogElement(b *blog.Blog) (out 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) auth, err := blogApp.GetAuthor(b)
if err == nil { if err == nil {
out += fmt.Sprintf(blogAuthor, auth.Name) out += fmt.Sprintf(blogAuthor, auth.Name)
+1 -1
View File
@@ -52,7 +52,7 @@ func (b *BlogApp) Blog(ID string) (*Blog, error) {
return nil, res.Err() return nil, res.Err()
} }
var blog Blog var blog Blog
err := res.Decode(blog) err := res.Decode(&blog)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+7 -1
View File
@@ -6,6 +6,8 @@ import (
"flag" "flag"
"log" "log"
"net/http" "net/http"
"net/http/httputil"
"net/url"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@@ -85,13 +87,15 @@ func setupBackend(mux *http.ServeMux) {
} }
func setupWebsite(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 /files", filesRequest)
mux.HandleFunc("GET /portfolio", portfolioRequest) mux.HandleFunc("GET /portfolio", portfolioRequest)
mux.HandleFunc("/", mainHandle) mux.HandleFunc("/", mainHandle)
} }
func mainHandle(w http.ResponseWriter, r *http.Request) { 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 == "" { if path == "/" || path == "" {
latestBlogsHandle(w, r) latestBlogsHandle(w, r)
return return
@@ -102,10 +106,12 @@ func mainHandle(w http.ResponseWriter, r *http.Request) {
return return
} }
spl := strings.Split(path, "/") spl := strings.Split(path, "/")
if len(spl) > 1 {
stat, err = os.Stat(filepath.Join(*webRoot, spl[0])) stat, err = os.Stat(filepath.Join(*webRoot, spl[0]))
if err == nil && stat.IsDir() { if err == nil && stat.IsDir() {
http.ServeFile(w, r, filepath.Join(*webRoot, spl[0], "index.html")) http.ServeFile(w, r, filepath.Join(*webRoot, spl[0], "index.html"))
return return
} }
}
blogHandle(w, r, path) blogHandle(w, r, path)
} }