diff --git a/cmd/main.go b/cmd/main.go index 846e242..08dc344 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,10 +1,10 @@ package main import ( + "github.com/gofor-little/env" "github.com/labstack/echo/v4" "github.com/lorenzhohermuth/portfolio/internal/handler" - "github.com/lorenzhohermuth/portfolio/internal/mdparser" - "github.com/gofor-little/env" + "github.com/lorenzhohermuth/portfolio/view/component" ) func main() { @@ -15,11 +15,11 @@ func main() { app := echo.New() index := 0 - projects := mdparser.GetProjects() - h := handler.Homehandler{index, projects} + var projects []component.CarouselEntry + h := handler.Homehandler{Index: index, Entrys: &projects} app.GET("/", h.HandleUserShow) - app.POST("/carousel/next", handler.HtmxCarouselHandler{&index, 1, projects}.HandlerCarouselUpdate) - app.POST("/carousel/previous", handler.HtmxCarouselHandler{&index, -1, projects}.HandlerCarouselUpdate) + app.POST("/carousel/next", handler.HtmxCarouselHandler{Index: &index,Direction: 1,Entrys: &projects}.HandlerCarouselUpdate) + app.POST("/carousel/previous", handler.HtmxCarouselHandler{Index: &index, Direction: -1, Entrys: &projects}.HandlerCarouselUpdate) app.Static("/static", "assets") app.Start(":3030") diff --git a/internal/handler/handler.go b/internal/handler/handler.go index a83f54d..756ad4a 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -4,13 +4,14 @@ import ( "time" "github.com/labstack/echo/v4" + "github.com/lorenzhohermuth/portfolio/internal/mdparser" "github.com/lorenzhohermuth/portfolio/view/component" "github.com/lorenzhohermuth/portfolio/view/page" ) type Homehandler struct { Index int - Entrys []component.CarouselEntry + Entrys *[]component.CarouselEntry } func(h Homehandler) HandleUserShow(ctx echo.Context) error { @@ -21,17 +22,19 @@ func(h Homehandler) HandleUserShow(ctx echo.Context) error { {time.Now(), time.Now(), "Title 4"}, {time.Now(), time.Now(), "Title 5"}, } + + *h.Entrys = mdparser.GetProjects() - return render(ctx, page.ShowHome(h.Entrys, h.Index, events)) + return render(ctx, page.ShowHome(*h.Entrys, h.Index, events)) } type HtmxCarouselHandler struct { Index *int Direction int - Entrys []component.CarouselEntry + Entrys *[]component.CarouselEntry } func(h HtmxCarouselHandler) HandlerCarouselUpdate(ctx echo.Context) error { *h.Index += h.Direction - return render(ctx, component.Carousel(h.Entrys, int(*h.Index))) + return render(ctx, component.Carousel(*h.Entrys, int(*h.Index))) } diff --git a/internal/mdparser/mdparser.go b/internal/mdparser/mdparser.go index a219121..e1c743e 100644 --- a/internal/mdparser/mdparser.go +++ b/internal/mdparser/mdparser.go @@ -2,8 +2,6 @@ package mdparser import ( "context" - "fmt" - "os" "regexp" "strings" @@ -15,15 +13,13 @@ const pathProjects string = "projects.md" const pathWork string = "work.md" func GetProjects() []component.CarouselEntry { - github.FetchGHFile(context.Background(), "/cmd") + projectsFile, ghErr := github.FetchGHFile(context.Background(), "/interactive/projects.md") + if ghErr != nil { + panic(ghErr) + } components := make([]component.CarouselEntry, 0) - dat, err := os.ReadFile("interactive/projects.md") - if err != nil { - panic(err) - } - - lines := strings.Split(string(dat), "\n") + lines := strings.Split(projectsFile, "\n") tmpTitle := "" tmpText := "" tmpImg := "" @@ -34,7 +30,6 @@ func GetProjects() []component.CarouselEntry { } } - fmt.Println(components) return components } diff --git a/pkg/github/github.go b/pkg/github/github.go index 7e9456e..823cdbe 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -54,13 +54,7 @@ func FetchGHFile(ctx context.Context, path string) (string, error){ func fetchGithub(ctx context.Context, path string) (*github.RepositoryContent, error) { client := github.NewClient(getAuthToken()) - fileContent, repoCont, res, err := client.Repositories.GetContents(ctx, owner, repo, path, nil) - //fmt.Printf("content : %#v\n", fileContent) - fmt.Printf("repoContent : %#v\n", repoCont) - if len(repoCont) > 0 { - fmt.Println("file : ", repoCont[0].GetName()) - } - fmt.Printf("response : %#v\n\n", res) + fileContent, _, _, err := client.Repositories.GetContents(ctx, owner, repo, path, nil) return fileContent, err }