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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gofor-little/env"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"github.com/lorenzhohermuth/portfolio/internal/handler"
|
"github.com/lorenzhohermuth/portfolio/internal/handler"
|
||||||
"github.com/lorenzhohermuth/portfolio/internal/mdparser"
|
"github.com/lorenzhohermuth/portfolio/view/component"
|
||||||
"github.com/gofor-little/env"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -15,11 +15,11 @@ func main() {
|
||||||
app := echo.New()
|
app := echo.New()
|
||||||
index := 0
|
index := 0
|
||||||
|
|
||||||
projects := mdparser.GetProjects()
|
var projects []component.CarouselEntry
|
||||||
h := handler.Homehandler{index, projects}
|
h := handler.Homehandler{Index: index, Entrys: &projects}
|
||||||
app.GET("/", h.HandleUserShow)
|
app.GET("/", h.HandleUserShow)
|
||||||
app.POST("/carousel/next", 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, -1, projects}.HandlerCarouselUpdate)
|
app.POST("/carousel/previous", handler.HtmxCarouselHandler{Index: &index, Direction: -1, Entrys: &projects}.HandlerCarouselUpdate)
|
||||||
app.Static("/static", "assets")
|
app.Static("/static", "assets")
|
||||||
|
|
||||||
app.Start(":3030")
|
app.Start(":3030")
|
||||||
|
|
|
@ -4,13 +4,14 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/lorenzhohermuth/portfolio/internal/mdparser"
|
||||||
"github.com/lorenzhohermuth/portfolio/view/component"
|
"github.com/lorenzhohermuth/portfolio/view/component"
|
||||||
"github.com/lorenzhohermuth/portfolio/view/page"
|
"github.com/lorenzhohermuth/portfolio/view/page"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Homehandler struct {
|
type Homehandler struct {
|
||||||
Index int
|
Index int
|
||||||
Entrys []component.CarouselEntry
|
Entrys *[]component.CarouselEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func(h Homehandler) HandleUserShow(ctx echo.Context) error {
|
func(h Homehandler) HandleUserShow(ctx echo.Context) error {
|
||||||
|
@ -22,16 +23,18 @@ func(h Homehandler) HandleUserShow(ctx echo.Context) error {
|
||||||
{time.Now(), time.Now(), "Title 5"},
|
{time.Now(), time.Now(), "Title 5"},
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(ctx, page.ShowHome(h.Entrys, h.Index, events))
|
*h.Entrys = mdparser.GetProjects()
|
||||||
|
|
||||||
|
return render(ctx, page.ShowHome(*h.Entrys, h.Index, events))
|
||||||
}
|
}
|
||||||
|
|
||||||
type HtmxCarouselHandler struct {
|
type HtmxCarouselHandler struct {
|
||||||
Index *int
|
Index *int
|
||||||
Direction int
|
Direction int
|
||||||
Entrys []component.CarouselEntry
|
Entrys *[]component.CarouselEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func(h HtmxCarouselHandler) HandlerCarouselUpdate(ctx echo.Context) error {
|
func(h HtmxCarouselHandler) HandlerCarouselUpdate(ctx echo.Context) error {
|
||||||
*h.Index += h.Direction
|
*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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -15,15 +13,13 @@ const pathProjects string = "projects.md"
|
||||||
const pathWork string = "work.md"
|
const pathWork string = "work.md"
|
||||||
|
|
||||||
func GetProjects() []component.CarouselEntry {
|
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)
|
components := make([]component.CarouselEntry, 0)
|
||||||
|
|
||||||
dat, err := os.ReadFile("interactive/projects.md")
|
lines := strings.Split(projectsFile, "\n")
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
lines := strings.Split(string(dat), "\n")
|
|
||||||
tmpTitle := ""
|
tmpTitle := ""
|
||||||
tmpText := ""
|
tmpText := ""
|
||||||
tmpImg := ""
|
tmpImg := ""
|
||||||
|
@ -34,7 +30,6 @@ func GetProjects() []component.CarouselEntry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(components)
|
|
||||||
return 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) {
|
func fetchGithub(ctx context.Context, path string) (*github.RepositoryContent, error) {
|
||||||
client := github.NewClient(getAuthToken())
|
client := github.NewClient(getAuthToken())
|
||||||
fileContent, repoCont, res, err := client.Repositories.GetContents(ctx, owner, repo, path, nil)
|
fileContent, _, _, 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)
|
|
||||||
return fileContent, err
|
return fileContent, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue