From e8d4570dba938aa7ce706e688d62928b53e6da77 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 14 Jul 2024 09:06:43 -0700 Subject: [PATCH 1/3] Updated the main template to require header meta tags --- internal/views/layout/withTemplate.templ | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/views/layout/withTemplate.templ b/internal/views/layout/withTemplate.templ index 28da166..83ed5bc 100644 --- a/internal/views/layout/withTemplate.templ +++ b/internal/views/layout/withTemplate.templ @@ -1,18 +1,24 @@ package layout -templ WithTemplate() { +import ( + "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma" + bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" +) + +templ WithTemplate(meta models.HeaderMetaTags) { - @header() + @header(meta) @navBar()
-
+ @bl.Container(bulma.BreakpointDefault) { { children... } @footer() -
+ } } From ad3756d27dc769006e26bd6285b6beaeb28fb443 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 14 Jul 2024 09:07:16 -0700 Subject: [PATCH 2/3] Updated handlers, views and models to support meta tags --- internal/handlers/articles.go | 9 +++++++-- internal/handlers/home.go | 19 ++++++++++++++++--- internal/handlers/users.go | 7 ++++++- internal/models/articles.go | 2 ++ internal/models/debug.go | 1 + internal/models/home.go | 9 +++++++++ internal/models/layout.go | 8 ++++++++ internal/models/sources.go | 3 ++- internal/models/users.go | 4 ++++ internal/views/articles/list.templ | 2 +- internal/views/articles/table.templ | 4 +++- internal/views/debug/cookies.templ | 2 +- internal/views/home/about.templ | 5 +++-- internal/views/home/index.templ | 5 +++-- internal/views/layout/error.templ | 7 ++++++- internal/views/layout/header.templ | 13 +++++++------ internal/views/sources/add.templ | 2 +- internal/views/sources/listAll.templ | 2 +- internal/views/users/login copy.templ | 5 +++-- internal/views/users/login.templ | 5 +++-- internal/views/users/logout.templ | 18 ++++++++++++------ internal/views/users/profile.templ | 7 +++++-- internal/views/users/signup.templ | 8 ++++++-- 23 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 internal/models/home.go diff --git a/internal/handlers/articles.go b/internal/handlers/articles.go index fd4a15d..e0dc757 100644 --- a/internal/handlers/articles.go +++ b/internal/handlers/articles.go @@ -20,7 +20,12 @@ func (h *Handler) ArticlesList(c echo.Context) error { return RenderError(c, err) } - vm := models.ListArticlesViewModel{} + vm := models.ListArticlesViewModel{ + HeaderMetaTags: models.HeaderMetaTags{ + Title: "Articles", + Type: "Page", + }, + } for _, article := range resp.Payload { source, err := h.api.Sources.GetById(GetJwtToken(c), article.SourceID) @@ -36,5 +41,5 @@ func (h *Handler) ArticlesList(c echo.Context) error { } - return Render(c, http.StatusOK, articles.ListArticlesTable(vm)) + return Render(c, http.StatusOK, articles.List(vm)) } diff --git a/internal/handlers/home.go b/internal/handlers/home.go index b47879f..3af0ed3 100644 --- a/internal/handlers/home.go +++ b/internal/handlers/home.go @@ -3,14 +3,27 @@ package handlers import ( "net/http" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/home" "github.com/labstack/echo/v4" ) func (h *Handler) HomeIndex(c echo.Context) error { - return Render(c, http.StatusOK, home.Index()) + return Render(c, http.StatusOK, home.Index(models.HomeIndexViewModel{ + HeaderMetaTags: models.HeaderMetaTags{ + Title: "Newsbot", + Description: "Welcome to your news", + Url: "", + Type: "Page", + }, + })) } func (h *Handler) HomeAbout(c echo.Context) error { - return Render(c, http.StatusOK, home.About()) -} \ No newline at end of file + return Render(c, http.StatusOK, home.About(models.HomeAboutViewModel{ + HeaderMetaTags: models.HeaderMetaTags{ + Title: "About", + Type: "Page", + }, + })) +} diff --git a/internal/handlers/users.go b/internal/handlers/users.go index cc05b12..cd34f0a 100644 --- a/internal/handlers/users.go +++ b/internal/handlers/users.go @@ -11,7 +11,12 @@ import ( ) func (h *Handler) UserLogin(c echo.Context) error { - return Render(c, http.StatusOK, users.LoginNew()) + return Render(c, http.StatusOK, users.LoginNew(models.UsersLoginViewModel{ + HeaderMetaTags: models.HeaderMetaTags{ + Title: "Login", + Type: "Page", + }, + })) } func (h *Handler) UserAfterLogin(c echo.Context) error { diff --git a/internal/models/articles.go b/internal/models/articles.go index d934049..520ad71 100644 --- a/internal/models/articles.go +++ b/internal/models/articles.go @@ -3,10 +3,12 @@ package models import "git.jamestombleson.com/jtom38/newsbot-api/domain" type ListArticlesViewModel struct { + HeaderMetaTags Items []ListArticleSourceModel } type ListArticleSourceModel struct { + HeaderMetaTags Article domain.ArticleDto Source domain.SourceDto } diff --git a/internal/models/debug.go b/internal/models/debug.go index 0621d83..a5aa388 100644 --- a/internal/models/debug.go +++ b/internal/models/debug.go @@ -1,6 +1,7 @@ package models type DebugCookiesViewModel struct { + HeaderMetaTags Username string Token string RefreshToken string diff --git a/internal/models/home.go b/internal/models/home.go new file mode 100644 index 0000000..87f3ee3 --- /dev/null +++ b/internal/models/home.go @@ -0,0 +1,9 @@ +package models + +type HomeIndexViewModel struct { + HeaderMetaTags +} + +type HomeAboutViewModel struct { + HeaderMetaTags +} \ No newline at end of file diff --git a/internal/models/layout.go b/internal/models/layout.go index efdc03d..c8d51d7 100644 --- a/internal/models/layout.go +++ b/internal/models/layout.go @@ -4,3 +4,11 @@ type LayoutIsLoggedInViewModel struct { IsLoggedIn bool Username string } + +type HeaderMetaTags struct { + Title string + Url string + Image string + Description string + Type string +} diff --git a/internal/models/sources.go b/internal/models/sources.go index aee1894..d5cffc1 100644 --- a/internal/models/sources.go +++ b/internal/models/sources.go @@ -3,11 +3,12 @@ package models import "git.jamestombleson.com/jtom38/newsbot-api/domain" type ListAllSourcesViewModel struct { + HeaderMetaTags IsError bool Message string Items []domain.SourceDto } type AddSourcePayloadModel struct { - + HeaderMetaTags } \ No newline at end of file diff --git a/internal/models/users.go b/internal/models/users.go index a06736a..84715fc 100644 --- a/internal/models/users.go +++ b/internal/models/users.go @@ -1,5 +1,9 @@ package models +type UsersLoginViewModel struct { + HeaderMetaTags +} + type AfterLoginViewModel struct { Message string Success bool diff --git a/internal/views/articles/list.templ b/internal/views/articles/list.templ index 1d9497c..51b059e 100644 --- a/internal/views/articles/list.templ +++ b/internal/views/articles/list.templ @@ -7,7 +7,7 @@ import ( ) templ List(model models.ListArticlesViewModel) { - @layout.WithTemplate() { + @layout.WithTemplate(model.HeaderMetaTags) { @filterBar() for _, item := range model.Items { @bulma.ArticleCardWithThumbnail(item.Article.Title, item.Article.Thumbnail, item.Article.Url, item.Article.PubDate.String(), item.Source.DisplayName) diff --git a/internal/views/articles/table.templ b/internal/views/articles/table.templ index 08aeabf..1f52d9d 100644 --- a/internal/views/articles/table.templ +++ b/internal/views/articles/table.templ @@ -7,12 +7,13 @@ import ( ) templ ListArticlesTable(model models.ListArticlesViewModel) { - @layout.WithTemplate() { + @layout.WithTemplate(model.HeaderMetaTags) { @bulma.Table() { @bulma.TableHeader() { @bulma.TableRow() { @bulma.TableHeaderData("Title") @bulma.TableHeaderData("Source") + @bulma.TableHeaderDataToolTip("Pub", "Date Published") @bulma.TableHeaderData("View") } } @@ -20,6 +21,7 @@ templ ListArticlesTable(model models.ListArticlesViewModel) { @bulma.TableRow() { @bulma.TableData(item.Article.Title) @bulma.TableData(item.Source.DisplayName) + @bulma.TableData(item.Article.PubDate.String()) @bulma.TableDataChildren() { @bulma.Button() { @bulma.ANewTab(item.Article.Url, "View") diff --git a/internal/views/debug/cookies.templ b/internal/views/debug/cookies.templ index 0f7d5e1..7b24bca 100644 --- a/internal/views/debug/cookies.templ +++ b/internal/views/debug/cookies.templ @@ -4,7 +4,7 @@ import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" templ Cookies(vm models.DebugCookiesViewModel) { - @layout.WithTemplate() { + @layout.WithTemplate(vm.HeaderMetaTags) {

Token: { vm.Token }

diff --git a/internal/views/home/about.templ b/internal/views/home/about.templ index b580198..92d96bf 100644 --- a/internal/views/home/about.templ +++ b/internal/views/home/about.templ @@ -2,9 +2,10 @@ package home import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma" +import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" -templ About() { - @layout.WithTemplate(){ +templ About(vm models.HomeAboutViewModel) { + @layout.WithTemplate(vm.HeaderMetaTags){ @bulma.Title("About this project") @bulma.Block() { Newsbot started a small project to send out notifications to discord servers. diff --git a/internal/views/home/index.templ b/internal/views/home/index.templ index c614456..29ee09a 100644 --- a/internal/views/home/index.templ +++ b/internal/views/home/index.templ @@ -3,11 +3,12 @@ package home import ( b "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma" bl "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout" + "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout" ) -templ Index() { - @layout.WithTemplate() { +templ Index(vm models.HomeIndexViewModel) { + @layout.WithTemplate(vm.HeaderMetaTags) { @bl.Hero("Welcome to Newsbot!", "Your new home for your news.") @b.Block() { News bot is a self hostable solution to aggregating your news. diff --git a/internal/views/layout/error.templ b/internal/views/layout/error.templ index e1b00d6..4247b8b 100644 --- a/internal/views/layout/error.templ +++ b/internal/views/layout/error.templ @@ -1,7 +1,12 @@ package layout +import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" + templ Error(err error) { - @WithTemplate() { + @WithTemplate(models.HeaderMetaTags{ + Title: "Error", + Description: err.Error(), + }) {

Error

{ err.Error() }

} diff --git a/internal/views/layout/header.templ b/internal/views/layout/header.templ index 0da3df2..1bd026b 100644 --- a/internal/views/layout/header.templ +++ b/internal/views/layout/header.templ @@ -1,17 +1,18 @@ package layout import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma" +import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models" -templ header() { +templ header(meta models.HeaderMetaTags) { @bulma.UseBulmaCdn() - - - - - + + + + +