Working on the actual web pages
This commit is contained in:
@@ -1,6 +1,30 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
blogTitle = "<h2 class='blog-title'>%v</h2>"
|
blogTitle = "<h2 class='blog-title'>%v</h2>"
|
||||||
blogAuthor = "<h4 class='blog-author'><i>%v</i></h4>"
|
blogAuthor = "<h4 class='blog-author'><i>%v</i></h4>"
|
||||||
|
blogMain = "<p class='blog'>%v</p>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func latestBlogsHandle(w http.ResponseWriter, r *http.Request) {}
|
||||||
|
|
||||||
|
func blogHandle(w http.ResponseWriter, r *http.Request, blog string) {
|
||||||
|
bl, err := blogApp.Blog(blog)
|
||||||
|
if err != nil {
|
||||||
|
if err == backend.ErrNotFound {
|
||||||
|
w.WriteHeader(404)
|
||||||
|
sendIndexWithContent(w, "Page not found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
sendIndexWithContent(w, "Error getting page")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||||
"github.com/CalebQ42/darkstorm-server/internal/backend/db"
|
"github.com/CalebQ42/darkstorm-server/internal/backend/db"
|
||||||
@@ -88,5 +91,21 @@ func setupWebsite(mux *http.ServeMux) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mainHandle(w http.ResponseWriter, r *http.Request) {
|
func mainHandle(w http.ResponseWriter, r *http.Request) {
|
||||||
|
path := path.Clean(r.URL.Path)
|
||||||
|
if path == "/" || path == "" {
|
||||||
|
latestBlogsHandle(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stat, err := os.Stat(filepath.Join(*webRoot, path))
|
||||||
|
if err == nil && !stat.IsDir() {
|
||||||
|
http.ServeFile(w, r, filepath.Join(*webRoot, path))
|
||||||
|
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
|
||||||
|
}
|
||||||
|
blogHandle(w, r, path)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,13 @@ func portfolioRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
sendIndexWithContent(w, "Error getting portfolio")
|
sendIndexWithContent(w, "Error getting portfolio")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
langs := make(map[string]struct{})
|
||||||
out := ""
|
out := ""
|
||||||
for _, p := range proj {
|
for _, p := range proj {
|
||||||
out += fmt.Sprintf(portfolioTitle, p.Title)
|
out += fmt.Sprintf(portfolioTitle, p.Title)
|
||||||
out += fmt.Sprintf(portfolioLink, p.Repository, p.Repository)
|
out += fmt.Sprintf(portfolioLink, p.Repository, p.Repository)
|
||||||
for _, l := range p.Languages {
|
for _, l := range p.Languages {
|
||||||
|
langs[l.Language] = struct{}{}
|
||||||
out += fmt.Sprintf(portfolioLanguage, l.Language, l.Dates)
|
out += fmt.Sprintf(portfolioLanguage, l.Language, l.Dates)
|
||||||
}
|
}
|
||||||
out += fmt.Sprintf(portfolioDesc, p.Description)
|
out += fmt.Sprintf(portfolioDesc, p.Description)
|
||||||
|
|||||||
@@ -28,7 +28,3 @@ func sendIndexWithContent(w http.ResponseWriter, content string) {
|
|||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
w.Write(dat)
|
w.Write(dat)
|
||||||
}
|
}
|
||||||
|
|
||||||
func blogHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user