From 3030588ffdc6ec0e248a521ed86c0609ea8ae60e Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Sat, 12 Aug 2023 21:09:22 -0400 Subject: [PATCH] Add HTMX --- web/routes.go | 21 +++--- web/views/download.html | 39 ++++++---- web/views/index.html | 61 ++++++++++++---- web/views/layouts/main.html | 139 +++++++++++++++++++++--------------- 4 files changed, 168 insertions(+), 92 deletions(-) diff --git a/web/routes.go b/web/routes.go index 2ee1894..6dd7228 100644 --- a/web/routes.go +++ b/web/routes.go @@ -20,6 +20,7 @@ type routes struct { func (r *routes) Register(app *fiber.App) { app.Get("/", r.IndexHandler) + app.Get("/home", r.HomeHandler) app.Get("/download", r.DownloadHandler) app.Head("/download/proxy", r.DownloadProxyHandler) app.Get("/download/proxy", r.DownloadProxyHandler) @@ -35,6 +36,13 @@ func (r *routes) IndexHandler(c *fiber.Ctx) error { }, "views/layouts/main") } +func (r *routes) HomeHandler(c *fiber.Ctx) error { + return c.Render("views/index", fiber.Map{ + "BasePath": viper.GetString("base_path"), + "Flash": flash.Get(c), + }) +} + func (r *routes) DownloadHandler(c *fiber.Ctx) error { urlBytes, err := url.QueryUnescape(c.Query("url")) if err != nil { @@ -60,14 +68,11 @@ func (r *routes) DownloadHandler(c *fiber.Ctx) error { } return c.Render("views/download", fiber.Map{ - "BasePath": viper.GetString("base_path"), - "Url": url, - "Meta": meta, - "Videos": GetVideos(meta), - "Version": version.Version, - "Build": version.Build, - "YtdlpVersion": r.ytdl.Version, - }, "views/layouts/main") + "BasePath": viper.GetString("base_path"), + "Url": url, + "Meta": meta, + "Videos": GetVideos(meta), + }) } func (r *routes) DownloadProxyHandler(c *fiber.Ctx) error { diff --git a/web/views/download.html b/web/views/download.html index a55660c..fc28ef7 100644 --- a/web/views/download.html +++ b/web/views/download.html @@ -2,35 +2,50 @@

Download Video

{{.Meta.Title}}

{{.Url}}

- + -{{$root := .}} - -{{range $vidIndex, $video := .Videos}} -{{if not (eq $vidIndex 0)}} +{{$root := .}} {{range $vidIndex, $video := .Videos}} {{if not (eq $vidIndex +0)}}
{{end}}
- {{.Meta.Title}} + {{.Meta.Title}}
{{range $index, $format := $video.Formats}}
{{$format.Format}}
{{end}}
-{{end}} \ No newline at end of file +{{end}} diff --git a/web/views/index.html b/web/views/index.html index f83ff4f..5008c97 100644 --- a/web/views/index.html +++ b/web/views/index.html @@ -1,32 +1,67 @@

YTDL Web

Download videos from over a thousand websites with the help of - yt-dlp, - a fork of youtube-dl with more features and fixes. + yt-dlp, a fork of youtube-dl + with more features and fixes.
View a complete list of supported websites - here. + here.

-
+
- -
- +
{{if .Flash}}
{{.Flash.message}}
{{end}} -
\ No newline at end of file + diff --git a/web/views/layouts/main.html b/web/views/layouts/main.html index 937d781..5f5f598 100644 --- a/web/views/layouts/main.html +++ b/web/views/layouts/main.html @@ -1,63 +1,84 @@ - - - - - - YTDL Web - - - - - - - - - -
- {{template "views/partials/navbar" .}} -
{{embed}}
-
- {{template "views/partials/footer" .}} - + + + + + + + +
+ {{template "views/partials/navbar" .}} +
{{embed}}
+
+ {{template "views/partials/footer" .}} + + +