Fixed some bugs pertaining to new pages
This commit is contained in:
@@ -11,15 +11,16 @@ import (
|
||||
)
|
||||
|
||||
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>"
|
||||
blogCreate = "<h5 class='blog-time'><i>Written on: %v</i></h5"
|
||||
blogMain = "<p class='blog'>%v</p>"
|
||||
blogCreate = "<h5 class='blog-time'><i>Written on: %v</i></h5>"
|
||||
blogMain = "<div class='blog'>%v</div>"
|
||||
|
||||
authorInfo = `
|
||||
<h2 class='blog-author-info'>About the author:</h2>
|
||||
<table><tr>
|
||||
<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>`
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user