diff --git a/cmd/main.go b/cmd/main.go index 08dc344..9bee535 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -17,7 +17,7 @@ func main() { var projects []component.CarouselEntry h := handler.Homehandler{Index: index, Entrys: &projects} - app.GET("/", h.HandleUserShow) + app.GET("/", h.HandleShowHome) 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") diff --git a/internal/handler/handler.go b/internal/handler/handler.go index 756ad4a..51173ed 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -1,8 +1,6 @@ package handler import ( - "time" - "github.com/labstack/echo/v4" "github.com/lorenzhohermuth/portfolio/internal/mdparser" "github.com/lorenzhohermuth/portfolio/view/component" @@ -14,15 +12,8 @@ type Homehandler struct { Entrys *[]component.CarouselEntry } -func(h Homehandler) HandleUserShow(ctx echo.Context) error { - events := []component.Event{ - {time.Now(), time.Now(), "Title 1"}, - {time.Now(), time.Now(), "Title 2"}, - {time.Now(), time.Now(), "Title 3"}, - {time.Now(), time.Now(), "Title 4"}, - {time.Now(), time.Now(), "Title 5"}, - } - +func(h Homehandler) HandleShowHome(ctx echo.Context) error { + events := mdparser.GetWork() *h.Entrys = mdparser.GetProjects() return render(ctx, page.ShowHome(*h.Entrys, h.Index, events)) diff --git a/internal/mdparser/mdparser.go b/internal/mdparser/mdparser.go deleted file mode 100644 index 22541e5..0000000 --- a/internal/mdparser/mdparser.go +++ /dev/null @@ -1,76 +0,0 @@ -package mdparser - -import ( - "context" - "regexp" - "strings" - - "github.com/lorenzhohermuth/portfolio/pkg/github" - "github.com/lorenzhohermuth/portfolio/view/component" -) - -const pathProjects string = "projects.md" -const pathWork string = "work.md" - -func GetProjects() []component.CarouselEntry { - projectsFile, ghErr := github.FetchGHFile(context.Background(), "/interactive/projects.md") - if ghErr != nil { - panic(ghErr) - } - components := make([]component.CarouselEntry, 0) - - lines := strings.Split(projectsFile, "\n") - tmpTitle := "" - tmpText := "" - tmpImg := "" - for _, l := range lines { - isFilled, elm := parseMd(l, &tmpTitle, &tmpText, &tmpImg) - if isFilled { - components = append(components, elm) - } - } - - return components -} - -func getChar(text string, pos int) string { - text = strings.TrimSpace(text) - if text == "" { - return "" - } - return string([]rune(text)[pos]) -} - -func parseMd(line string, title *string, text *string, img *string) (bool, component.CarouselEntry){ - char := getChar(line, 0) - - if char == "" { - elm := component.CarouselEntry{ - ImgPath: *img, - Title: *title, - Text: *text, - } - *img = "" - *title = "" - *text = "" - return true, elm - - } else if char == "#" { - *title = strings.TrimSpace(line[1:]) - - } else if char == "!" { - rgx := regexp.MustCompile(`\((.*?)\)`) - mdImage := rgx.FindStringSubmatch(line)[1] - mdImage = strings.TrimSpace(mdImage) - - if mdImage[:4] != "http" { - mdImage = strings.Replace(mdImage, "assets", "static", 1) - } - - *img = mdImage - - } else { - *text += line - } - return false, component.CarouselEntry{} -} diff --git a/view/component/Timeline.templ b/view/component/Timeline.templ index 27dcc0d..334592f 100644 --- a/view/component/Timeline.templ +++ b/view/component/Timeline.templ @@ -1,10 +1,7 @@ package component -import "time" - type Event struct { - DateStart time.Time - DateEnd time.Time + TimePeriode string Title string } @@ -15,7 +12,7 @@ templ Timeline(evts []Event) { <div class="h-1 w-3 m-0 mr-4 rounded-full bg-white"/> <div> <p class="m-0 mb-1">{v.Title}</p> - <p class="m-0 text-sm">{v.DateEnd.Format("02 January 2006")} - {v.DateEnd.Format("02 January 2006")}</p> + <p class="m-0 text-sm">{v.TimePeriode}</p> </div> </div> if i + 1 < len(evts) { diff --git a/view/component/Timeline_templ.go b/view/component/Timeline_templ.go index a84f366..e0cba78 100644 --- a/view/component/Timeline_templ.go +++ b/view/component/Timeline_templ.go @@ -10,12 +10,9 @@ import "context" import "io" import "bytes" -import "time" - type Event struct { - DateStart time.Time - DateEnd time.Time - Title string + TimePeriode string + Title string } func Timeline(evts []Event) templ.Component { @@ -43,7 +40,7 @@ func Timeline(evts []Event) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(v.Title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/component/Timeline.templ`, Line: 17, Col: 33} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/component/Timeline.templ`, Line: 14, Col: 33} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -54,27 +51,14 @@ func Timeline(evts []Event) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var3 string - templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(v.DateEnd.Format("02 January 2006")) + templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(v.TimePeriode) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/component/Timeline.templ`, Line: 18, Col: 64} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/component/Timeline.templ`, Line: 15, Col: 42} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" - ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var4 string - templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(v.DateEnd.Format("02 January 2006")) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/component/Timeline.templ`, Line: 18, Col: 104} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p></div></div>") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err