Working on the actual web pages
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||
)
|
||||
|
||||
const (
|
||||
blogTitle = "<h2 class='blog-title'>%v</h2>"
|
||||
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"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/CalebQ42/darkstorm-server/internal/backend"
|
||||
"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) {
|
||||
|
||||
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")
|
||||
return
|
||||
}
|
||||
langs := make(map[string]struct{})
|
||||
out := ""
|
||||
for _, p := range proj {
|
||||
out += fmt.Sprintf(portfolioTitle, p.Title)
|
||||
out += fmt.Sprintf(portfolioLink, p.Repository, p.Repository)
|
||||
for _, l := range p.Languages {
|
||||
langs[l.Language] = struct{}{}
|
||||
out += fmt.Sprintf(portfolioLanguage, l.Language, l.Dates)
|
||||
}
|
||||
out += fmt.Sprintf(portfolioDesc, p.Description)
|
||||
|
||||
Reference in New Issue
Block a user