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) {
{v.Title}
-{v.DateEnd.Format("02 January 2006")} - {v.DateEnd.Format("02 January 2006")}
+{v.TimePeriode}