github sync working
This commit is contained in:
parent
47f5b9dbd4
commit
9c7e309ec6
12
cmd/main.go
12
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")
|
||||
|
|
|
@ -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)))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue