Echo!
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/uptrace/bunrouter"
|
||||
"github.com/labstack/echo/v4"
|
||||
"goth.stack/lib"
|
||||
)
|
||||
|
||||
@ -16,19 +16,19 @@ type BlogProps struct {
|
||||
Posts []lib.CardLink
|
||||
}
|
||||
|
||||
func Blog(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
func Blog(c echo.Context) error {
|
||||
var posts []lib.CardLink
|
||||
|
||||
files, err := os.ReadDir("./content/")
|
||||
if err != nil {
|
||||
http.Error(w, "There was an issue finding posts!", http.StatusInternalServerError)
|
||||
http.Error(c.Response().Writer, "There was an issue finding posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
frontMatter, err := lib.ExtractFrontMatter(file, "./content/")
|
||||
if err != nil {
|
||||
http.Error(w, "There was an issue rendering the posts!", http.StatusInternalServerError)
|
||||
http.Error(c.Response().Writer, "There was an issue rendering the posts!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -62,5 +62,5 @@ func Blog(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
partials := []string{"header", "navitems", "cardlinks"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(w, "base", partials, props)
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
||||
|
@ -2,9 +2,8 @@ package pages
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
|
||||
"github.com/uptrace/bunrouter"
|
||||
"github.com/labstack/echo/v4"
|
||||
"goth.stack/lib"
|
||||
)
|
||||
|
||||
@ -16,7 +15,7 @@ type HomeProps struct {
|
||||
SupportLink string
|
||||
}
|
||||
|
||||
func Home(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
func Home(c echo.Context) error {
|
||||
socials := []lib.IconLink{
|
||||
{
|
||||
Name: "Email",
|
||||
@ -135,6 +134,5 @@ func Home(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return lib.RenderTemplate(w, "base", partials, props)
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
|
||||
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
|
||||
"github.com/uptrace/bunrouter"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/yuin/goldmark"
|
||||
highlighting "github.com/yuin/goldmark-highlighting/v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
@ -21,26 +21,26 @@ type PostProps struct {
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func Post(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
postName := req.Param("post")
|
||||
func Post(c echo.Context) error {
|
||||
postName := c.Param("post")
|
||||
|
||||
filePath := "content/" + postName + ".md"
|
||||
|
||||
md, err := os.ReadFile(filePath)
|
||||
if err != nil {
|
||||
http.Error(w, "This post does not exist!", http.StatusNotFound)
|
||||
http.Error(c.Response().Writer, "This post does not exist!", http.StatusNotFound)
|
||||
return nil
|
||||
}
|
||||
|
||||
frontmatterBytes, content, err := lib.SplitFrontmatter(md)
|
||||
if err != nil {
|
||||
http.Error(w, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
var frontmatter lib.FrontMatter
|
||||
if err := yaml.Unmarshal(frontmatterBytes, &frontmatter); err != nil {
|
||||
http.Error(w, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ func Post(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
)
|
||||
|
||||
if err := markdown.Convert(content, &buf); err != nil {
|
||||
http.Error(w, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
http.Error(c.Response().Writer, "There was an issue rendering this post!", http.StatusInternalServerError)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -72,5 +72,5 @@ func Post(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(w, "post", partials, props)
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, props)
|
||||
}
|
||||
|
@ -1,16 +1,14 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/uptrace/bunrouter"
|
||||
"github.com/labstack/echo/v4"
|
||||
"goth.stack/lib"
|
||||
)
|
||||
|
||||
func SSEDemo(w http.ResponseWriter, req bunrouter.Request) error {
|
||||
func SSEDemo(c echo.Context) error {
|
||||
// Specify the partials used by this page
|
||||
partials := []string{"header", "navitems"}
|
||||
|
||||
// Render the template
|
||||
return lib.RenderTemplate(w, "base", partials, nil)
|
||||
return lib.RenderTemplate(c.Response().Writer, "base", partials, nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user