diff --git a/blog.go b/blog.go index 878ec74..687f6da 100644 --- a/blog.go +++ b/blog.go @@ -1,6 +1,30 @@ package main +import ( + "net/http" + + "github.com/CalebQ42/darkstorm-server/internal/backend" +) + const ( blogTitle = "
%v
" ) + +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 + } + +} diff --git a/main.go b/main.go index 916a233..5cfaedd 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/portfolio.go b/portfolio.go index 9a338dd..a9b6d1d 100644 --- a/portfolio.go +++ b/portfolio.go @@ -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) diff --git a/web.go b/web.go index 951d47d..755b65c 100644 --- a/web.go +++ b/web.go @@ -28,7 +28,3 @@ func sendIndexWithContent(w http.ResponseWriter, content string) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Write(dat) } - -func blogHandler(w http.ResponseWriter, r *http.Request) { - //TODO -}